import {z} from 'zod' export type CreateApiApiV2ChannelsPublishFlowsArgs = {body: {flowId?: string | undefined, content: {title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}) | undefined}, publishAt: string, context?: ({materialGroupId?: string | undefined, materialId?: string | undefined}) | undefined, items: Array<{platform: 'bilibili', option: {tid: number, no_reprint?: number | undefined, topic_id?: number | undefined, mission_id?: number | undefined, copyright?: number | undefined, source?: string | undefined} | {tid: number, no_reprint?: number | undefined, topic_id?: number | undefined, mission_id?: number | undefined, copyright: number, source: string}, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'youtube', option?: ({privacyStatus?: ('public' | 'unlisted' | 'private') | undefined, categoryId?: string | undefined, publishAt?: string | undefined, license?: ('creativeCommon' | 'youtube') | undefined, embeddable?: boolean | undefined, notifySubscribers?: boolean | undefined, selfDeclaredMadeForKids?: boolean | undefined, madeForKids?: boolean | undefined, containsSyntheticMedia?: boolean | undefined}) | undefined, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'wxGzh', option?: ({author?: string | undefined, digest?: string | undefined, open_comment?: number | undefined, only_fans_can_comment?: number | undefined, showCoverPic?: boolean | undefined, sourceUrl?: string | undefined}) | undefined, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'facebook', option?: ({content_category?: ('post' | 'reel' | 'story') | undefined, link?: string | undefined, content_tags?: Array | undefined, custom_labels?: Array | undefined, direct_share_status?: number | undefined, embeddable?: boolean | undefined, feed_targeting?: {[key: string]: unknown} | undefined, video_state?: ('DRAFT' | 'SCHEDULED' | 'PUBLISHED') | undefined}) | undefined, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'instagram', option?: ({alt_text?: string | undefined, caption?: string | undefined, collaborators?: Array | undefined, cover_url?: string | undefined, image_url?: string | undefined, location_id?: string | undefined, media_type?: ('IMAGE' | 'REELS' | 'STORIES' | 'CAROUSEL') | undefined, product_tags?: Array<{product_id: string, x: number, y: number}> | undefined, user_tags?: Array<{username: string, x: number, y: number}> | undefined}) | undefined, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'threads', option?: ({reply_control?: ('everyone' | 'accounts_you_follow' | 'mentioned_only' | 'parent_post_author_only' | 'followers_only') | undefined, location_id?: string | undefined, allowlisted_country_codes?: Array | undefined, alt_text?: string | undefined, auto_publish_text?: boolean | undefined, link_attachment?: string | undefined, reply_to_id?: string | undefined, quote_post_id?: string | undefined}) | undefined, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'pinterest', option: {boardId: string, link?: string | undefined, altText?: string | undefined, coverImageUrl?: string | undefined}, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'tiktok', option?: ({privacy_level?: ('PUBLIC_TO_EVERYONE' | 'MUTUAL_FOLLOW_FRIENDS' | 'SELF_ONLY' | 'FOLLOWER_OF_CREATOR') | undefined, disable_duet?: boolean | undefined, disable_stitch?: boolean | undefined, disable_comment?: boolean | undefined, brand_organic_toggle?: boolean | undefined, brand_content_toggle?: boolean | undefined, auto_add_music?: boolean | undefined, photo_cover_index?: number | undefined, source?: ('FILE_UPLOAD' | 'PULL_FROM_URL') | undefined, is_aigc?: boolean | undefined}) | undefined, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'douyin', option?: ({short_title?: string | undefined, cover_tsp?: number | undefined, download_type?: number | undefined, private_status?: number | undefined}) | undefined, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'twitter', option?: ({reply_to_tweet_id?: string | undefined, reply_settings?: ('following' | 'mentionedUsers' | 'subscribers' | 'verified') | undefined, poll?: {options: Array, duration_minutes: number} | undefined, quote_tweet_id?: string | undefined, made_with_ai?: boolean | undefined, paid_partnership?: boolean | undefined, alt_text?: string | undefined}) | undefined, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'KWAI', option?: ({cover?: string | undefined, stereo_type?: string | undefined, merchant_product_id?: string | undefined}) | undefined, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'linkedin', option?: ({visibility?: ('CONNECTIONS' | 'PUBLIC') | undefined, authorUrn?: string | undefined, distribution?: ('MAIN_FEED' | 'NONE') | undefined, commentary?: string | undefined}) | undefined, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'xhs', option: {workLink: string}, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined} | {platform: 'wxSph', option?: ({workId?: string | undefined, workLink?: string | undefined, linkStatus?: ('pending' | 'ready' | 'failed') | undefined, linkMeta?: ({mediaMd5sum?: string | undefined, videoClipTaskId?: string | undefined, scheduledTime?: number | undefined}) | undefined}) | undefined, accountId: string, overrides?: ({title?: string | undefined, body?: string | undefined, media?: (Array<{url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined}>) | undefined, cover?: ({url: string, options?: ({adaptation?: ({imageFormat?: ('off' | 'auto' | 'jpeg' | 'png' | 'webp') | undefined}) | undefined}) | undefined} | null) | undefined}) | undefined}>}}; export type CreateApiApiV2ChannelsPublishFlowsOptions = {baseUrl?: string | undefined, apikeyHeaderXApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV2ChannelsPublishFlowsResponse = z.object({data: z.object({flowId: z.string().optional(), tasks: z.array(z.object({id: z.string().optional(), accountId: z.string().optional(), platform: z.string().optional(), status: z.number().optional(), publishTime: z.string().optional(), platformWorkId: z.string().optional(), workLink: z.string().optional(), linkStatus: z.string().optional(), linkError: z.string().optional(), linkMeta: z.object({}).optional(), errorMsg: z.string().optional()})).optional()}).optional(), code: z.number().int(), message: z.string(), 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 }; /** * 创建发布流程 * * POST /api/v2/channels/publish/flows */ export const createApiApiV2ChannelsPublishFlows = async (args: CreateApiApiV2ChannelsPublishFlowsArgs, options?: CreateApiApiV2ChannelsPublishFlowsOptions) => { const {baseUrl = "https://aitoearn.cn", fetch: fetchFn = fetch, apikeyHeaderXApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apikeyHeaderXApiKey !== undefined) headers.set("X-Api-Key", apikeyHeaderXApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/channels/publish/flows${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(createApiApiV2ChannelsPublishFlowsResponse, await res.json()) };