core: add domain delete

This commit is contained in:
undefined committed 2021-05-25 23:16:27 +08:00
1 parent 71f86cf79b
commit ef73b97089
8 files changed
+23 -2

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.27.2",
"version": "2.27.3",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+5
View File
@@ -428,6 +428,11 @@ async function ensureIndexes() {
}
bus.once('app/started', ensureIndexes);
bus.on('domain/delete', (domainId) => Promise.all([
coll.deleteMany({ domainId }),
collStatus.deleteMany({ domainId }),
]));
global.Hydro.model.document = {
coll,
collStatus,
+7
View File
@@ -249,6 +249,13 @@ class DomainModel {
}).limit(limit).toArray();
return ddocs;
}
@ArgMethod
static async del(domainId: string) {
await coll.deleteOne({ _id: domainId });
await collUser.deleteMany({ domainId });
await bus.parallel('domain/delete', domainId);
}
}
export default DomainModel;
+2
View File
@@ -208,5 +208,7 @@ class RecordModel {
}
bus.on('problem/delete', (domainId, docId) => RecordModel.coll.deleteMany({ domainId, pid: docId }));
bus.on('domain/delete', (domainId) => RecordModel.coll.deleteMany({ domainId }));
export default RecordModel;
global.Hydro.model.record = RecordModel;
+4
View File
@@ -97,6 +97,10 @@ bus.once('app/started', async () => {
});
}
});
bus.on('domain/delete', async (domainId) => {
const files = await StorageModel.list(`problem/${domainId}`);
await StorageModel.del(files.map((i) => i.path));
});
global.Hydro.model.storage = StorageModel;
export default StorageModel;
+2
View File
@@ -127,5 +127,7 @@ class TaskModel {
static Worker = Worker;
}
bus.on('domain/delete', (domainId) => coll.deleteMany({ domainId }));
export default TaskModel;
global.Hydro.model.task = TaskModel;
+1
View File
@@ -55,6 +55,7 @@ export interface EventMap extends Record<string, any> {
'domain/get': (ddoc: DomainDoc) => VoidReturn
'domain/before-update': (domainId: string, $set: Partial<DomainDoc>) => VoidReturn
'domain/update': (domainId: string, $set: Partial<DomainDoc>, ddoc: DomainDoc) => VoidReturn
'domain/delete': (domainId: string) => VoidReturn
'document/add': (doc: any) => VoidReturn
'document/set': <T extends keyof DocType>(
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.9.1",
"version": "4.9.2",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",