import {z} from 'zod' export type UpdateArtRequest = {overwrite?: (0 | 1) | undefined} | {[key: string]: unknown}; export type CreateApiArtistsArtistIdUpdateArtArgs = {artist_id: string, overwrite?: (0 | 1) | undefined, body: UpdateArtRequest}; export type CreateApiArtistsArtistIdUpdateArtOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const successResponse = z.object({success: z.string().optional()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Update art for an object (Catalog Manager) * * POST /artists/{artist_id}/update-art * * Also accepts auth: ApiKeyAuthHeader, ApiKeyAuthQuery */ export const createApiArtistsArtistIdUpdateArt = async (args: CreateApiArtistsArtistIdUpdateArtArgs, options?: CreateApiArtistsArtistIdUpdateArtOptions) => { const {baseUrl = "https://develop.ampache.dev/rest/8/json", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.overwrite != null) query.append("overwrite", String(args.overwrite)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/artists/${encodeURIComponent(String(args.artist_id))}/update-art${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(successResponse, await res.json()) };