core: fix config hande

This commit is contained in:
undefined committed 2021-04-18 20:32:48 +08:00
1 parent f4c3ca20a2
commit a7dc00361c
4 files changed
+14 -3

No files matched your search

+11
View File
@@ -1,6 +1,7 @@
import type { Readable } from 'stream';
import { ObjectID, FilterQuery } from 'mongodb';
import { Dictionary, escapeRegExp, pick } from 'lodash';
import { streamToBuffer } from '@hydrooj/utils/lib/utils';
import { STATUS } from './builtin';
import * as document from './document';
import { buildProjection } from '../utils';
@@ -248,6 +249,16 @@ export class ProblemModel {
}
}
bus.on('problem/addTestdata', async (domainId, docId, name) => {
if (!['config.yaml', 'config.yml', 'Config.yaml', 'Config.yml'].includes(name)) return;
const buf = await storage.get(`problem/${domainId}/${docId}/testdata/${name}`);
await ProblemModel.edit(domainId, docId, { config: (await streamToBuffer(buf)).toString() });
});
bus.on('problem/delTestdata', async (domainId, docId, names) => {
if (!names.includes('config.yaml')) return;
await ProblemModel.edit(domainId, docId, { config: '' });
});
ProblemModel.extend((docId, pid) => ({
_id: new ObjectID(),
domainId: 'system',