Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docker): add docker-compose-local #730

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9d9650d
chore(docker): add docker-compose-local
aderan Jun 5, 2023
4f95654
fix(record): keep record transcodingConfig limit to 1920*1080 (#733)
vince-hz Jul 3, 2023
bf2e3b4
fix(record): update agora record transcodingConfig limitation (#734)
vince-hz Jul 3, 2023
4928867
chore(ci): remove US deployment (#735)
hyrious Jul 3, 2023
43c9478
feat: add region code (#736)
ooeyuna Jul 19, 2023
df16feb
fix(v1): rejoin a deleted room causes incorrect rtc uid (#737)
hyrious Jul 19, 2023
3c12f43
(fix): cancel roomUUID uuid-v4 format limit (#738)
ooeyuna Jul 19, 2023
8d576bf
fix invite code check (#739)
ooeyuna Jul 25, 2023
2b00cd9
refactor(room): set invite code expiration to 100 days (#740)
hyrious Jul 25, 2023
aa307d4
feat: add region configs api (#741)
ooeyuna Jul 28, 2023
644f70d
feat(v2): add user/rebind-phone{/send-message} (#742)
hyrious Aug 3, 2023
8d27bd7
feat(v2): add register/phone{/send-message} (#743)
hyrious Aug 3, 2023
8f6fef7
fix: should use full phone string in database (#746)
hyrious Aug 3, 2023
7a7bb78
chore: deploy sg via ci (for dev) (#747)
flat-bot Aug 3, 2023
76cf885
feat: add email support (#745)
hyrious Aug 3, 2023
e83c1a7
fix: wrong return value of send message (#749)
hyrious Aug 4, 2023
383726b
refactor: change all login errors (#748)
hyrious Aug 4, 2023
ea9e16a
refactor: add {hasPassword: boolean} to login responses (#744)
hyrious Aug 4, 2023
8ede9c4
refactor: update email templates (#750)
hyrious Aug 4, 2023
93abd3f
fix sg deploy (#751)
ooeyuna Aug 4, 2023
801183f
refactor: add more fields to region configs (#752)
hyrious Aug 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ stages:
HOST_NAME: $HOST_NAME_CHINA
KUBE_CONFIG: $KUBE_CONFIG_CHINA

.us:
.sg:
before_script:
- cp $PROJECT_CONFIG_UNITED_STATES ./helm/files/production.yaml
- cp $PROJECT_CONFIG_SG ./helm/files/production.yaml
variables:
HOST_NAME: $HOST_NAME_UNITED_STATES
KUBE_CONFIG: $KUBE_CONFIG_UNITED_STATES
HOST_NAME: $HOST_NAME_SG
KUBE_CONFIG: $KUBE_CONFIG_SG

.docker_build: &DOCKER_BUILD
stage: build_image
Expand Down Expand Up @@ -118,24 +118,16 @@ deploy_dev_cn:
extends: .cn
<<: *DEV

deploy_dev_us:
<<: *DEPLOY
extends: .us
variables:
DOCKER_TAG: dev-$CI_COMMIT_SHA
<<: *DEV

deploy_prod_cn:
<<: *DEPLOY
extends: .cn
variables:
DOCKER_TAG: $CI_COMMIT_SHA
<<: *PROD

deploy_prod_us:
deploy_prod_sg:
<<: *DEPLOY
extends: .us
extends: .sg
variables:
DOCKER_TAG: $CI_COMMIT_SHA
<<: *PROD

DOCKER_TAG: dev-$CI_COMMIT_SHA
<<: *DEV
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.17.0
19 changes: 19 additions & 0 deletions config/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ oauth:
- jpeg

login:
salt:
wechat:
web:
enable: false
Expand Down Expand Up @@ -125,6 +126,23 @@ login:
access_secret:
template_code:
sign_name:
email:
enable: true
test_emails:
- email:
code:
type: smtp
smtp:
host: smtpdm.aliyun.com
port: 465
secure: true
auth:
user:
pass:
aliCloud:
access_id:
access_secret:
account_name: [email protected]

agora:
app:
Expand Down Expand Up @@ -159,6 +177,7 @@ agora:
secret:

whiteboard:
app_id:
access_key:
secret_access_key:
convert_region:
Expand Down
21 changes: 21 additions & 0 deletions config/test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
server:
port: 8761
env: dev
region: CN
region_code: 1

redis:
host: 127.0.0.1
Expand Down Expand Up @@ -72,6 +74,7 @@ oauth:
- jpeg

login:
salt: test
wechat:
web:
enable: true
Expand Down Expand Up @@ -118,6 +121,23 @@ login:
access_secret:
template_code:
sign_name:
email:
enable: true
test_emails:
- email:
code:
type: smtp
smtp:
host: smtpdm.aliyun.com
port: 465
secure: true
auth:
user:
pass:
aliCloud:
access_id:
access_secret:
account_name: [email protected]

agora:
app:
Expand Down Expand Up @@ -152,6 +172,7 @@ agora:
secret:

whiteboard:
app_id: "test/flat-server"
access_key: "test"
secret_access_key: "test"
convert_region: "cn-hz"
Expand Down
29 changes: 29 additions & 0 deletions docker/docker-compose-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3'
name: flat-server-local
services:
redis:
image: redis
container_name: redis
ports:
- 7528:6379
volumes:
- redis_data:/data
environment:
- REDIS_PASSWORD=flat-server-test

mysql:
image: mysql
container_name: mysql
ports:
- 7519:3306
environment:
- MYSQL_ROOT_PASSWORD=flat-server-test
- MYSQL_DATABASE=flat_server
command:
--default-authentication-plugin=mysql_native_password
volumes:
- mysql_data:/var/lib/mysql

volumes:
redis_data:
mysql_data:
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"test:sync:orm": "ts-node -r dotenv-flow/config scripts/sync-orm.ts -- --default-node-env=test --dotenv-flow-path=config",
"test:local": "./scripts/prepare-test-env.sh && yarn run test:sync:orm && yarn run test",
"test": "c8 --reporter=html ava",
"docker:local:up": "docker compose -f docker/docker-compose-local.yml up --detach",
"docker:local:down": "docker compose -f docker/docker-compose-local.yml down",
"lint": "lint-staged"
},
"devDependencies": {
Expand All @@ -23,6 +25,7 @@
"@types/lodash": "^4.14.170",
"@types/node": "^18.0.0",
"@types/node-rsa": "^1.1.1",
"@types/nodemailer": "^6.4.9",
"@types/qs": "^6.9.7",
"@types/query-string": "^6.3.0",
"@types/sinon": "^10.0.12",
Expand Down Expand Up @@ -58,6 +61,7 @@
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"@alicloud/dm20151123": "^1.0.6",
"@alicloud/dysmsapi20170525": "^2.0.9",
"@alicloud/openapi-client": "^0.4.1",
"@fastify-userland/request-id": "^2.0.1",
Expand Down Expand Up @@ -89,6 +93,7 @@
"mysql2": "^2.2.5",
"nanoid": "^3.1.31",
"node-rsa": "^1.1.1",
"nodemailer": "^6.9.4",
"prom-client": "^14.0.0",
"qs": "^6.10.3",
"reflect-metadata": "^0.1.13",
Expand Down
8 changes: 8 additions & 0 deletions src/ErrorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export enum ErrorCode {
UserNotFound = 400000, // user not found
UserRoomListNotEmpty, // user room list is not empty.
UserAlreadyBinding, // user already binding
UserPasswordIncorrect, // user password (for update) incorrect
UserOrPasswordIncorrect, // user or password (for login) incorrect

RecordNotFound = 500000, // record info not found

Expand All @@ -50,6 +52,12 @@ export enum ErrorCode {
SMSVerificationCodeInvalid = 110000, // verification code invalid
SMSAlreadyExist, // phone already exist by current user
SMSAlreadyBinding, // phone are binding by other users
SMSFailedToSendCode, // failed to send verification code

EmailVerificationCodeInvalid = 115000, // verification code invalid
EmailAlreadyExist, // email already exist by current user
EmailAlreadyBinding, // email are binding by other users
EmailFailedToSendCode, // failed to send verification code

CensorshipFailed = 120000, // censorship failed

Expand Down
4 changes: 3 additions & 1 deletion src/abstract/login/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { v4 } from "uuid";
import { ServiceCloudStorageUserFiles } from "../../v1/service/cloudStorage/CloudStorageUserFiles";
import { ServiceUserPhone } from "../../v1/service/user/UserPhone";
import { FileConvertStep, FileResourceType } from "../../model/cloudStorage/Constants";
import { ServiceUser } from "../../v1/service/user/User";

export abstract class AbstractLogin {
protected readonly userUUID: string;
Expand Down Expand Up @@ -49,6 +50,7 @@ export abstract class AbstractLogin {
...userInfo,
userUUID: this.userUUID,
hasPhone: await ServiceUserPhone.exist(this.userUUID),
hasPassword: await ServiceUser.hasPassword(this.userUUID),
}),
60 * 60,
);
Expand Down Expand Up @@ -108,7 +110,7 @@ export abstract class AbstractLogin {
]);
}

private static get guidePPTX(): string {
public static get guidePPTX(): string {
return "guide-pptx/guide.pptx";
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/constants/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const Server = {
name: "flat-server",
version: packages.version,
env: config.server.env,
region: config.server.region || "CN",
// value: 1-9
regionCode: config.server.region_code || 1,
};

export const Redis = {
Expand All @@ -28,6 +31,8 @@ export const MySQL = {
db: config.mysql.db,
};

export const Salt = config.login.salt;

export const Website = config.website;

export const WeChat = {
Expand Down Expand Up @@ -95,6 +100,31 @@ export const PhoneSMS = {
},
};

export const EmailSMS = {
enable: config.login.email.enable,
testEmails: config.login.email.test_emails.map(user => {
return {
email: String(user.email),
code: user.code,
};
}),
type: config.login.email.type,
aliCloud: {
accessId: config.login.email.aliCloud.access_id,
accessSecret: config.login.email.aliCloud.access_secret,
accountName: config.login.email.aliCloud.account_name,
},
smtp: {
host: config.login.email.smtp.host,
port: config.login.email.smtp.port,
secure: config.login.email.smtp.secure,
auth: {
user: config.login.email.smtp.auth.user,
pass: config.login.email.smtp.auth.pass,
},
},
};

export const Agora = {
appId: config.agora.app.id,
appCertificate: config.agora.app.certificate,
Expand Down Expand Up @@ -131,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,
Expand Down
1 change: 1 addition & 0 deletions src/constants/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum LoginPlatform {
Agora = "Agora",
Google = "Google",
Phone = "Phone",
Email = "Email",
}

export enum Gender {
Expand Down
3 changes: 3 additions & 0 deletions src/dao/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { UserAgoraModel } from "../model/user/Agora";
import { UserGoogleModel } from "../model/user/Google";
import { UserPhoneModel } from "../model/user/Phone";
import { UserSensitiveModel } from "../model/user/Sensitive";
import { UserEmailModel } from "../model/user/Email";

export const UserDAO = DAOImplement(UserModel) as ReturnType<DAO<UserModel>>;

Expand All @@ -32,6 +33,8 @@ export const UserGoogleDAO = DAOImplement(UserGoogleModel) as ReturnType<DAO<Use

export const UserPhoneDAO = DAOImplement(UserPhoneModel) as ReturnType<DAO<UserPhoneModel>>;

export const UserEmailDAO = DAOImplement(UserEmailModel) as ReturnType<DAO<UserEmailModel>>;

export const UserSensitiveDAO = DAOImplement(UserSensitiveModel) as ReturnType<
DAO<UserSensitiveModel>
>;
Expand Down
13 changes: 13 additions & 0 deletions src/logger/LogConext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ export type LoggerSMS = LoggerBase & {
};
};

export type LoggerEmail = LoggerBase & {
email: {
accountName: string;
email: string;
verificationCode: string;
};
emailDetail?: {
envId: string;
requestId: string;
messageId: string;
};
};

export type LoggerQueue = LoggerBase & {
queue: {
name: string;
Expand Down
14 changes: 14 additions & 0 deletions src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
LoggerServer,
LoggerService,
LoggerSMS,
LoggerEmail,
} from "./LogConext";
import { LoggerPluginFile } from "./plugins/LoggerPluginFile";
import { LoggerPluginTerminal } from "./plugins/LoggerPluginTerminal";
Expand Down Expand Up @@ -104,6 +105,19 @@ export const createLoggerSMS = <R extends LoggerContext>(
);
};

export const createLoggerEmail = <R extends LoggerContext>(
context: Partial<LoggerEmail & R>,
): Logger<LoggerEmail & R> => {
return new Logger<LoggerEmail & R>(
"email",
{
...context,
...baseContext,
},
loggerPlugins as LoggerAbstractPlugin<LoggerEmail & R>[],
);
};

export const createLoggerRTCScreenshot = <R extends LoggerContext>(
context: Partial<LoggerRTCScreenshot & R>,
): Logger<LoggerRTCScreenshot & R> => {
Expand Down
2 changes: 2 additions & 0 deletions src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { OAuthInfosModel } from "./oauth/oauth-infos";
import { OAuthSecretsModel } from "./oauth/oauth-secrets";
import { OAuthUsersModel } from "./oauth/oauth-users";
import { UserSensitiveModel } from "./user/Sensitive";
import { UserEmailModel } from "./user/Email";

export type Model =
| UserModel
Expand All @@ -27,6 +28,7 @@ export type Model =
| UserAgoraModel
| UserGoogleModel
| UserPhoneModel
| UserEmailModel
| UserSensitiveModel
| RoomModel
| RoomUserModel
Expand Down
Loading