/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { LivepeerCore } from "../core.js"; import { encodeJSON } from "../lib/encodings.js"; import * as M from "../lib/matchers.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 * as components from "../models/components/index.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import { SDKError } from "../models/errors/sdkerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import * as operations from "../models/operations/index.js"; import { Result } from "../types/fp.js"; /** * Transcode a video * * @remarks * `POST /transcode` transcodes a video file and uploads the results to the * specified storage service. * \ * \ * Transcoding is asynchronous so you will need to check the status of the * task in order to determine when transcoding is complete. The `id` field * in the response is the unique ID for the transcoding `Task`. The task * status can be queried using the [GET tasks * endpoint](https://docs.livepeer.org/reference/api/get-tasks): * \ * \ * When `status.phase` is `completed`, transcoding will be complete and * the results will be stored in the storage service and the specified * output location. * \ * \ * The results will be available under `params.outputs.hls.path` and * `params.outputs.mp4.path` in the specified storage service. * ## Input * \ * This endpoint currently supports the following inputs: * - HTTP * - S3 API Compatible Service * \ * \ * **HTTP** * \ * A public HTTP URL can be used to read a video file. * ```json * { * "url": "https://www.example.com/video.mp4" * } * ``` * | Name | Type | Description | * | ---- | ------ | ------------------------------------ | * | url | string | A public HTTP URL for the video file. | * * Note: For IPFS HTTP gateway URLs, the API currently only supports “path * style” URLs and does not support “subdomain style” URLs. The API will * support both styles of URLs in a future update. * \ * \ * **S3 API Compatible Service** * \ * \ * S3 credentials can be used to authenticate with a S3 API compatible * service to read a video file. * * ```json * { * "type": "s3", * "endpoint": "https://gateway.storjshare.io", * "credentials": { * "accessKeyId": "$ACCESS_KEY_ID", * "secretAccessKey": "$SECRET_ACCESS_KEY" * }, * "bucket": "inbucket", * "path": "/video/source.mp4" * } * ``` * * ## Storage * \ * This endpoint currently supports the following storage services: * - S3 API Compatible Service * - Web3 Storage * \ * \ * **S3 API Compatible Service** * ```json * { * "type": "s3", * "endpoint": "https://gateway.storjshare.io", * "credentials": { * "accessKeyId": "$ACCESS_KEY_ID", * "secretAccessKey": "$SECRET_ACCESS_KEY" * }, * "bucket": "mybucket" * } * ``` * * **Web3 Storage** * * ```json * { * "type": "web3.storage", * "credentials": { * "proof": "$UCAN_DELEGATION_PROOF", * } * } * ``` * * ## Outputs * \ * This endpoint currently supports the following output types: * - HLS * - MP4 * * **HLS** * * ```json * { * "hls": { * "path": "/samplevideo/hls" * } * } * ``` * * **MP4** * * ```json * { * "mp4": { * "path": "/samplevideo/mp4" * } * } * ``` */ export async function transcodeCreate( client: LivepeerCore, request: components.TranscodePayload, options?: RequestOptions, ): Promise< Result< operations.TranscodeVideoResponse, | SDKError | SDKValidationError | UnexpectedClientError | InvalidRequestError | RequestAbortedError | RequestTimeoutError | ConnectionError > > { const parsed = safeParse( request, (value) => components.TranscodePayload$outboundSchema.parse(value), "Input validation failed", ); if (!parsed.ok) { return parsed; } const payload = parsed.value; const body = encodeJSON("body", payload, { explode: true }); const path = pathToFunc("/transcode")(); const headers = new Headers({ "Content-Type": "application/json", Accept: "application/json", }); const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; const requestSecurity = resolveGlobalSecurity(securityInput); const context = { operationID: "transcodeVideo", oAuth2Scopes: [], resolvedSecurity: requestSecurity, securitySource: client._options.apiKey, 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", path: path, headers: headers, body: body, timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, errorCodes: ["4XX", "5XX"], retryConfig: context.retryConfig, retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; } const response = doResult.value; const responseFields = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, RawResponse: response, Headers: {}, }; const [result] = await M.match< operations.TranscodeVideoResponse, | SDKError | SDKValidationError | UnexpectedClientError | InvalidRequestError | RequestAbortedError | RequestTimeoutError | ConnectionError >( M.json(200, operations.TranscodeVideoResponse$inboundSchema, { key: "task", }), M.fail(["4XX", "5XX"]), M.json("default", operations.TranscodeVideoResponse$inboundSchema, { key: "error", }), )(response, { extraFields: responseFields }); if (!result.ok) { return result; } return result; }