import {z} from 'zod' export type CreateApi1VodChannelChannelMediaMediaThumbstripArgs = {channel: number, media: number, body: {folder_id: number, category_id?: number | undefined, language_id?: number | undefined, name: string, description?: string | undefined, validated?: boolean | undefined, published?: boolean | undefined, password?: string | undefined, streams?: string | undefined, shot_boundaries?: Array | undefined, duration?: number | undefined, client: '"cli"' | '"http"', http_ip?: unknown | undefined, http_user_agent?: string | undefined, cli_user?: string | undefined, cli_hostname?: string | undefined, debug?: boolean | undefined}}; export type CreateApi1VodChannelChannelMediaMediaThumbstripOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const response = z.object({result: z.enum(["success", "error", "asynchronous"])}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get new thumbstrip thumbnail ( for medias older than 2024, async job ) * * POST /1/vod/channel/{channel}/media/{media}/thumbstrip */ export const createApi1VodChannelChannelMediaMediaThumbstrip = async (args: CreateApi1VodChannelChannelMediaMediaThumbstripArgs, options?: CreateApi1VodChannelChannelMediaMediaThumbstripOptions) => { const {baseUrl = "https://api.infomaniak.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/1/vod/channel/${encodeURIComponent(String(args.channel))}/media/${encodeURIComponent(String(args.media))}/thumbstrip${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(response, await res.json()) };