mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: support ContentNode[] format
This commit is contained in:
1 parent
151cc79f36
commit
b0aa983e6f
12 files changed
+640
-130
No files matched your search
@@ -5,12 +5,12 @@ import fs from 'fs-extra';
|
||||
import AdmZip from 'adm-zip';
|
||||
import yaml from 'js-yaml';
|
||||
import { ObjectID } from 'mongodb';
|
||||
import { LocalProblemConfig } from 'hydrooj';
|
||||
import { ContentNode, LocalProblemConfig } from 'hydrooj';
|
||||
import {
|
||||
Route, Handler, param, Types,
|
||||
} from 'hydrooj/dist/service/server';
|
||||
import { BadRequestError } from 'hydrooj/dist/error';
|
||||
import { buildContent, streamToBuffer } from 'hydrooj/dist/utils';
|
||||
import { streamToBuffer } from 'hydrooj/dist/utils';
|
||||
import { ProblemAdd } from 'hydrooj/dist/lib/ui';
|
||||
import * as file from 'hydrooj/dist/model/file';
|
||||
import * as problem from 'hydrooj/dist/model/problem';
|
||||
@@ -31,14 +31,53 @@ class ImportQduojHandler extends Handler {
|
||||
for (const folder of folders) {
|
||||
const buf = await fs.readFile(path.join(tmp, folder, 'problem.json'));
|
||||
const pdoc = JSON.parse(buf.toString());
|
||||
const content = buildContent({
|
||||
description: pdoc.description?.value,
|
||||
input: pdoc.input_description?.value,
|
||||
output: pdoc.output_description?.value,
|
||||
samples: pdoc.samples.map((i) => [i.input, i.output]),
|
||||
hint: pdoc.hint?.value,
|
||||
source: pdoc.source?.value,
|
||||
}, 'html');
|
||||
const content: ContentNode[] = [];
|
||||
if (pdoc.description?.value) {
|
||||
content.push({
|
||||
type: 'Text',
|
||||
subType: 'html',
|
||||
sectionTitle: this.translate('Description'),
|
||||
text: pdoc.description.value,
|
||||
});
|
||||
}
|
||||
if (pdoc.input_description?.value) {
|
||||
content.push({
|
||||
type: 'Text',
|
||||
subType: 'html',
|
||||
sectionTitle: this.translate('Input Format'),
|
||||
text: pdoc.input_description.value,
|
||||
});
|
||||
}
|
||||
if (pdoc.output_description?.value) {
|
||||
content.push({
|
||||
type: 'Text',
|
||||
subType: 'html',
|
||||
sectionTitle: this.translate('Output Format'),
|
||||
text: pdoc.output_description.value,
|
||||
});
|
||||
}
|
||||
if (pdoc.samples?.length) {
|
||||
content.push(...pdoc.samples.map((sample) => ({
|
||||
type: 'Sample',
|
||||
payload: [sample.input, sample.output],
|
||||
})));
|
||||
}
|
||||
if (pdoc.hint?.value) {
|
||||
content.push({
|
||||
type: 'Text',
|
||||
subType: 'html',
|
||||
sectionTitle: this.translate('Hint'),
|
||||
text: pdoc.hint.value,
|
||||
});
|
||||
}
|
||||
if (pdoc.source?.value) {
|
||||
content.push({
|
||||
type: 'Text',
|
||||
subType: 'html',
|
||||
sectionTitle: this.translate('Source'),
|
||||
text: pdoc.source.value,
|
||||
});
|
||||
}
|
||||
const pid = await problem.add(domainId, pdoc.display_id, pdoc.title, content, this.user._id, pdoc.tags);
|
||||
const testdata = new AdmZip();
|
||||
const config: LocalProblemConfig = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/import-qduoj",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"description": "Import QDUOJ problem export",
|
||||
"main": "package.json",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
@@ -15,10 +15,10 @@
|
||||
"bson": "^4.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"hydrooj": "^2.13.0"
|
||||
"hydrooj": "^2.14.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"lint": "eslint . --ext ts --fix"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user