46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import logger from "@egg/logger"
|
|
import { RecordModel } from "pocketbase"
|
|
|
|
import pbClient from "../db/pbClient"
|
|
|
|
interface Config extends RecordModel {
|
|
key: string
|
|
value: string
|
|
desc: string
|
|
}
|
|
|
|
export interface AppInfo extends RecordModel {
|
|
name: string
|
|
app_id: string
|
|
app_secret: string
|
|
app_name: string
|
|
}
|
|
|
|
export const APP_CONFIG: Record<string, string> = {}
|
|
|
|
export const APP_MAP: Record<string, Omit<AppInfo, "name">> = {}
|
|
|
|
/**
|
|
* 初始化应用配置
|
|
*/
|
|
const initAppConfig = async () => {
|
|
// 获取所有环境变量
|
|
const envList = await pbClient.collection<Config>("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<AppInfo>("app").getFullList()
|
|
for (const app of appList) {
|
|
APP_MAP[app.name] = {
|
|
app_id: app.app_id,
|
|
app_secret: app.app_secret,
|
|
app_name: app.app_name,
|
|
}
|
|
}
|
|
logger.info(`Get app list: ${JSON.stringify(APP_MAP)}`)
|
|
}
|
|
|
|
export default initAppConfig
|