Skip to content

Commit 68ffcda

Browse files
committed
refactor: remove region payload, add whiteboard.region config (#753)
1 parent 5cfd188 commit 68ffcda

File tree

7 files changed

+16
-7
lines changed

7 files changed

+16
-7
lines changed

config/defaults.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ whiteboard:
182182
app_id:
183183
access_key:
184184
secret_access_key:
185+
region:
185186
convert_region:
186187

187188
storage_service:

config/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ whiteboard:
177177
app_id: "test/flat-server"
178178
access_key: "test"
179179
secret_access_key: "test"
180+
region: "cn-hz"
180181
convert_region: "cn-hz"
181182

182183
storage_service:

src/constants/Config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export const Whiteboard = {
168168
appId: config.whiteboard.app_id,
169169
accessKey: config.whiteboard.access_key,
170170
secretAccessKey: config.whiteboard.secret_access_key,
171+
region: config.whiteboard.region,
171172
convertRegion: config.whiteboard.convert_region,
172173
};
173174

src/utils/ParseConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ type Config = {
202202
app_id: string;
203203
access_key: string;
204204
secret_access_key: string;
205+
region: "cn-hz" | "us-sv" | "sg" | "in-mum" | "gb-lon";
205206
convert_region: "cn-hz" | "us-sv" | "sg" | "in-mum" | "gb-lon";
206207
};
207208
storage_service: {

src/v1/controller/room/create/Ordinary.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class CreateOrdinary extends AbstractController<RequestType, ResponseType
2525
public static readonly schema: FastifySchema<RequestType> = {
2626
body: {
2727
type: "object",
28-
required: ["title", "type", "region"],
28+
required: ["title", "type"],
2929
properties: {
3030
title: {
3131
type: "string",
@@ -48,6 +48,7 @@ export class CreateOrdinary extends AbstractController<RequestType, ResponseType
4848
region: {
4949
type: "string",
5050
enum: [Region.CN_HZ, Region.US_SV, Region.SG, Region.IN_MUM, Region.GB_LON],
51+
nullable: true,
5152
},
5253
},
5354
},
@@ -128,7 +129,7 @@ export interface RequestType {
128129
type: RoomType;
129130
beginTime?: number;
130131
endTime?: number;
131-
region: Region;
132+
region?: Region;
132133
};
133134
}
134135

src/v1/controller/room/create/Periodic.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { rtcQueue } from "../../../queue";
2323
import { aliGreenText } from "../../../utils/AliGreen";
2424
import { ControllerError } from "../../../../error/ControllerError";
2525
import { dataSource } from "../../../../thirdPartyService/TypeORMService";
26+
import { Whiteboard } from "../../../../constants/Config";
2627

2728
@Controller<RequestType, ResponseType>({
2829
method: "post",
@@ -33,7 +34,7 @@ export class CreatePeriodic extends AbstractController<RequestType, ResponseType
3334
public static readonly schema: FastifySchema<RequestType> = {
3435
body: {
3536
type: "object",
36-
required: ["title", "type", "beginTime", "endTime", "region", "periodic"],
37+
required: ["title", "type", "beginTime", "endTime", "periodic"],
3738
properties: {
3839
title: {
3940
type: "string",
@@ -54,6 +55,7 @@ export class CreatePeriodic extends AbstractController<RequestType, ResponseType
5455
region: {
5556
type: "string",
5657
enum: [Region.CN_HZ, Region.US_SV, Region.SG, Region.IN_MUM, Region.GB_LON],
58+
nullable: true,
5759
},
5860
periodic: {
5961
type: "object",
@@ -105,7 +107,8 @@ export class CreatePeriodic extends AbstractController<RequestType, ResponseType
105107
private readonly periodicUUID = v4();
106108

107109
public async execute(): Promise<Response<ResponseType>> {
108-
const { title, type, beginTime, endTime, region, periodic } = this.body;
110+
const region = Whiteboard.region as Region;
111+
const { title, type, beginTime, endTime, periodic } = this.body;
109112
const userUUID = this.userUUID;
110113

111114
if (await aliGreenText.textNonCompliant(title)) {
@@ -224,7 +227,7 @@ interface RequestType {
224227
type: RoomType;
225228
beginTime: number;
226229
endTime: number;
227-
region: Region;
230+
region?: Region;
228231
periodic: Periodic;
229232
};
230233
}

src/v1/service/room/Room.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { RoomStatus, RoomType } from "../../../model/room/Constants";
99
import { whiteboardCreateRoom } from "../../utils/request/whiteboard/WhiteboardRequest";
1010
import { addHours, toDate } from "date-fns/fp";
1111
import { InsertResult } from "typeorm/query-builder/result/InsertResult";
12+
import { Whiteboard } from "../../../constants/Config";
1213

1314
export class ServiceRoom {
1415
constructor(private readonly roomUUID: string, private readonly userUUID: string) {}
@@ -58,13 +59,13 @@ export class ServiceRoom {
5859
data: {
5960
title: string;
6061
type: RoomType;
61-
region: Region;
6262
beginTime?: number | Date;
6363
endTime?: number | Date;
6464
},
6565
t?: EntityManager,
6666
): Promise<InsertResult> {
67-
const { title, type, region, endTime } = data;
67+
const region = Whiteboard.region as Region;
68+
const { title, type, endTime } = data;
6869
const beginTime = data.beginTime || Date.now();
6970

7071
return await RoomDAO(t).insert({

0 commit comments

Comments
 (0)