import {z} from 'zod' export type GetApiApiV2ChannelsPublishRecordsArgs = {accountId?: string | undefined, accountType?: ('douyin' | 'xhs' | 'wxSph' | 'KWAI' | 'youtube' | 'wxGzh' | 'bilibili' | 'twitter' | 'tiktok' | 'facebook' | 'instagram' | 'threads' | 'pinterest' | 'linkedin' | 'google_business') | undefined, time?: Array | undefined, status?: number | undefined}; export type GetApiApiV2ChannelsPublishRecordsOptions = {baseUrl?: string | undefined, apikeyHeaderXApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV2ChannelsPublishRecordsResponse = z.object({data: z.array(z.object({id: z.string().optional(), flowId: z.string().optional(), userTaskId: z.string().optional(), accountId: z.string().optional(), accountType: z.string().optional(), type: z.string().optional(), status: z.number().optional(), title: z.string().optional(), desc: z.string().optional(), publishTime: z.string().optional(), platformWorkId: z.string().optional(), workLink: z.string().optional(), videoUrl: z.string().optional(), coverUrl: z.string().optional(), imgUrlList: z.array(z.string()).optional(), source: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()})).optional(), code: z.number().int().optional(), message: z.string().optional(), requestId: z.string().optional(), timestamp: z.number().int().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 }; /** * 发布记录列表 * * GET /api/v2/channels/publish/records */ export const getApiApiV2ChannelsPublishRecords = async (args: GetApiApiV2ChannelsPublishRecordsArgs, options?: GetApiApiV2ChannelsPublishRecordsOptions) => { const {baseUrl = "https://aitoearn.cn", fetch: fetchFn = fetch, apikeyHeaderXApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.accountId != null) query.append("accountId", String(args.accountId)) if (args.accountType != null) query.append("accountType", String(args.accountType)) for (const item of args.time ?? []) query.append("time", String(item)) if (args.status != null) query.append("status", String(args.status)) if (apikeyHeaderXApiKey !== undefined) headers.set("X-Api-Key", apikeyHeaderXApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/channels/publish/records${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(getApiApiV2ChannelsPublishRecordsResponse, await res.json()) };