42 lines
1012 B
TypeScript
42 lines
1012 B
TypeScript
import logger from "@egg/logger"
|
|
import { RecordModel } from "pocketbase"
|
|
|
|
import pbClient from "../db/pbClient"
|
|
|
|
interface ConfigModel extends RecordModel {
|
|
key: string
|
|
value: string
|
|
desc: string
|
|
}
|
|
|
|
export interface AppInfoModel extends RecordModel {
|
|
name: string
|
|
appId: string
|
|
appSecret: string
|
|
appName: 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(`Get env list: ${JSON.stringify(APP_CONFIG)}`)
|
|
// 获取所有应用信息
|
|
const appList = await pbClient.collection<AppInfoModel>("app").getFullList()
|
|
for (const app of appList) {
|
|
APP_MAP[app.name] = app
|
|
}
|
|
logger.info(`Get app list: ${JSON.stringify(APP_MAP)}`)
|
|
}
|
|
|
|
export default initAppConfig
|