Skip to content

Commit 801183f

Browse files
hyriousaderan
authored andcommitted
refactor: add more fields to region configs (#752)
* refactor: add more fields to region configs * enforce filename style * add censorship config * add config hash
1 parent 93abd3f commit 801183f

File tree

7 files changed

+72
-16
lines changed

7 files changed

+72
-16
lines changed

config/defaults.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ agora:
177177
secret:
178178

179179
whiteboard:
180+
app_id:
180181
access_key:
181182
secret_access_key:
182183
convert_region:

config/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ agora:
172172
secret:
173173

174174
whiteboard:
175+
app_id: "test/flat-server"
175176
access_key: "test"
176177
secret_access_key: "test"
177178
convert_region: "cn-hz"

src/constants/Config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export const JWT = {
161161
};
162162

163163
export const Whiteboard = {
164+
appId: config.whiteboard.app_id,
164165
accessKey: config.whiteboard.access_key,
165166
secretAccessKey: config.whiteboard.secret_access_key,
166167
convertRegion: config.whiteboard.convert_region,

src/utils/ParseConfig.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import yaml from "js-yaml";
22
import fs from "fs";
33
import path from "path";
4+
import crypto from "crypto";
45

56
const configDirPath =
67
process.env.IS_TEST === "yes"
@@ -24,6 +25,8 @@ const configPath = (() => {
2425

2526
const yamlContent = fs.readFileSync(configPath, "utf8");
2627

28+
export const configHash = crypto.createHash("md5").update(yamlContent).digest("hex");
29+
2730
export const config = yaml.load(yamlContent) as Config;
2831

2932
type Config = {
@@ -195,6 +198,7 @@ type Config = {
195198
};
196199
};
197200
whiteboard: {
201+
app_id: string;
198202
access_key: string;
199203
secret_access_key: string;
200204
convert_region: "cn-hz" | "us-sv" | "sg" | "in-mum" | "gb-lon";

src/v2/controllers/configs/__tests__/fetchRegionConfig.ts renamed to src/v2/controllers/configs/__tests__/fetch-region-config.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import test from "ava";
22
import { HelperAPI } from "../../../__tests__/helpers/api";
3-
import { regionConfigs, regionConfigsRouters } from "../regionConfigs";
3+
import { regionConfigs, regionConfigsRouters } from "../region-configs";
44
import { initializeDataSource } from "../../../__tests__/helpers/db/test-hooks";
55

66
const namespace = "v2.controllers.region.configs";
77
initializeDataSource(test, namespace);
88

99
test(`${namespace} - fetch region configs`, async ava => {
10-
1110
const helperAPI = new HelperAPI();
1211
await helperAPI.import(regionConfigsRouters, regionConfigs);
1312

@@ -16,8 +15,8 @@ test(`${namespace} - fetch region configs`, async ava => {
1615
method: "GET",
1716
url: "/v2/region/configs",
1817
});
19-
const s = resp.payload
20-
console.log(s)
18+
const s = resp.payload;
19+
console.log(s);
2120
ava.is(resp.statusCode, 200);
2221
const data = (await resp.json()).data;
2322
ava.true(data.login.wechatWeb);
@@ -31,5 +30,4 @@ test(`${namespace} - fetch region configs`, async ava => {
3130
ava.is(data.server.region, "CN");
3231
ava.is(data.server.regionCode, 1);
3332
}
34-
3533
});

src/v2/controllers/configs/regionConfigs.ts renamed to src/v2/controllers/configs/region-configs.ts

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@ import { Server } from "../../../utils/registryRoutersV2";
44
import { Type } from "@sinclair/typebox";
55
import { successJSON } from "../internal/utils/response-json";
66

7+
import { configHash } from "../../../utils/ParseConfig";
78
import {
8-
Server as ServerConfig, WeChat, Github, Google, Apple, AgoraLogin,
9-
PhoneSMS, Whiteboard, Agora, CloudStorage
9+
Server as ServerConfig,
10+
WeChat,
11+
Github,
12+
Google,
13+
Apple,
14+
AgoraLogin,
15+
PhoneSMS,
16+
Whiteboard,
17+
Agora,
18+
CloudStorage,
19+
StorageService,
20+
Censorship,
1021
} from "../../../constants/Config";
1122

1223
type regionConfigsResponseSchema = {
24+
hash: string;
1325
login: {
1426
wechatWeb: boolean;
1527
wechatMobile: boolean;
@@ -19,29 +31,49 @@ type regionConfigsResponseSchema = {
1931
agora: boolean;
2032
sms: boolean;
2133
smsForce: boolean;
22-
},
34+
};
2335
server: {
2436
region: string;
2537
regionCode: number;
2638
env: string;
27-
},
39+
};
2840
whiteboard: {
41+
appId: string;
2942
convertRegion: string;
30-
},
43+
};
3144
agora: {
45+
clientId: string;
46+
appId: string;
3247
screenshot: boolean;
3348
messageNotification: boolean;
34-
},
49+
};
50+
github: {
51+
clientId: string;
52+
};
53+
wechat: {
54+
webAppId: string;
55+
mobileAppId: string;
56+
};
57+
google: {
58+
clientId: string;
59+
};
3560
cloudStorage: {
3661
singleFileSize: number;
37-
totleSize: number;
62+
totalSize: number;
3863
allowFileSuffix: Array<String>;
64+
accessKey: string;
65+
};
66+
censorship: {
67+
video: boolean;
68+
voice: boolean;
69+
text: boolean;
3970
};
4071
};
4172

4273
// export for unit test
4374
export const regionConfigs = async (): Promise<ResponseSuccess<regionConfigsResponseSchema>> => {
4475
return successJSON({
76+
hash: configHash,
4577
login: {
4678
wechatWeb: WeChat.web.enable,
4779
wechatMobile: WeChat.mobile.enable,
@@ -58,17 +90,36 @@ export const regionConfigs = async (): Promise<ResponseSuccess<regionConfigsResp
5890
env: ServerConfig.env,
5991
},
6092
whiteboard: {
61-
convertRegion: Whiteboard.convertRegion
93+
appId: Whiteboard.appId,
94+
convertRegion: Whiteboard.convertRegion,
6295
},
6396
agora: {
97+
clientId: AgoraLogin.clientId,
98+
appId: Agora.appId,
6499
screenshot: Agora.screenshot.enable,
65100
messageNotification: Agora.messageNotification.enable,
66101
},
102+
github: {
103+
clientId: Github.clientId,
104+
},
105+
wechat: {
106+
webAppId: WeChat.web.appId,
107+
mobileAppId: WeChat.mobile.appId,
108+
},
109+
google: {
110+
clientId: Google.clientId,
111+
},
67112
cloudStorage: {
68113
singleFileSize: CloudStorage.singleFileSize,
69-
totleSize: CloudStorage.totalSize,
114+
totalSize: CloudStorage.totalSize,
70115
allowFileSuffix: CloudStorage.allowFileSuffix,
71-
}
116+
accessKey: StorageService.oss.accessKey,
117+
},
118+
censorship: {
119+
video: Censorship.video.enable,
120+
voice: Censorship.voice.enable,
121+
text: Censorship.text.enable,
122+
},
72123
});
73124
};
74125

src/v2/controllers/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { applicationRouters } from "./application/routes";
55
import { roomRouters } from "./room/routes";
66
import { oauthRouters } from "./auth2/routes";
77
import { tempPhotoRouters } from "./temp-photo/routes";
8-
import { regionConfigsRouters } from "./configs/regionConfigs";
8+
import { regionConfigsRouters } from "./configs/region-configs";
99
import { registerRouters } from "./register/routes";
1010
import { loginRouters } from "./login/routes";
1111
import { resetRouters } from "./reset/routes";

0 commit comments

Comments
 (0)