import {z} from 'zod' export type GetApiSafevideoV1MediasIdArgs = {id: string}; export type GetApiSafevideoV1MediasIdOptions = {baseUrl?: string | undefined, eduzzAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiSafevideoV1MediasIdResponse = z.object({id: z.string(), key: z.string(), userId: z.string(), userEmail: z.string(), title: z.string(), filename: z.string(), status: z.string(), duration: z.number(), order: z.number(), tags: z.array(z.string()), storage: z.string(), deletedAt: z.string().nullable(), description: z.string(), createdAt: z.string(), updatedAt: z.string(), source: z.object({filename: z.string(), size: z.number(), width: z.number(), height: z.number()}), encoded: z.array(z.object({format: z.string(), codec: z.string(), size: z.number(), resolutions: z.array(z.object({width: z.number(), height: z.number()}))}))}); 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 }; /** * Detalhes da mídia do produtor * * GET /safevideo/v1/medias/:id */ export const getApiSafevideoV1MediasId = async (args: GetApiSafevideoV1MediasIdArgs, options?: GetApiSafevideoV1MediasIdOptions) => { const {baseUrl = "https://api.eduzz.com", fetch: fetchFn = fetch, eduzzAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (eduzzAuth !== undefined) headers.set('authorization', `Bearer ${eduzzAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/safevideo/v1/medias/:id${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiSafevideoV1MediasIdResponse, await res.json()) };