egg_server/constant/config.ts

44 lines
1.0 KiB
TypeScript

import logger from "@egg/logger"
import { RecordModel } from "pocketbase"
import pbClient from "../db/pbClient"
export interface ConfigModel extends RecordModel {
key: string
value: string
desc: string
}
export interface AppInfoModel extends RecordModel {
name: string
appId: string
appSecret: string
appName: string
errChatId: string
}
export const APP_CONFIG: Record<string, string> = {}
export const APP_MAP: Record<string, AppInfoModel> = {}
/**
* 初始化应用配置
*/
const initAppConfig = async () => {
// 获取所有环境变量
const envList = await pbClient.collection<ConfigModel>("env").getFullList()
for (const env of envList) {
APP_CONFIG[env.key] = env.value
}
logger.info("获取环境变量列表", { envList: APP_CONFIG })
// 获取所有应用信息
const appList = await pbClient.collection<AppInfoModel>("app").getFullList()
for (const app of appList) {
APP_MAP[app.name] = app
}
logger.info("获取应用列表", { appList: APP_MAP })
}
export default initAppConfig