mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
fps-importer: 对标题进行html-decode
This commit is contained in:
1 parent
dbc5fff09f
commit
2c2ce194a0
2 files changed
+19
-2
No files matched your search
@@ -5,6 +5,8 @@ import fs from 'fs-extra';
|
|||||||
import AdmZip from 'adm-zip';
|
import AdmZip from 'adm-zip';
|
||||||
import xml2js from 'xml2js';
|
import xml2js from 'xml2js';
|
||||||
import { ObjectID } from 'bson';
|
import { ObjectID } from 'bson';
|
||||||
|
import { filter } from 'lodash';
|
||||||
|
import decodeHTML from 'decode-html';
|
||||||
import { LocalProblemConfig } from 'hydrooj';
|
import { LocalProblemConfig } from 'hydrooj';
|
||||||
import {
|
import {
|
||||||
Route, Handler, param, Types,
|
Route, Handler, param, Types,
|
||||||
@@ -14,11 +16,19 @@ import { ProblemAdd } from 'hydrooj/dist/lib/ui';
|
|||||||
import * as file from 'hydrooj/dist/model/file';
|
import * as file from 'hydrooj/dist/model/file';
|
||||||
import { PERM } from 'hydrooj/dist/model/builtin';
|
import { PERM } from 'hydrooj/dist/model/builtin';
|
||||||
|
|
||||||
|
const processing = {};
|
||||||
|
|
||||||
class FpsProblemImportHandler extends Handler {
|
class FpsProblemImportHandler extends Handler {
|
||||||
@param('ufid', Types.ObjectID, true)
|
@param('ufid', Types.ObjectID, true)
|
||||||
async get(domainId: string, ufid?: ObjectID) {
|
async get(domainId: string, ufid?: ObjectID) {
|
||||||
if (ufid) {
|
if (ufid) {
|
||||||
|
if (processing[ufid.toHexString()]) {
|
||||||
|
this.response.body = 'Processing';
|
||||||
|
return;
|
||||||
|
}
|
||||||
const stream = await file.get(ufid);
|
const stream = await file.get(ufid);
|
||||||
|
processing[ufid.toHexString()] = true;
|
||||||
|
try {
|
||||||
const buf = await streamToBuffer(stream);
|
const buf = await streamToBuffer(stream);
|
||||||
let input = buf.toString();
|
let input = buf.toString();
|
||||||
try {
|
try {
|
||||||
@@ -36,6 +46,10 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
await this.post({ domainId, input });
|
await this.post({ domainId, input });
|
||||||
await file.del(ufid);
|
await file.del(ufid);
|
||||||
|
} catch (e) {
|
||||||
|
processing[ufid.toHexString()] = false;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
} else this.response.template = 'problem_import_fps.html';
|
} else this.response.template = 'problem_import_fps.html';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +107,9 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
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 pid = await problem.add(domainId, null, p.title.join(' '), content.join('\n'), this.user._id, p.source, []);
|
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, []);
|
||||||
testdata.addFile('config.yaml', Buffer.from(`time: ${config.time}\nmemory: ${config.memory}`));
|
testdata.addFile('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++) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/fps-importer",
|
"name": "@hydrooj/fps-importer",
|
||||||
"version": "1.1.0",
|
"version": "1.1.1",
|
||||||
"description": "Import FPS problems",
|
"description": "Import FPS problems",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"adm-zip": "^0.4.16",
|
"adm-zip": "^0.4.16",
|
||||||
|
"decode-html": "^2.0.0",
|
||||||
"fs-extra": "^9.0.1",
|
"fs-extra": "^9.0.1",
|
||||||
"xml2js": "^0.4.23"
|
"xml2js": "^0.4.23"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user