mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: add file edit hook
This commit is contained in:
1 parent
32df811bfa
commit
76615e0f5d
5 files changed
+18
-6
No files matched your search
@@ -142,12 +142,14 @@ export class ProblemModel {
|
||||
const payload = { name, ...pick(meta, ['size', 'lastModified', 'etag']) };
|
||||
if (!fileinfo) await ProblemModel.push(domainId, pid, 'data', { _id: name, ...payload });
|
||||
else await document.setSub(domainId, document.TYPE_PROBLEM, pid, 'data', name, payload);
|
||||
await bus.emit('problem/addTestdata', domainId, pid, name, payload);
|
||||
}
|
||||
|
||||
static async delTestdata(domainId: string, pid: number, name: string | string[]) {
|
||||
const names = (name instanceof Array) ? name : [name];
|
||||
await storage.del(names.map((t) => `problem/${domainId}/${pid}/testdata/${t}`));
|
||||
await ProblemModel.pull(domainId, pid, 'data', names);
|
||||
await bus.emit('problem/delTestdata', domainId, pid, name);
|
||||
}
|
||||
|
||||
static async addAdditionalFile(domainId: string, pid: number, name: string, f: Readable | Buffer | string) {
|
||||
@@ -159,12 +161,14 @@ export class ProblemModel {
|
||||
const payload = { name, ...pick(meta, ['size', 'lastModified', 'etag']) };
|
||||
if (!fileinfo) await ProblemModel.push(domainId, pid, 'additional_file', { _id: name, ...payload });
|
||||
else await document.setSub(domainId, document.TYPE_PROBLEM, pid, 'additional_file', name, payload);
|
||||
await bus.emit('problem/addAdditionalFile', domainId, pid, name, payload);
|
||||
}
|
||||
|
||||
static async delAdditionalFile(domainId: string, pid: number, name: string | string[]) {
|
||||
const names = (name instanceof Array) ? name : [name];
|
||||
await storage.del(names.map((t) => `problem/${domainId}/${pid}/additional_file/${t}`));
|
||||
await ProblemModel.pull(domainId, pid, 'additional_file', names);
|
||||
await bus.emit('problem/delAdditionalFile', domainId, pid, name);
|
||||
}
|
||||
|
||||
static async random(domainId: string, query: FilterQuery<Pdoc>): Promise<string | null> {
|
||||
|
||||
Reference in new issue
Block a user