diff --git a/server/schema/gateway/LoginToken.ts b/server/schema/gateway/LoginToken.ts new file mode 100644 index 0000000..b3bb8be --- /dev/null +++ b/server/schema/gateway/LoginToken.ts @@ -0,0 +1,23 @@ +import { type UserIDType } from "./User.js"; +import { Schema, model } from "mongoose"; + +export interface ILoginToken { + userID: UserIDType; + token: string; + ip: string; + regDate: Date; + validUntil: Date; +} + +export const LoginToken = new Schema({ + userID: { type: Number, required: true }, + token: { type: String, required: true }, + ip: { type: String, required: true }, + regDate: { type: Date, required: true }, + validUntil: { type: Date, required: true }, +}, { autoIndex: false }) + .index({ userID: 1, token: 1 }) + .index({ validUntil: 1 }, { expireAfterSeconds: 1 }) + ; + +export default model('LoginToken', LoginToken); \ No newline at end of file diff --git a/server/schema/gateway/ServerConfig.ts b/server/schema/gateway/ServerConfig.ts new file mode 100644 index 0000000..3db36d7 --- /dev/null +++ b/server/schema/gateway/ServerConfig.ts @@ -0,0 +1,22 @@ +import { Schema, model } from "mongoose"; + +export interface IServerConfig { + allowLogin: boolean; + allowOAuthLogin: boolean; + allowRegister: boolean; +}; + +export const ServerConfig = new Schema({ + allowLogin: { type: Boolean, required: true }, + allowOAuthLogin: { type: Boolean, required: true }, + allowRegister: { type: Boolean, required: true }, +}, { + autoIndex: false, + capped: { + max: 1, + } +}) +; + +//단일 document로 관리 +export default model('ServerConfig', ServerConfig); \ No newline at end of file diff --git a/server/schema/gateway/ServerVersion.ts b/server/schema/gateway/ServerVersion.ts new file mode 100644 index 0000000..739fbd8 --- /dev/null +++ b/server/schema/gateway/ServerVersion.ts @@ -0,0 +1,19 @@ +import { Schema, model } from "mongoose"; + +export interface IServerVersion { + serverKey: string; + branch: string; + version: string; + updateDate: Date; +} + +export const ServerVersion = new Schema({ + serverKey: { type: String, required: true }, + branch: { type: String, required: true }, + version: { type: String, required: true }, + updateDate: { type: Date, required: true }, +}, { autoIndex: false }) + .index({ serverKey: 1 }, { unique: true }) + ; + +export default model('ServerVersion', ServerVersion); \ No newline at end of file diff --git a/server/schema/gateway/User.ts b/server/schema/gateway/User.ts index b40de7b..45ac50a 100644 --- a/server/schema/gateway/User.ts +++ b/server/schema/gateway/User.ts @@ -1,9 +1,21 @@ import { Schema, model } from 'mongoose'; export type UserIDType = number; -export type validOAuthType = 'KAKAO' | 'NONE'; -const validOAuthTypeList: validOAuthType[] = ['KAKAO', 'NONE']; +const validOAuthTypeList = ['KAKAO', 'NONE'] as const; +export type validOAuthType = typeof validOAuthTypeList[number]; + +const validServerActionTypeList = [ + 'Update', 'UpdateByGitPath', 'ShowErrorLog', + 'CloseServer', 'OpenServer', 'StopAndResumeServer', 'OpenVote', +] as const; +export type ServerActionType = typeof validServerActionTypeList[number]; + +const validGatewayActionTypeList = [ + 'Update', 'UpdateByGitPath', 'ShowErrorLog', 'ResetUserPassword', 'ChangeGatewayState', 'DeleteUser', +] as const; + +export type GatewayActionType = typeof validGatewayActionTypeList[number]; interface IUser { _id: UserIDType; @@ -22,7 +34,8 @@ interface IUser { allowThirdPartyUse: boolean; userName: string; - allowServerAction?: Map; + allowServerAction?: Map; + allowGatewayAction?: ServerActionType[]; penalty?: Map; picture?: string; @@ -49,7 +62,17 @@ export const User = new Schema({ allowThirdPartyUse: { type: Boolean, required: true }, userName: { type: String, required: true }, - allowServerAction: { type: Map, required: false, of: Number }, + allowServerAction: { + type: Map, required: false, of: { + type: Array, + of: { type: String, enum: validServerActionTypeList } + } + }, + allowGatewayAction: { + type: Array, required: false, of: { + type: String, enum: validGatewayActionTypeList + } + }, penalty: { type: Map, required: false, of: Date }, picture: { type: String, required: false }, @@ -57,11 +80,11 @@ export const User = new Schema({ regDate: { type: Date, required: true }, deleteAfter: { type: Date, required: false }, -}) +}, { autoIndex: false }) .index({ id: 1 }, { unique: true }) .index({ email: 1 }, { unique: true }) .index({ oauthID: 1 }, { unique: true, sparse: true }) - .index({ deleteAfter: 1 }) + .index({ deleteAfter: 1 }) // 자동 삭제 아님! ; export default model('User', User); \ No newline at end of file diff --git a/server/schema/gateway/UserLog.ts b/server/schema/gateway/UserLog.ts index bbcb3ed..2b019e6 100644 --- a/server/schema/gateway/UserLog.ts +++ b/server/schema/gateway/UserLog.ts @@ -22,9 +22,9 @@ export const UserLog = new Schema({ logDate: { type: Date, required: true }, logType: { type: String, required: true, enum: LogTypeList }, action: { type: Object, required: true }, -}) +}, { autoIndex: false }) .index({ userID: 1, logDate: 1 }) - .index({ logDate: 1 }) + .index({ logDate: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 365 * 3 }) ; export default model('UserLog', UserLog); \ No newline at end of file