mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: fix testdata zip upload
This commit is contained in:
1 parent
777d648f63
commit
b833efc8c9
4 files changed
+16
-2
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.20.46",
|
"version": "2.20.47",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -384,6 +384,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
|||||||
const zip = new AdmZip(this.request.files.file.path);
|
const zip = new AdmZip(this.request.files.file.path);
|
||||||
const entries = zip.getEntries();
|
const entries = zip.getEntries();
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
|
if (!entry.name) continue;
|
||||||
if (type === 'testdata') {
|
if (type === 'testdata') {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
await problem.addTestdata(domainId, this.pdoc.docId, entry.name, entry.getData());
|
await problem.addTestdata(domainId, this.pdoc.docId, entry.name, entry.getData());
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { buildProjection } from '../utils';
|
|||||||
import type { ProblemStatusDoc, Pdict, Document } from '../interface';
|
import type { ProblemStatusDoc, Pdict, Document } from '../interface';
|
||||||
import { Content } from '../loader';
|
import { Content } from '../loader';
|
||||||
import { ArrayKeys, NumberKeys, Projection } from '../typeutils';
|
import { ArrayKeys, NumberKeys, Projection } from '../typeutils';
|
||||||
import { ProblemNotFoundError } from '../error';
|
import { ProblemNotFoundError, ValidationError } from '../error';
|
||||||
import storage from '../service/storage';
|
import storage from '../service/storage';
|
||||||
import * as bus from '../service/bus';
|
import * as bus from '../service/bus';
|
||||||
|
|
||||||
@@ -134,11 +134,13 @@ export function del(domainId: string, docId: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function addTestdata(domainId: string, pid: number, name: string, f: Readable | Buffer | string) {
|
export async function addTestdata(domainId: string, pid: number, name: string, f: Readable | Buffer | string) {
|
||||||
|
if (!name) throw new ValidationError('name');
|
||||||
const [[, fileinfo]] = await Promise.all([
|
const [[, fileinfo]] = await Promise.all([
|
||||||
document.getSub(domainId, document.TYPE_PROBLEM, pid, 'data', name),
|
document.getSub(domainId, document.TYPE_PROBLEM, pid, 'data', name),
|
||||||
storage.put(`problem/${domainId}/${pid}/testdata/${name}`, f),
|
storage.put(`problem/${domainId}/${pid}/testdata/${name}`, f),
|
||||||
]);
|
]);
|
||||||
const meta = await storage.getMeta(`problem/${domainId}/${pid}/testdata/${name}`);
|
const meta = await storage.getMeta(`problem/${domainId}/${pid}/testdata/${name}`);
|
||||||
|
if (!meta) throw new Error('Upload failed');
|
||||||
const payload = { name, ...pick(meta, ['size', 'lastModified', 'etag']) };
|
const payload = { name, ...pick(meta, ['size', 'lastModified', 'etag']) };
|
||||||
if (!fileinfo) await push(domainId, pid, 'data', { _id: name, ...payload });
|
if (!fileinfo) await push(domainId, pid, 'data', { _id: name, ...payload });
|
||||||
else await document.setSub(domainId, document.TYPE_PROBLEM, pid, 'data', name, payload);
|
else await document.setSub(domainId, document.TYPE_PROBLEM, pid, 'data', name, payload);
|
||||||
|
|||||||
@@ -232,6 +232,17 @@ const scripts: UpgradeScript[] = [
|
|||||||
await db.collection('domain.user').deleteMany({ uid: null });
|
await db.collection('domain.user').deleteMany({ uid: null });
|
||||||
await db.collection('domain.user').deleteMany({ uid: 0 });
|
await db.collection('domain.user').deleteMany({ uid: 0 });
|
||||||
},
|
},
|
||||||
|
async function _15_16() {
|
||||||
|
const _FRESH_INSTALL_IGNORE = 1;
|
||||||
|
await iterateAllProblem(['data', 'additional_file'], async (pdoc) => {
|
||||||
|
const $set: any = {};
|
||||||
|
const td = pdoc.data.filter((f) => f.name);
|
||||||
|
if (JSON.stringify(td) !== JSON.stringify(pdoc.data)) $set.data = td;
|
||||||
|
const af = pdoc.additional_file.filter((f) => f.name);
|
||||||
|
if (JSON.stringify(af) !== JSON.stringify(pdoc.additional_file)) $set.additional_file = af;
|
||||||
|
if (Object.keys($set).length) await problem.edit(pdoc.domainId, pdoc.docId, $set);
|
||||||
|
});
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export = scripts;
|
export = scripts;
|
||||||
Reference in new issue
Block a user