gateway schema
This commit is contained in:
@@ -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<ILoginToken>({
|
||||||
|
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<ILoginToken>('LoginToken', LoginToken);
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { Schema, model } from "mongoose";
|
||||||
|
|
||||||
|
export interface IServerConfig {
|
||||||
|
allowLogin: boolean;
|
||||||
|
allowOAuthLogin: boolean;
|
||||||
|
allowRegister: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ServerConfig = new Schema<IServerConfig>({
|
||||||
|
allowLogin: { type: Boolean, required: true },
|
||||||
|
allowOAuthLogin: { type: Boolean, required: true },
|
||||||
|
allowRegister: { type: Boolean, required: true },
|
||||||
|
}, {
|
||||||
|
autoIndex: false,
|
||||||
|
capped: {
|
||||||
|
max: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
;
|
||||||
|
|
||||||
|
//단일 document로 관리
|
||||||
|
export default model<IServerConfig>('ServerConfig', ServerConfig);
|
||||||
@@ -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<IServerVersion>({
|
||||||
|
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<IServerVersion>('ServerVersion', ServerVersion);
|
||||||
@@ -1,9 +1,21 @@
|
|||||||
import { Schema, model } from 'mongoose';
|
import { Schema, model } from 'mongoose';
|
||||||
|
|
||||||
export type UserIDType = number;
|
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 {
|
interface IUser {
|
||||||
_id: UserIDType;
|
_id: UserIDType;
|
||||||
@@ -22,7 +34,8 @@ interface IUser {
|
|||||||
allowThirdPartyUse: boolean;
|
allowThirdPartyUse: boolean;
|
||||||
|
|
||||||
userName: string;
|
userName: string;
|
||||||
allowServerAction?: Map<string, number>;
|
allowServerAction?: Map<string, ServerActionType[]>;
|
||||||
|
allowGatewayAction?: ServerActionType[];
|
||||||
penalty?: Map<string, Date>;
|
penalty?: Map<string, Date>;
|
||||||
|
|
||||||
picture?: string;
|
picture?: string;
|
||||||
@@ -49,7 +62,17 @@ export const User = new Schema<IUser>({
|
|||||||
allowThirdPartyUse: { type: Boolean, required: true },
|
allowThirdPartyUse: { type: Boolean, required: true },
|
||||||
|
|
||||||
userName: { type: String, 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 },
|
penalty: { type: Map, required: false, of: Date },
|
||||||
|
|
||||||
picture: { type: String, required: false },
|
picture: { type: String, required: false },
|
||||||
@@ -57,11 +80,11 @@ export const User = new Schema<IUser>({
|
|||||||
|
|
||||||
regDate: { type: Date, required: true },
|
regDate: { type: Date, required: true },
|
||||||
deleteAfter: { type: Date, required: false },
|
deleteAfter: { type: Date, required: false },
|
||||||
})
|
}, { autoIndex: false })
|
||||||
.index({ id: 1 }, { unique: true })
|
.index({ id: 1 }, { unique: true })
|
||||||
.index({ email: 1 }, { unique: true })
|
.index({ email: 1 }, { unique: true })
|
||||||
.index({ oauthID: 1 }, { unique: true, sparse: true })
|
.index({ oauthID: 1 }, { unique: true, sparse: true })
|
||||||
.index({ deleteAfter: 1 })
|
.index({ deleteAfter: 1 }) // 자동 삭제 아님!
|
||||||
;
|
;
|
||||||
|
|
||||||
export default model<IUser>('User', User);
|
export default model<IUser>('User', User);
|
||||||
@@ -22,9 +22,9 @@ export const UserLog = new Schema<IUserLog>({
|
|||||||
logDate: { type: Date, required: true },
|
logDate: { type: Date, required: true },
|
||||||
logType: { type: String, required: true, enum: LogTypeList },
|
logType: { type: String, required: true, enum: LogTypeList },
|
||||||
action: { type: Object, required: true },
|
action: { type: Object, required: true },
|
||||||
})
|
}, { autoIndex: false })
|
||||||
.index({ userID: 1, logDate: 1 })
|
.index({ userID: 1, logDate: 1 })
|
||||||
.index({ logDate: 1 })
|
.index({ logDate: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 365 * 3 })
|
||||||
;
|
;
|
||||||
|
|
||||||
export default model<IUserLog>('UserLog', UserLog);
|
export default model<IUserLog>('UserLog', UserLog);
|
||||||
Reference in New Issue
Block a user