mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
import-qduoj: fix
This commit is contained in:
1 parent
991ffa6c86
commit
84d7e1b95d
6 files changed
+18
-13
No files matched your search
+2
-2
@@ -21,12 +21,12 @@
|
||||
"@shelf/jest-mongodb": "^1.2.3",
|
||||
"@types/cross-spawn": "^6.0.2",
|
||||
"@types/jest": "^26.0.20",
|
||||
"@types/node": "^14.14.20",
|
||||
"@types/node": "^14.14.21",
|
||||
"@types/semver": "^7.3.4",
|
||||
"@typescript-eslint/eslint-plugin": "^3.9.1",
|
||||
"@typescript-eslint/parser": "^3.9.1",
|
||||
"cross-spawn": "^7.0.3",
|
||||
"eslint": "^7.17.0",
|
||||
"eslint": "^7.18.0",
|
||||
"eslint-config-airbnb-base": "^14.2.1",
|
||||
"eslint-import-resolver-typescript": "^2.3.0",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"lodash": "^4.17.20",
|
||||
"p-queue": "^6.6.1",
|
||||
"shell-quote": "^1.7.2",
|
||||
"systeminformation": "^4.34.5",
|
||||
"systeminformation": "^4.34.7",
|
||||
"yargs": "^16.2.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.15.21",
|
||||
"version": "2.15.22",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
@@ -32,8 +32,8 @@
|
||||
"serialize-javascript": "^5.0.1",
|
||||
"sockjs": "^0.3.20",
|
||||
"superagent": "^6.1.0",
|
||||
"systeminformation": "^4.34.5",
|
||||
"terminal-kit": "^1.44.3",
|
||||
"systeminformation": "^4.34.7",
|
||||
"terminal-kit": "^1.45.4",
|
||||
"yargs": "^16.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -45,7 +45,7 @@
|
||||
"@types/koa-static-cache": "^5.1.0",
|
||||
"@types/lodash": "^4.14.167",
|
||||
"@types/lru-cache": "^5.1.0",
|
||||
"@types/minio": "^7.0.6",
|
||||
"@types/minio": "^7.0.7",
|
||||
"@types/mongodb": "^3.5.33",
|
||||
"@types/nodemailer": "^6.4.0",
|
||||
"@types/serialize-javascript": "^5.0.0",
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Readable } from 'stream';
|
||||
import assert from 'assert';
|
||||
import { URL } from 'url';
|
||||
import { Client, BucketItem, ItemBucketMetadata } from 'minio';
|
||||
import { createReadStream } from 'fs-extra';
|
||||
import { Logger } from '../logger';
|
||||
import { streamToBuffer } from '../utils';
|
||||
|
||||
@@ -103,7 +104,7 @@ class StorageService {
|
||||
}
|
||||
|
||||
async put(target: string, file: string | Buffer | Readable, meta: ItemBucketMetadata = {}) {
|
||||
if (typeof file === 'string') return await this.client.fPutObject(this.opts.bucket, target, file, meta);
|
||||
if (typeof file === 'string') file = createReadStream(file);
|
||||
return await this.client.putObject(this.opts.bucket, target, file, meta);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import AdmZip from 'adm-zip';
|
||||
import yaml from 'js-yaml';
|
||||
import { ContentNode, LocalProblemConfig } from 'hydrooj';
|
||||
import { Route, Handler } from 'hydrooj/dist/service/server';
|
||||
import * as storage from 'hydrooj/dist/service/storage';
|
||||
import storage from 'hydrooj/dist/service/storage';
|
||||
import { BadRequestError, ValidationError } from 'hydrooj/dist/error';
|
||||
import { ProblemAdd } from 'hydrooj/dist/lib/ui';
|
||||
import * as problem from 'hydrooj/dist/model/problem';
|
||||
@@ -19,7 +19,7 @@ class ImportQduojHandler extends Handler {
|
||||
const zip = new AdmZip(zipfile);
|
||||
const tmp = path.resolve(os.tmpdir(), 'hydro', 'import-qduoj', String.random(32));
|
||||
await new Promise((resolve, reject) => {
|
||||
zip.extractAllToAsync(tmp, true, (err) => (err ? resolve(null) : reject(err)));
|
||||
zip.extractAllToAsync(tmp, true, (err) => (err ? reject(err) : resolve(null)));
|
||||
});
|
||||
try {
|
||||
const folders = await fs.readdir(tmp);
|
||||
@@ -73,6 +73,8 @@ class ImportQduojHandler extends Handler {
|
||||
text: pdoc.source.value,
|
||||
});
|
||||
}
|
||||
const n = await problem.get(domainId, pdoc.display_id);
|
||||
if (n) pdoc.display_id = null;
|
||||
const pid = await problem.add(domainId, pdoc.display_id, pdoc.title, content, this.user._id, pdoc.tags);
|
||||
const config: LocalProblemConfig = {
|
||||
time: `${pdoc.time_limit}ms`,
|
||||
@@ -82,11 +84,11 @@ class ImportQduojHandler extends Handler {
|
||||
for (const tc of pdoc.test_case_score) {
|
||||
await storage.put(
|
||||
`problem/${domainId}/${pid}/testdata/${tc.input_name}`,
|
||||
path.join(tmp, 'testcase', tc.input_name),
|
||||
path.join(tmp, folder, 'testcase', tc.input_name),
|
||||
);
|
||||
await storage.put(
|
||||
`problem/${domainId}/${pid}/testdata/${tc.output_name}`,
|
||||
path.join(tmp, 'testcase', tc.output_name),
|
||||
path.join(tmp, folder, 'testcase', tc.output_name),
|
||||
);
|
||||
config.subtasks.push({
|
||||
score: tc.score,
|
||||
@@ -103,6 +105,8 @@ class ImportQduojHandler extends Handler {
|
||||
const data = await storage.list(`problem/${domainId}/${pid}/testdata/`, true);
|
||||
await problem.edit(domainId, pid, { html: true, data });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
await fs.remove(tmp);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/import-qduoj",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.2",
|
||||
"description": "Import QDUOJ problem export",
|
||||
"main": "package.json",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
Reference in new issue
Block a user