mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: update buildContent
This commit is contained in:
1 parent
7bd7325db6
commit
308605f884
3 files changed
+46
-13
No files matched your search
@@ -11,7 +11,7 @@ import solution from 'hydrooj/dist/model/solution';
|
|||||||
import problem from 'hydrooj/dist/model/problem';
|
import problem from 'hydrooj/dist/model/problem';
|
||||||
import { PERM } from 'hydrooj/dist/model/builtin';
|
import { PERM } from 'hydrooj/dist/model/builtin';
|
||||||
import { FileTooLargeError, ValidationError } from 'hydrooj/dist/error';
|
import { FileTooLargeError, ValidationError } from 'hydrooj/dist/error';
|
||||||
import type { ProblemConfigFile } from 'hydrooj';
|
import type { ContentNode, ProblemConfigFile } from 'hydrooj';
|
||||||
|
|
||||||
class FpsProblemImportHandler extends Handler {
|
class FpsProblemImportHandler extends Handler {
|
||||||
async get() {
|
async get() {
|
||||||
@@ -20,22 +20,53 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
|
|
||||||
async run(domainId: string, result: any) {
|
async run(domainId: string, result: any) {
|
||||||
for (const p of result.fps.item) {
|
for (const p of result.fps.item) {
|
||||||
const content = buildContent({
|
const content: ContentNode[] = [];
|
||||||
description: p.description,
|
if (p.description?.[0]) {
|
||||||
input: p.input,
|
content.push({
|
||||||
output: p.output,
|
type: 'Text',
|
||||||
samples: p.sample_input
|
subType: 'html',
|
||||||
? p.sample_input.map((si: string, i: number) => [si, p.sample_output[i]])
|
sectionTitle: this.translate('Description'),
|
||||||
: [],
|
text: p.description[0],
|
||||||
hint: p.hint,
|
});
|
||||||
}, 'html', this.translate.bind(this));
|
}
|
||||||
|
if (p.input?.[0]) {
|
||||||
|
content.push({
|
||||||
|
type: 'Text',
|
||||||
|
subType: 'html',
|
||||||
|
sectionTitle: this.translate('Input Format'),
|
||||||
|
text: p.input[0],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (p.output?.[0]) {
|
||||||
|
content.push({
|
||||||
|
type: 'Text',
|
||||||
|
subType: 'html',
|
||||||
|
sectionTitle: this.translate('Output Format'),
|
||||||
|
text: p.output[0],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (p.sample_input?.length) {
|
||||||
|
content.push(...p.sample_input.map((input, i) => ({
|
||||||
|
type: 'Sample',
|
||||||
|
sectionTitle: this.translate('Sample'),
|
||||||
|
payload: [input, p.sample_output[i]],
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
if (p.hint?.[0]) {
|
||||||
|
content.push({
|
||||||
|
type: 'Text',
|
||||||
|
subType: 'html',
|
||||||
|
sectionTitle: this.translate('Hint'),
|
||||||
|
text: p.hint[0],
|
||||||
|
});
|
||||||
|
}
|
||||||
const config: ProblemConfigFile = {
|
const config: ProblemConfigFile = {
|
||||||
time: p.time_limit[0]._ + p.time_limit[0].$.unit,
|
time: p.time_limit[0]._ + p.time_limit[0].$.unit,
|
||||||
memory: p.memory_limit[0]._ + p.memory_limit[0].$.unit,
|
memory: p.memory_limit[0]._ + p.memory_limit[0].$.unit,
|
||||||
};
|
};
|
||||||
const title = decodeHTML(p.title.join(' '));
|
const title = decodeHTML(p.title.join(' '));
|
||||||
const tags = filter(p.source, (i: string) => i.trim());
|
const tags = filter(p.source, (i: string) => i.trim());
|
||||||
const pid = await problem.add(domainId, null, title, content, this.user._id, tags);
|
const pid = await problem.add(domainId, null, title, buildContent(content, 'html'), this.user._id, tags);
|
||||||
await problem.addTestdata(domainId, pid, 'config.yaml', Buffer.from(`time: ${config.time}\nmemory: ${config.memory}`));
|
await problem.addTestdata(domainId, pid, 'config.yaml', Buffer.from(`time: ${config.time}\nmemory: ${config.memory}`));
|
||||||
if (p.test_output) {
|
if (p.test_output) {
|
||||||
for (let i = 0; i < p.test_input.length; i++) {
|
for (let i = 0; i < p.test_input.length; i++) {
|
||||||
@@ -75,6 +106,7 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
const result = await xml2js.parseStringPromise(content);
|
const result = await xml2js.parseStringPromise(content);
|
||||||
tasks.push(result);
|
tasks.push(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
const zip = new AdmZip(this.request.files.file.path);
|
const zip = new AdmZip(this.request.files.file.path);
|
||||||
for (const entry of zip.getEntries()) {
|
for (const entry of zip.getEntries()) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.28.35",
|
"version": "2.28.36",
|
||||||
"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",
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ export function buildContent(source: ProblemSource | ContentNode[], type: 'markd
|
|||||||
? source.map((node) => [
|
? source.map((node) => [
|
||||||
node.type !== 'Plain' ? `<h2>${node.sectionTitle}</h2>` : '',
|
node.type !== 'Plain' ? `<h2>${node.sectionTitle}</h2>` : '',
|
||||||
node.type === 'Sample'
|
node.type === 'Sample'
|
||||||
? `<h2>${_('Sample Input')}<h2><pre>${node.payload[0]}</pre><h2>${_('Sample Output')}</h2><pre>${node.payload[1]}</pre>`
|
? `<pre><code class="language-input${++cnt}">${node.payload[0]}</code></pre>`
|
||||||
|
+ `<pre><code class="language-output${cnt}">${node.payload[1]}</code></pre>`
|
||||||
: '',
|
: '',
|
||||||
node.text,
|
node.text,
|
||||||
].join('\n')).join('\n')
|
].join('\n')).join('\n')
|
||||||
|
|||||||
Reference in new issue
Block a user