| 1 | import { aitoearnAiClientConfigSchema } from '@yikart/aitoearn-ai-client' |
| 2 | import { aitoearnAuthConfigSchema } from '@yikart/aitoearn-auth' |
| 3 | import { assetsConfigSchema } from '@yikart/assets' |
| 4 | import { mongodbConfigSchema as channelDbConfigSchema } from '@yikart/channel-db' |
| 5 | import { baseConfig, createZodDto, selectConfig } from '@yikart/common' |
| 6 | import { mongodbConfigSchema } from '@yikart/mongodb' |
| 7 | import { redisConfigSchema } from '@yikart/redis' |
| 8 | import { redlockConfigSchema } from '@yikart/redlock' |
| 9 | import z from 'zod' |
| 10 | import { bilibiliConfigSchema } from './core/channels/platforms/bilibili/bilibili.config' |
| 11 | import { douyinConfigSchema } from './core/channels/platforms/douyin/douyin.config' |
| 12 | import { facebookConfigSchema } from './core/channels/platforms/facebook/facebook.config' |
| 13 | import { googleBusinessConfigSchema } from './core/channels/platforms/google-business/google-business.config' |
| 14 | import { instagramConfigSchema } from './core/channels/platforms/instagram/instagram.config' |
| 15 | import { kwaiConfigSchema } from './core/channels/platforms/kwai/kwai.config' |
| 16 | import { linkedinConfigSchema } from './core/channels/platforms/linkedin/linkedin.config' |
| 17 | import { pinterestConfigSchema } from './core/channels/platforms/pinterest/pinterest.config' |
| 18 | import { rednoteConfigSchema } from './core/channels/platforms/rednote/rednote.config' |
| 19 | import { threadsConfigSchema } from './core/channels/platforms/threads/threads.config' |
| 20 | import { tiktokConfigSchema } from './core/channels/platforms/tiktok/tiktok.config' |
| 21 | import { twitterConfigSchema } from './core/channels/platforms/twitter/twitter.config' |
| 22 | import { wechatConfigSchema } from './core/channels/platforms/wechat/wechat.config' |
| 23 | import { youtubeConfigSchema } from './core/channels/platforms/youtube/youtube.config' |
| 24 | |
| 25 | const httpUrlSchema = z.url({ protocol: /^https?$/ }) |
| 26 | |
| 27 | export const relayConfigSchema = z.object({ |
| 28 | serverUrl: httpUrlSchema.describe('中转服务器地址'), |
| 29 | apiKey: z.string().describe('用户 API Key'), |
| 30 | callbackUrl: httpUrlSchema.describe('OAuth 回调完整地址,如 http://localhost:3000/api/v2/channels/relay/callback'), |
| 31 | }) |
| 32 | |
| 33 | export const apiKeyConfigSchema = z.object({ |
| 34 | prefix: z.string().min(1).default('ai_'), |
| 35 | }).default({ prefix: 'ai_' }) |
| 36 | |
| 37 | export const channelConfigSchema = z.object({ |
| 38 | channelDb: channelDbConfigSchema, |
| 39 | shortLink: z.object({ |
| 40 | baseUrl: z.string().default(''), |
| 41 | }), |
| 42 | bilibili: bilibiliConfigSchema.optional(), |
| 43 | douyin: douyinConfigSchema.optional(), |
| 44 | facebook: facebookConfigSchema.optional(), |
| 45 | kwai: kwaiConfigSchema.optional(), |
| 46 | instagram: instagramConfigSchema.optional(), |
| 47 | linkedin: linkedinConfigSchema.optional(), |
| 48 | googleBusiness: googleBusinessConfigSchema.optional(), |
| 49 | pinterest: pinterestConfigSchema.optional(), |
| 50 | rednote: rednoteConfigSchema.optional(), |
| 51 | threads: threadsConfigSchema.optional(), |
| 52 | tiktok: tiktokConfigSchema.optional(), |
| 53 | twitter: twitterConfigSchema.optional(), |
| 54 | wechat: wechatConfigSchema.optional(), |
| 55 | youtube: youtubeConfigSchema.optional(), |
| 56 | }) |
| 57 | |
| 58 | export const appConfigSchema = z.object({ |
| 59 | ...baseConfig.shape, |
| 60 | environment: z.enum(['development', 'production']).default('development'), |
| 61 | auth: aitoearnAuthConfigSchema, |
| 62 | apiKey: apiKeyConfigSchema, |
| 63 | redis: redisConfigSchema, |
| 64 | mongodb: mongodbConfigSchema, |
| 65 | redlock: redlockConfigSchema, |
| 66 | assets: assetsConfigSchema, |
| 67 | aiClient: aitoearnAiClientConfigSchema, |
| 68 | channel: channelConfigSchema, |
| 69 | relay: relayConfigSchema.optional(), |
| 70 | }) |
| 71 | |
| 72 | export class AppConfig extends createZodDto(appConfigSchema) { } |
| 73 | |
| 74 | export const config = selectConfig(AppConfig) |
| 75 |