mirror of
https://github.com/LukeHagar/plexjs.git
synced 2025-12-06 04:20:46 +00:00
166 lines
4.6 KiB
TypeScript
166 lines
4.6 KiB
TypeScript
/*
|
|
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
*/
|
|
|
|
import * as z from "zod/v4";
|
|
import { PlexAPICore } from "../core.js";
|
|
import * as M from "../lib/matchers.js";
|
|
import { compactMap } from "../lib/primitives.js";
|
|
import { safeParse } from "../lib/schemas.js";
|
|
import { RequestOptions } from "../lib/sdks.js";
|
|
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
import { pathToFunc } from "../lib/url.js";
|
|
import {
|
|
ConnectionError,
|
|
InvalidRequestError,
|
|
RequestAbortedError,
|
|
RequestTimeoutError,
|
|
UnexpectedClientError,
|
|
} from "../models/errors/httpclienterrors.js";
|
|
import { PlexAPIError } from "../models/errors/plexapierror.js";
|
|
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
import { APICall, APIPromise } from "../types/async.js";
|
|
import { Result } from "../types/fp.js";
|
|
|
|
/**
|
|
* Logging a multi-line message to the Plex Media Server log
|
|
*
|
|
* @remarks
|
|
* This endpoint will write multiple lines to the main Plex Media Server log in a single request. It takes a set of query strings as would normally sent to the above PUT endpoint as a linefeed-separated block of POST data. The parameters for each query string match as above.
|
|
*/
|
|
export function logWriteLog(
|
|
client: PlexAPICore,
|
|
request: ReadableStream<Uint8Array> | Blob | ArrayBuffer | Uint8Array,
|
|
options?: RequestOptions,
|
|
): APIPromise<
|
|
Result<
|
|
void,
|
|
| PlexAPIError
|
|
| ResponseValidationError
|
|
| ConnectionError
|
|
| RequestAbortedError
|
|
| RequestTimeoutError
|
|
| InvalidRequestError
|
|
| UnexpectedClientError
|
|
| SDKValidationError
|
|
>
|
|
> {
|
|
return new APIPromise($do(
|
|
client,
|
|
request,
|
|
options,
|
|
));
|
|
}
|
|
|
|
async function $do(
|
|
client: PlexAPICore,
|
|
request: ReadableStream<Uint8Array> | Blob | ArrayBuffer | Uint8Array,
|
|
options?: RequestOptions,
|
|
): Promise<
|
|
[
|
|
Result<
|
|
void,
|
|
| PlexAPIError
|
|
| ResponseValidationError
|
|
| ConnectionError
|
|
| RequestAbortedError
|
|
| RequestTimeoutError
|
|
| InvalidRequestError
|
|
| UnexpectedClientError
|
|
| SDKValidationError
|
|
>,
|
|
APICall,
|
|
]
|
|
> {
|
|
const parsed = safeParse(
|
|
request,
|
|
(value) =>
|
|
z.union([
|
|
z.custom<ReadableStream<Uint8Array>>(x => x instanceof ReadableStream),
|
|
z.custom<Blob>(x => x instanceof Blob),
|
|
z.custom<ArrayBuffer>(x => x instanceof ArrayBuffer),
|
|
z.custom<Uint8Array>(x => x instanceof Uint8Array),
|
|
]).parse(value),
|
|
"Input validation failed",
|
|
);
|
|
if (!parsed.ok) {
|
|
return [parsed, { status: "invalid" }];
|
|
}
|
|
const payload = parsed.value;
|
|
const body = payload;
|
|
|
|
const path = pathToFunc("/log")();
|
|
|
|
const headers = new Headers(compactMap({
|
|
"Content-Type": "text/plain",
|
|
Accept: "*/*",
|
|
}));
|
|
|
|
const secConfig = await extractSecurity(client._options.token);
|
|
const securityInput = secConfig == null ? {} : { token: secConfig };
|
|
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
|
|
const context = {
|
|
options: client._options,
|
|
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
operationID: "writeLog",
|
|
oAuth2Scopes: null,
|
|
|
|
resolvedSecurity: requestSecurity,
|
|
|
|
securitySource: client._options.token,
|
|
retryConfig: options?.retries
|
|
|| client._options.retryConfig
|
|
|| { strategy: "none" },
|
|
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
};
|
|
|
|
const requestRes = client._createRequest(context, {
|
|
security: requestSecurity,
|
|
method: "POST",
|
|
baseURL: options?.serverURL,
|
|
path: path,
|
|
headers: headers,
|
|
body: body,
|
|
userAgent: client._options.userAgent,
|
|
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
}, options);
|
|
if (!requestRes.ok) {
|
|
return [requestRes, { status: "invalid" }];
|
|
}
|
|
const req = requestRes.value;
|
|
|
|
const doResult = await client._do(req, {
|
|
context,
|
|
errorCodes: ["400", "4XX", "5XX"],
|
|
retryConfig: context.retryConfig,
|
|
retryCodes: context.retryCodes,
|
|
});
|
|
if (!doResult.ok) {
|
|
return [doResult, { status: "request-error", request: req }];
|
|
}
|
|
const response = doResult.value;
|
|
|
|
const [result] = await M.match<
|
|
void,
|
|
| PlexAPIError
|
|
| ResponseValidationError
|
|
| ConnectionError
|
|
| RequestAbortedError
|
|
| RequestTimeoutError
|
|
| InvalidRequestError
|
|
| UnexpectedClientError
|
|
| SDKValidationError
|
|
>(
|
|
M.nil(200, z.void()),
|
|
M.fail([400, "4XX"]),
|
|
M.fail("5XX"),
|
|
)(response, req);
|
|
if (!result.ok) {
|
|
return [result, { status: "complete", request: req, response }];
|
|
}
|
|
|
|
return [result, { status: "complete", request: req, response }];
|
|
}
|