diff --git a/build/build.js b/build/build.js index b32ec49fd..6a5f44670 100644 --- a/build/build.js +++ b/build/build.js @@ -52,9 +52,9 @@ const configFlat = { const packages = fs.readdirSync(path.resolve(process.cwd(), 'packages')); console.log(packages); for (const package of packages) { - if (package !== 'hydrooj') config.references.push({ path: `packages/${package}` }); const files = fs.readdirSync(path.resolve(process.cwd(), 'packages', package)); if (!files.includes('src') && !files.map(n => n.split('.')[1]).includes('ts')) continue; + if (package !== 'hydrooj') config.references.push({ path: `packages/${package}` }); fs.writeFileSync( path.resolve(process.cwd(), 'packages', package, 'tsconfig.json'), files.includes('src') ? JSON.stringify(configSrc) : JSON.stringify(configFlat), diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 55f4695a6..57e860d2c 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.13.23", + "version": "2.13.24", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/entry/common.ts b/packages/hydrooj/src/entry/common.ts index f2943a627..9b08ffe79 100644 --- a/packages/hydrooj/src/entry/common.ts +++ b/packages/hydrooj/src/entry/common.ts @@ -18,7 +18,7 @@ export const builtinModel = [ 'builtin', 'document', 'domain', 'blacklist', 'opcount', 'setting', 'token', 'user', 'problem', 'record', 'contest', 'message', 'solution', 'training', 'file', - 'discussion', 'system', + 'discussion', 'system', 'oplog', ]; export const builtinHandler = [ diff --git a/packages/hydrooj/src/handler/discussion.ts b/packages/hydrooj/src/handler/discussion.ts index fd5f784c5..aed356bc0 100644 --- a/packages/hydrooj/src/handler/discussion.ts +++ b/packages/hydrooj/src/handler/discussion.ts @@ -6,6 +6,7 @@ import { } from '../interface'; import paginate from '../lib/paginate'; import * as user from '../model/user'; +import * as oplog from '../model/oplog'; import * as message from '../model/message'; import * as discussion from '../model/discussion'; import * as document from '../model/document'; @@ -257,6 +258,7 @@ class DiscussionDetailHandler extends DiscussionHandler { } else this.checkPerm(PERM.PERM_DELETE_DISCUSSION_SELF); } await discussion.delReply(domainId, drid); + await oplog.add({ ...this.drdoc, operator: this.user._id, type: 'drdoc' }); this.back(); } @@ -275,6 +277,7 @@ class DiscussionDetailHandler extends DiscussionHandler { async postDeleteTailReply(domainId: string, drid: ObjectID, drrid: ObjectID) { if (this.drrdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_DELETE_DISCUSSION_REPLY); await discussion.delTailReply(domainId, drid, drrid); + await oplog.add({ ...this.drrdoc, operator: this.user._id, type: 'drrdoc' }); this.back(); } @@ -348,6 +351,7 @@ class DiscussionEditHandler extends DiscussionHandler { if (this.ddoc.owner !== this.user._id) this.checkPerm(PERM.PERM_DELETE_DISCUSSION); else this.checkPerm(PERM.PERM_DELETE_DISCUSSION_SELF); await discussion.del(domainId, did); + await oplog.add({ ...this.ddoc, operator: this.user._id, type: 'ddoc' }); this.response.body = { type: this.ddoc.parentType, parent: this.ddoc.parentId }; this.response.redirect = this.url('discussion_node', { type: discussion.typeDisplay[this.ddoc.parentType], diff --git a/packages/hydrooj/src/interface.ts b/packages/hydrooj/src/interface.ts index a2f0cf319..e7ebad71c 100644 --- a/packages/hydrooj/src/interface.ts +++ b/packages/hydrooj/src/interface.ts @@ -374,7 +374,12 @@ export interface TokenDoc { [key: string]: any, } -export interface ContestStat extends Dictionary { +export interface OplogDoc extends Record { + _id: ObjectID, + type: string, +} + +export interface ContestStat extends Record { detail: any, } @@ -464,6 +469,7 @@ export interface Collections { 'oauth': any, 'system': System, 'task': Task, + 'oplog': OplogDoc, 'opcount': any, 'fs.chunks': any, 'fs.files': any, @@ -486,6 +492,7 @@ export interface Model { solution: typeof import('./model/solution'), system: typeof import('./model/system'), task: typeof import('./model/task'), + oplog: typeof import('./model/oplog'), token: typeof import('./model/token'), training: typeof import('./model/training'), user: typeof import('./model/user'), diff --git a/packages/hydrooj/src/model/oplog.ts b/packages/hydrooj/src/model/oplog.ts new file mode 100644 index 000000000..ce82a4a05 --- /dev/null +++ b/packages/hydrooj/src/model/oplog.ts @@ -0,0 +1,16 @@ +import { ObjectID } from 'mongodb'; +import { OplogDoc } from '../interface'; +import * as db from '../service/db'; + +export const coll = db.collection('oplog'); + +export async function add(data: Partial): Promise { + const res = await coll.insertOne(data); + return res.insertedId; +} + +export async function get(id: ObjectID): Promise { + return await coll.findOne({ _id: id }); +} + +global.Hydro.model.oplog = { coll, add, get };