mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: 添加buildContent方法
This commit is contained in:
1 parent
f81d7daa54
commit
19ebf5e9a8
5 files changed
+116
-92
No files matched your search
@@ -11,7 +11,7 @@ import { LocalProblemConfig } from 'hydrooj';
|
||||
import {
|
||||
Route, Handler, param, Types,
|
||||
} from 'hydrooj/dist/service/server';
|
||||
import { streamToBuffer } from 'hydrooj/dist/utils';
|
||||
import { buildContent, streamToBuffer } from 'hydrooj/dist/utils';
|
||||
import { ProblemAdd } from 'hydrooj/dist/lib/ui';
|
||||
import * as file from 'hydrooj/dist/model/file';
|
||||
import * as solution from 'hydrooj/dist/model/solution';
|
||||
@@ -60,57 +60,22 @@ class FpsProblemImportHandler extends Handler {
|
||||
const problem = global.Hydro.model.problem;
|
||||
for (const p of result.fps.item) {
|
||||
const testdata = new AdmZip();
|
||||
const content = [];
|
||||
if (p.description) {
|
||||
content.push(
|
||||
`<h2>${this.translate('Description')}</h2>`,
|
||||
...p.description,
|
||||
);
|
||||
}
|
||||
if (p.input) {
|
||||
content.push(
|
||||
`<h2>${this.translate('Input Format')}</h2>`,
|
||||
...p.input,
|
||||
);
|
||||
}
|
||||
if (p.output) {
|
||||
content.push(
|
||||
`<h2>${this.translate('Output Format')}</h2>`,
|
||||
...p.output,
|
||||
);
|
||||
}
|
||||
if (p.sample_input) {
|
||||
if (p.sample_input.length === 1) {
|
||||
content.push(
|
||||
`<h2>${this.translate('Sample Input')}</h2>`,
|
||||
`<pre><code>${p.sample_input[0]}</code></pre>`,
|
||||
`<h2>${this.translate('Sample Output')}</h2>`,
|
||||
`<pre><code>${p.sample_output[0]}</code></pre>`,
|
||||
);
|
||||
} else {
|
||||
for (let i = 0; i < p.sample_input.length; i++) {
|
||||
content.push(
|
||||
`<h2>${this.translate('Sample Input')}${i + 1}</h2>`,
|
||||
`<pre><code>${p.sample_input[i]}</code></pre>`,
|
||||
`<h2>${this.translate('Sample Output')}${i + 1}</h2>`,
|
||||
`<pre><code>${p.sample_output[i]}</code></pre>`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p.hint) {
|
||||
content.push(
|
||||
`<h2>${this.translate('Hint')}</h2>`,
|
||||
...p.hint,
|
||||
);
|
||||
}
|
||||
const content = buildContent({
|
||||
description: p.description,
|
||||
input: p.input,
|
||||
output: p.output,
|
||||
samples: p.sample_input
|
||||
? p.sample_input.map((si: string, i: number) => [si, p.sample_output[i]])
|
||||
: [],
|
||||
hint: p.hint,
|
||||
}, 'html', this.translate.bind(this));
|
||||
const config: LocalProblemConfig = {
|
||||
time: p.time_limit[0]._ + p.time_limit[0].$.unit,
|
||||
memory: p.memory_limit[0]._ + p.memory_limit[0].$.unit,
|
||||
};
|
||||
const title = decodeHTML(p.title.join(' '));
|
||||
const tags = filter(p.source, (i: string) => i.trim());
|
||||
const pid = await problem.add(domainId, null, title, content.join('\n'), this.user._id, tags, []);
|
||||
const pid = await problem.add(domainId, null, title, content, this.user._id, tags, []);
|
||||
testdata.addFile('config.yaml', Buffer.from(`time: ${config.time}\nmemory: ${config.memory}`));
|
||||
if (p.test_output) {
|
||||
for (let i = 0; i < p.test_input.length; i++) {
|
||||
|
||||
Reference in new issue
Block a user