import {z} from 'zod' export type GetApiInfoFindInfoArgs = {ID?: number | undefined, content?: string | undefined, createdAt?: string | undefined, title?: string | undefined, updatedAt?: string | undefined, userID?: number | undefined}; export type GetApiInfoFindInfoOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const modelInfo = z.object({ID: z.number().int().optional(), attachments: z.array(z.object({})).optional(), content: z.string().optional(), createdAt: z.string().optional(), title: z.string().optional(), updatedAt: z.string().optional(), userID: z.number().int().optional()}); export const getApiInfoFindInfoResponse = z.object({code: z.number().int().optional(), data: modelInfo.optional(), msg: z.string().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 }; /** * 用id查询公告 * * GET /info/findInfo */ export const getApiInfoFindInfo = async (args: GetApiInfoFindInfoArgs, options: GetApiInfoFindInfoOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ID != null) query.append("ID", String(args.ID)) if (args.content != null) query.append("content", String(args.content)) if (args.createdAt != null) query.append("createdAt", String(args.createdAt)) if (args.title != null) query.append("title", String(args.title)) if (args.updatedAt != null) query.append("updatedAt", String(args.updatedAt)) if (args.userID != null) query.append("userID", String(args.userID)) if (ApiKeyAuth !== undefined) headers.set("x-token", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/info/findInfo${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(getApiInfoFindInfoResponse, await res.json()) };