import {z} from 'zod' export type GetApiV1PrivateContentPacksPackIdGalleryArgs = {packId: string, page?: number | undefined, pageSize?: number | undefined}; export type GetApiV1PrivateContentPacksPackIdGalleryOptions = {baseUrl: string, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const privateContentModelDto = z.object({id: z.string(), name: z.string(), slug: z.string(), avatarUrl: z.string().optional()}); export const privateContentGalleryPackDto = z.object({id: z.string(), title: z.string().nullable().optional(), description: z.string().nullable().optional(), model: privateContentModelDto, likesCount: z.number(), dislikesCount: z.number(), positiveRatePercent: z.number().nullable().optional(), myReaction: z.enum(["LIKE", "DISLIKE"]).nullable().optional()}); export const modelContentMediaDto = z.object({id: z.string(), type: z.enum(["PHOTO", "VIDEO"]), url: z.string().optional(), videoUrl: z.string().optional(), previewUrl: z.string().optional(), nsfwThumbnailUrl: z.string().optional(), lockedCoverUrl: z.string().optional(), duration: z.number().optional(), order: z.number(), price: z.number(), isPurchased: z.boolean(), isLocked: z.boolean()}); export const privateContentPackGalleryResponseDto = z.object({total: z.number(), pageSize: z.number(), page: z.number(), pack: privateContentGalleryPackDto, items: z.array(modelContentMediaDto)}); 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 }; /** * Contents of an unlocked pack * * GET /v1/private-content/packs/{packId}/gallery */ export const getApiV1PrivateContentPacksPackIdGallery = async (args: GetApiV1PrivateContentPacksPackIdGalleryArgs, options: GetApiV1PrivateContentPacksPackIdGalleryOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/private-content/packs/${encodeURIComponent(String(args.packId))}/gallery${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(privateContentPackGalleryResponseDto, await res.json()) };