diff --git a/config/defaults.yaml b/config/defaults.yaml index 0e3e7685..c0f611db 100644 --- a/config/defaults.yaml +++ b/config/defaults.yaml @@ -177,6 +177,7 @@ agora: secret: whiteboard: + app_id: access_key: secret_access_key: convert_region: diff --git a/config/test.yaml b/config/test.yaml index fac912fa..ec728439 100644 --- a/config/test.yaml +++ b/config/test.yaml @@ -172,6 +172,7 @@ agora: secret: whiteboard: + app_id: "test/flat-server" access_key: "test" secret_access_key: "test" convert_region: "cn-hz" diff --git a/src/constants/Config.ts b/src/constants/Config.ts index 2252c6ac..cc3533c6 100644 --- a/src/constants/Config.ts +++ b/src/constants/Config.ts @@ -161,6 +161,7 @@ export const JWT = { }; export const Whiteboard = { + appId: config.whiteboard.app_id, accessKey: config.whiteboard.access_key, secretAccessKey: config.whiteboard.secret_access_key, convertRegion: config.whiteboard.convert_region, diff --git a/src/utils/ParseConfig.ts b/src/utils/ParseConfig.ts index 82f6d4cc..8bf5c8fc 100644 --- a/src/utils/ParseConfig.ts +++ b/src/utils/ParseConfig.ts @@ -1,6 +1,7 @@ import yaml from "js-yaml"; import fs from "fs"; import path from "path"; +import crypto from "crypto"; const configDirPath = process.env.IS_TEST === "yes" @@ -24,6 +25,8 @@ const configPath = (() => { const yamlContent = fs.readFileSync(configPath, "utf8"); +export const configHash = crypto.createHash("md5").update(yamlContent).digest("hex"); + export const config = yaml.load(yamlContent) as Config; type Config = { @@ -195,6 +198,7 @@ type Config = { }; }; whiteboard: { + app_id: string; access_key: string; secret_access_key: string; convert_region: "cn-hz" | "us-sv" | "sg" | "in-mum" | "gb-lon"; diff --git a/src/v2/controllers/configs/__tests__/fetchRegionConfig.ts b/src/v2/controllers/configs/__tests__/fetch-region-config.ts similarity index 88% rename from src/v2/controllers/configs/__tests__/fetchRegionConfig.ts rename to src/v2/controllers/configs/__tests__/fetch-region-config.ts index ea48b4ec..cfec61f1 100644 --- a/src/v2/controllers/configs/__tests__/fetchRegionConfig.ts +++ b/src/v2/controllers/configs/__tests__/fetch-region-config.ts @@ -1,13 +1,12 @@ import test from "ava"; import { HelperAPI } from "../../../__tests__/helpers/api"; -import { regionConfigs, regionConfigsRouters } from "../regionConfigs"; +import { regionConfigs, regionConfigsRouters } from "../region-configs"; import { initializeDataSource } from "../../../__tests__/helpers/db/test-hooks"; const namespace = "v2.controllers.region.configs"; initializeDataSource(test, namespace); test(`${namespace} - fetch region configs`, async ava => { - const helperAPI = new HelperAPI(); await helperAPI.import(regionConfigsRouters, regionConfigs); @@ -16,8 +15,8 @@ test(`${namespace} - fetch region configs`, async ava => { method: "GET", url: "/v2/region/configs", }); - const s = resp.payload - console.log(s) + const s = resp.payload; + console.log(s); ava.is(resp.statusCode, 200); const data = (await resp.json()).data; ava.true(data.login.wechatWeb); @@ -31,5 +30,4 @@ test(`${namespace} - fetch region configs`, async ava => { ava.is(data.server.region, "CN"); ava.is(data.server.regionCode, 1); } - }); diff --git a/src/v2/controllers/configs/regionConfigs.ts b/src/v2/controllers/configs/region-configs.ts similarity index 58% rename from src/v2/controllers/configs/regionConfigs.ts rename to src/v2/controllers/configs/region-configs.ts index e1ce1ca1..2395b85f 100644 --- a/src/v2/controllers/configs/regionConfigs.ts +++ b/src/v2/controllers/configs/region-configs.ts @@ -4,12 +4,24 @@ import { Server } from "../../../utils/registryRoutersV2"; import { Type } from "@sinclair/typebox"; import { successJSON } from "../internal/utils/response-json"; +import { configHash } from "../../../utils/ParseConfig"; import { - Server as ServerConfig, WeChat, Github, Google, Apple, AgoraLogin, - PhoneSMS, Whiteboard, Agora, CloudStorage + Server as ServerConfig, + WeChat, + Github, + Google, + Apple, + AgoraLogin, + PhoneSMS, + Whiteboard, + Agora, + CloudStorage, + StorageService, + Censorship, } from "../../../constants/Config"; type regionConfigsResponseSchema = { + hash: string; login: { wechatWeb: boolean; wechatMobile: boolean; @@ -19,29 +31,49 @@ type regionConfigsResponseSchema = { agora: boolean; sms: boolean; smsForce: boolean; - }, + }; server: { region: string; regionCode: number; env: string; - }, + }; whiteboard: { + appId: string; convertRegion: string; - }, + }; agora: { + clientId: string; + appId: string; screenshot: boolean; messageNotification: boolean; - }, + }; + github: { + clientId: string; + }; + wechat: { + webAppId: string; + mobileAppId: string; + }; + google: { + clientId: string; + }; cloudStorage: { singleFileSize: number; - totleSize: number; + totalSize: number; allowFileSuffix: Array; + accessKey: string; + }; + censorship: { + video: boolean; + voice: boolean; + text: boolean; }; }; // export for unit test export const regionConfigs = async (): Promise> => { return successJSON({ + hash: configHash, login: { wechatWeb: WeChat.web.enable, wechatMobile: WeChat.mobile.enable, @@ -58,17 +90,36 @@ export const regionConfigs = async (): Promise