Skip to content

Commit f42670a

Browse files
ooeyunahyrioussiyuvince-hzflat-bot
authored
support sg region (#776)
* chore(ci): remove US deployment (#735) * feat: add region code (#736) * add region code for roomUUID and inviteCode * remove us ci, use CN as default region * fix test.yaml * roomUUID not only uuidv4 format * `region_code` use `1` as default --------- Co-authored-by: siyu <chensiyi@agora.io> * fix(v1): rejoin a deleted room causes incorrect rtc uid (#737) Co-authored-by: xuyunshi <405029644@qq.com> * (fix): cancel roomUUID uuid-v4 format limit (#738) * fix: cancel roomUUID uuid-v4 format limit * cancel room export users api uuid limit --------- Co-authored-by: siyu <chensiyi@agora.io> * fix invite code check (#739) Co-authored-by: siyu <chensiyi@agora.io> * refactor(room): set invite code expiration to 100 days (#740) * feat: add region configs api (#741) Co-authored-by: siyu <chensiyi@agora.io> Co-authored-by: hyrious <hyrious@outlook.com> * feat(v2): add user/rebind-phone{/send-message} (#742) * feat(v2): add user/rebind-phone{/send-message} * use safe phone in checking can send code * update filename * add unit test * feat(v2): add register/phone{/send-message} (#743) feat(v2): add login/phone feat(v2): add user/password feat(v2): add reset/phone{/send-password} add unit test move mysql.salt to login.salt * fix: should use full phone string in database (#746) * chore: deploy sg via ci (for dev) (#747) * add sg ci * remove unuse step # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Thu Aug 3 16:22:13 2023 +0800 # # On branch sa/add_sg_ci # Changes to be committed: # modified: .gitlab-ci.yml # --------- Co-authored-by: siyu <chensiyi@agora.io> * feat: add email support (#745) * feat(v2): add email support feat: add SMTP support * add ajv email, return email send failed, email length = 100 * return phone send failed * fix: wrong return value of send message (#749) * refactor: change all login errors (#748) * refactor: add {hasPassword: boolean} to login responses (#744) * refactor: update email templates (#750) * fix sg deploy (#751) Co-authored-by: siyu <chensiyi@agora.io> * refactor: add more fields to region configs (#752) * refactor: add more fields to region configs * enforce filename style * add censorship config * add config hash * chore(deploy): add dev sg (#756) * chore(deploy): add dev sg * fix: v2 login should return the same structure as v1 (#755) * refactor: generate different avatars for users (#754) * refactor: generate different avatars for users * refactor: update avatar name --------- Co-authored-by: qianzhu <36325249+syt-honey@users.noreply.github.com> * refactor: remove region payload, add whiteboard.region config (#753) * change replicaCount and namespace for dev (#757) Co-authored-by: siyu <chensiyi@agora.io> * fix typing issue introduced in 6a91e5c (#758) * fix helm name conflict (#759) Co-authored-by: siyu <chensiyi@agora.io> * fix helm name for dev deploy (#760) Co-authored-by: siyu <chensiyi@agora.io> * refactor: rebind-phone use lowercase in status keys (#761) * fix: rebind phone should only work with existing account (#762) * refactor(v1): bind email send message support language (#763) * refactor(v1): bind email send message support language * refactor: move email template to a single file * refactor: add binding information in list (#765) * fix guide pptx (#764) * fix v2 setGuidePPTX() failed to insert file * refactor: set only one guide pptx file by convert region * fix: use correct region * fix(v1): register binding email routes (#767) * fix(v1): google use different callbacks to get token (#768) * fix: cannot use "password" format (#766) * fix(v1): list binding missing apple field (#769) * feat(v1): add binding apple api (#770) * fix(v1): add guide pptx in google register process (#771) * fix(v1): add router for apple binding (#772) * fix(v1): apple login find incorrect user (#773) * refactor(v2): remove password limit (#774) * force manual when prod deploy (#775) Co-authored-by: siyu <chensiyi@agora.io> --------- Co-authored-by: hyrious <hyrious@outlook.com> Co-authored-by: siyu <chensiyi@agora.io> Co-authored-by: xuyunshi <405029644@qq.com> Co-authored-by: flat-bot <81130480+flat-bot@users.noreply.github.com> Co-authored-by: qianzhu <36325249+syt-honey@users.noreply.github.com> Co-authored-by: Vince <zjxuyunshi@gmail.com>
1 parent c285913 commit f42670a

File tree

122 files changed

+3707
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+3707
-192
lines changed

.gitlab-ci.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ stages:
2323
HOST_NAME: $HOST_NAME_CHINA
2424
KUBE_CONFIG: $KUBE_CONFIG_CHINA
2525

26-
.us:
26+
.sg:
2727
before_script:
28-
- cp $PROJECT_CONFIG_UNITED_STATES ./helm/files/production.yaml
28+
- cp $PROJECT_CONFIG_SG ./helm/files/production.yaml
2929
variables:
30-
HOST_NAME: $HOST_NAME_UNITED_STATES
31-
KUBE_CONFIG: $KUBE_CONFIG_UNITED_STATES
30+
HOST_NAME: $HOST_NAME_SG
31+
KUBE_CONFIG: $KUBE_CONFIG_SG
3232

3333
.docker_build: &DOCKER_BUILD
3434
stage: build_image
@@ -109,33 +109,46 @@ docker_build_prod:
109109
helm install stakater-reloader stakater/reloader --set reloader.watchGlobally=false --namespace $KUBE_NAMESPACE
110110
fi
111111
112-
- helm upgrade --install flat-server-$CI_ENVIRONMENT_SLUG helm
112+
- helm upgrade --install $HELM_NAME helm --namespace $KUBE_NAMESPACE --set replicaCount=$REPLICA_COUNT
113113

114114
deploy_dev_cn:
115115
<<: *DEPLOY
116116
variables:
117117
DOCKER_TAG: dev-$CI_COMMIT_SHA
118+
KUBE_NAMESPACE: default
119+
REPLICA_COUNT: 2
120+
HELM_NAME: flat-server-development
118121
extends: .cn
119122
<<: *DEV
120123

121-
deploy_dev_us:
124+
deploy_dev_sg:
122125
<<: *DEPLOY
123-
extends: .us
126+
extends: .sg
124127
variables:
125128
DOCKER_TAG: dev-$CI_COMMIT_SHA
129+
KUBE_NAMESPACE: sg
130+
REPLICA_COUNT: 2
131+
HELM_NAME: flat-server-sg-development
126132
<<: *DEV
127133

128134
deploy_prod_cn:
129135
<<: *DEPLOY
130136
extends: .cn
131137
variables:
132138
DOCKER_TAG: $CI_COMMIT_SHA
139+
KUBE_NAMESPACE: default
140+
REPLICA_COUNT: 3
141+
HELM_NAME: flat-server-production
133142
<<: *PROD
143+
when: manual
134144

135-
deploy_prod_us:
145+
deploy_prod_sg:
136146
<<: *DEPLOY
137-
extends: .us
147+
extends: .sg
138148
variables:
139149
DOCKER_TAG: $CI_COMMIT_SHA
150+
KUBE_NAMESPACE: default
151+
REPLICA_COUNT: 3
152+
HELM_NAME: flat-server-production
140153
<<: *PROD
141-
154+
when: manual

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18.17.0

config/defaults.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jwt:
2323

2424
website: https://flat-web-dev.whiteboard.agora.io
2525

26+
default_avatar: https://flat-storage.oss-cn-hangzhou.aliyuncs.com/flat-resources/avatar/[index].png
27+
2628
# flag see: https://github.com/netless-io/flat-server/blob/main/src/utils/EnvVariable.ts
2729
log:
2830
pathname: "{{PROJECT_DIR}}/logs"
@@ -79,6 +81,7 @@ oauth:
7981
- jpeg
8082

8183
login:
84+
salt:
8285
wechat:
8386
web:
8487
enable: false
@@ -97,6 +100,8 @@ login:
97100
client_id:
98101
client_secret:
99102
redirect_uri:
103+
login:
104+
bind:
100105
apple:
101106
enable: false
102107
agora:
@@ -125,6 +130,23 @@ login:
125130
access_secret:
126131
template_code:
127132
sign_name:
133+
email:
134+
enable: true
135+
test_emails:
136+
- email:
137+
code:
138+
type: smtp
139+
smtp:
140+
host: smtpdm.aliyun.com
141+
port: 465
142+
secure: true
143+
auth:
144+
user:
145+
pass:
146+
aliCloud:
147+
access_id:
148+
access_secret:
149+
account_name: test@test.test
128150

129151
agora:
130152
app:
@@ -159,8 +181,10 @@ agora:
159181
secret:
160182

161183
whiteboard:
184+
app_id:
162185
access_key:
163186
secret_access_key:
187+
region:
164188
convert_region:
165189

166190
storage_service:

config/test.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
server:
22
port: 8761
33
env: dev
4+
region: CN
5+
region_code: 1
46

57
redis:
68
host: 127.0.0.1
@@ -23,6 +25,8 @@ jwt:
2325

2426
website: https://flat-web-dev.whiteboard.agora.io
2527

28+
default_avatar: https://flat-storage.oss-cn-hangzhou.aliyuncs.com/flat-resources/avatar/[index].png
29+
2630
log:
2731
pathname: "{{PROJECT_DIR}}/logs"
2832
filename: "{{DAY_DATE}}"
@@ -72,6 +76,7 @@ oauth:
7276
- jpeg
7377

7478
login:
79+
salt: test
7580
wechat:
7681
web:
7782
enable: true
@@ -90,6 +95,8 @@ login:
9095
client_id:
9196
client_secret:
9297
redirect_uri:
98+
login:
99+
bind:
93100
apple:
94101
enable: true
95102
agora:
@@ -118,6 +125,23 @@ login:
118125
access_secret:
119126
template_code:
120127
sign_name:
128+
email:
129+
enable: true
130+
test_emails:
131+
- email:
132+
code:
133+
type: smtp
134+
smtp:
135+
host: smtpdm.aliyun.com
136+
port: 465
137+
secure: true
138+
auth:
139+
user:
140+
pass:
141+
aliCloud:
142+
access_id:
143+
access_secret:
144+
account_name: test@test.test
121145

122146
agora:
123147
app:
@@ -152,8 +176,10 @@ agora:
152176
secret:
153177

154178
whiteboard:
179+
app_id: "test/flat-server"
155180
access_key: "test"
156181
secret_access_key: "test"
182+
region: "cn-hz"
157183
convert_region: "cn-hz"
158184

159185
storage_service:

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@types/lodash": "^4.14.170",
2424
"@types/node": "^18.0.0",
2525
"@types/node-rsa": "^1.1.1",
26+
"@types/nodemailer": "^6.4.9",
2627
"@types/qs": "^6.9.7",
2728
"@types/query-string": "^6.3.0",
2829
"@types/sinon": "^10.0.12",
@@ -58,6 +59,7 @@
5859
"webpack-node-externals": "^3.0.0"
5960
},
6061
"dependencies": {
62+
"@alicloud/dm20151123": "^1.0.6",
6163
"@alicloud/dysmsapi20170525": "^2.0.9",
6264
"@alicloud/openapi-client": "^0.4.1",
6365
"@fastify-userland/request-id": "^2.0.1",
@@ -89,6 +91,7 @@
8991
"mysql2": "^2.2.5",
9092
"nanoid": "^3.1.31",
9193
"node-rsa": "^1.1.1",
94+
"nodemailer": "^6.9.4",
9295
"prom-client": "^14.0.0",
9396
"qs": "^6.10.3",
9497
"reflect-metadata": "^0.1.13",

src/ErrorCode.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export enum ErrorCode {
2525
UserNotFound = 400000, // user not found
2626
UserRoomListNotEmpty, // user room list is not empty.
2727
UserAlreadyBinding, // user already binding
28+
UserPasswordIncorrect, // user password (for update) incorrect
29+
UserOrPasswordIncorrect, // user or password (for login) incorrect
2830

2931
RecordNotFound = 500000, // record info not found
3032

@@ -50,6 +52,12 @@ export enum ErrorCode {
5052
SMSVerificationCodeInvalid = 110000, // verification code invalid
5153
SMSAlreadyExist, // phone already exist by current user
5254
SMSAlreadyBinding, // phone are binding by other users
55+
SMSFailedToSendCode, // failed to send verification code
56+
57+
EmailVerificationCodeInvalid = 115000, // verification code invalid
58+
EmailAlreadyExist, // email already exist by current user
59+
EmailAlreadyBinding, // email are binding by other users
60+
EmailFailedToSendCode, // failed to send verification code
5361

5462
CensorshipFailed = 120000, // censorship failed
5563

src/abstract/login/index.ts

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { ErrorCode } from "../../ErrorCode";
55
import { ControllerError } from "../../error/ControllerError";
66
import { Logger, LoggerAPI } from "../../logger";
77
import { getDisposition, ossClient } from "../../v1/controller/cloudStorage/alibabaCloud/Utils";
8-
import { Region } from "../../constants/Project";
98
import {
109
getFilePath,
1110
getOSSFileURLPath,
@@ -17,6 +16,8 @@ import { v4 } from "uuid";
1716
import { ServiceCloudStorageUserFiles } from "../../v1/service/cloudStorage/CloudStorageUserFiles";
1817
import { ServiceUserPhone } from "../../v1/service/user/UserPhone";
1918
import { FileConvertStep, FileResourceType } from "../../model/cloudStorage/Constants";
19+
import { ServiceUser } from "../../v1/service/user/User";
20+
import { Whiteboard } from "../../constants/Config";
2021

2122
export abstract class AbstractLogin {
2223
protected readonly userUUID: string;
@@ -49,6 +50,7 @@ export abstract class AbstractLogin {
4950
...userInfo,
5051
userUUID: this.userUUID,
5152
hasPhone: await ServiceUserPhone.exist(this.userUUID),
53+
hasPassword: await ServiceUser.hasPassword(this.userUUID),
5254
}),
5355
60 * 60,
5456
);
@@ -62,53 +64,35 @@ export abstract class AbstractLogin {
6264
},
6365
t: EntityManager,
6466
): Promise<any> {
65-
const [cnFileUUID, enFileUUID] = [v4(), v4()];
66-
const [cnName, enName] = ["开始使用 Flat.pptx", "Get Started with Flat.pptx"];
67-
const [cnPPTXPath, enPPTXPath] = [
68-
getFilePath(cnName, cnFileUUID),
69-
getFilePath(enName, enFileUUID),
70-
];
71-
const [cnFileSize, enFileSize] = [5027927, 5141265];
67+
const CN = Whiteboard.convertRegion === "cn-hz";
7268

73-
await Promise.all([
74-
ossClient.copy(cnPPTXPath, AbstractLogin.guidePPTX, {
75-
headers: { "Content-Disposition": getDisposition(cnName) },
76-
}),
77-
ossClient.copy(enPPTXPath, AbstractLogin.guidePPTX, {
78-
headers: { "Content-Disposition": getDisposition(enName) },
79-
}),
80-
]);
69+
const fileUUID = v4();
70+
const name = CN ? "开始使用 Flat.pptx" : "Get Started with Flat.pptx";
71+
const pptxPath = getFilePath(name, fileUUID);
72+
const fileSize = CN ? 5027927 : 5141265;
73+
74+
await ossClient.copy(pptxPath, AbstractLogin.guidePPTX, {
75+
headers: { "Content-Disposition": getDisposition(name) },
76+
});
8177

8278
return Promise.all([
83-
svc.cloudStorageConfigs.createOrUpdate(cnFileSize + enFileSize, t),
84-
svc.cloudStorageFiles.create({
85-
payload: {
86-
region: Region.CN_HZ,
87-
convertStep: FileConvertStep.None,
88-
},
89-
fileURL: getOSSFileURLPath(cnPPTXPath),
90-
fileSize: cnFileSize,
91-
fileUUID: cnFileUUID,
92-
fileName: cnName,
93-
resourceType: FileResourceType.WhiteboardProjector,
94-
}),
79+
svc.cloudStorageConfigs.createOrUpdate(fileSize, t),
9580
svc.cloudStorageFiles.create({
9681
payload: {
97-
region: Region.US_SV,
82+
region: Whiteboard.convertRegion,
9883
convertStep: FileConvertStep.None,
9984
},
100-
fileURL: getOSSFileURLPath(enPPTXPath),
101-
fileSize: enFileSize,
102-
fileUUID: enFileUUID,
103-
fileName: enName,
85+
fileURL: getOSSFileURLPath(pptxPath),
86+
fileSize: fileSize,
87+
fileUUID: fileUUID,
88+
fileName: name,
10489
resourceType: FileResourceType.WhiteboardProjector,
10590
}),
106-
svc.cloudStorageUserFiles.create(cnFileUUID),
107-
svc.cloudStorageUserFiles.create(enFileUUID),
91+
svc.cloudStorageUserFiles.create(fileUUID),
10892
]);
10993
}
11094

111-
private static get guidePPTX(): string {
95+
public static get guidePPTX(): string {
11296
return "guide-pptx/guide.pptx";
11397
}
11498
}

0 commit comments

Comments
 (0)