import {z} from 'zod' export type ImageType = 'Primary' | 'Art' | 'Backdrop' | 'Banner' | 'Logo' | 'Thumb' | 'Disc' | 'Box' | 'Screenshot' | 'Menu' | 'Chapter' | 'BoxRear' | 'Profile'; export type GetApiItemsItemIdRemoteImagesArgs = {itemId: string, type?: ImageType | undefined, startIndex?: (number | null) | undefined, limit?: (number | null) | undefined, providerName?: (string | null) | undefined, includeAllLanguages?: boolean | undefined}; export type GetApiItemsItemIdRemoteImagesOptions = {baseUrl?: string | undefined, CustomAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const imageType = z.enum(["Primary", "Art", "Backdrop", "Banner", "Logo", "Thumb", "Disc", "Box", "Screenshot", "Menu", "Chapter", "BoxRear", "Profile"]); export const ratingType = z.enum(["Score", "Likes"]); export const remoteImageInfo = z.object({ProviderName: z.string().nullable().optional(), Url: z.string().nullable().optional(), ThumbnailUrl: z.string().nullable().optional(), Height: z.number().int().nullable().optional(), Width: z.number().int().nullable().optional(), CommunityRating: z.number().nullable().optional(), VoteCount: z.number().int().nullable().optional(), Language: z.string().nullable().optional(), Type: imageType.optional(), RatingType: ratingType.optional()}); export const remoteImageResult = z.object({Images: z.array(remoteImageInfo).nullable().optional(), TotalRecordCount: z.number().int().optional(), Providers: z.array(z.string()).nullable().optional()}); 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 }; /** * Gets available remote images for an item. * * GET /Items/{itemId}/RemoteImages */ export const getApiItemsItemIdRemoteImages = async (args: GetApiItemsItemIdRemoteImagesArgs, options?: GetApiItemsItemIdRemoteImagesOptions) => { const {baseUrl = "http://localhost", fetch: fetchFn = fetch, CustomAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (args.startIndex != null) query.append("startIndex", String(args.startIndex)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.providerName != null) query.append("providerName", String(args.providerName)) if (args.includeAllLanguages != null) query.append("includeAllLanguages", String(args.includeAllLanguages)) if (CustomAuthentication !== undefined) headers.set("X-Emby-Authorization", CustomAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/Items/${encodeURIComponent(String(args.itemId))}/RemoteImages${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(remoteImageResult, await res.json()) };