mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
fps-import: support fps version 1.4
This commit is contained in:
1 parent
bd1034eff8
commit
88613c8a05
3 files changed
+23
-20
No files matched your search
@@ -61,29 +61,30 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
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 ProblemModel.add(domainId, null, title, buildContent(content, 'html'), this.user._id, tags);
|
const pid = await ProblemModel.add(domainId, null, title, buildContent(content, 'html'), this.user._id, tags);
|
||||||
await ProblemModel.addTestdata(domainId, pid, 'config.yaml', Buffer.from(`time: ${config.time}\nmemory: ${config.memory}`));
|
const tasks = [
|
||||||
|
ProblemModel.edit(domainId, pid, { html: true }),
|
||||||
|
ProblemModel.addTestdata(domainId, pid, 'config.yaml', Buffer.from(`time: ${config.time}\nmemory: ${config.memory}`)),
|
||||||
|
];
|
||||||
|
const addTestdata = (node: any, id: string, ext: string) => {
|
||||||
|
let c = node;
|
||||||
|
if (node.$?.name) {
|
||||||
|
id = node.$.name;
|
||||||
|
c = node._;
|
||||||
|
}
|
||||||
|
tasks.push(ProblemModel.addTestdata(domainId, pid, `${id}.${ext}`, Buffer.from(c)));
|
||||||
|
};
|
||||||
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++) {
|
||||||
const input = typeof p.test_input[i]?._ === 'string'
|
addTestdata(p.test_input[i], `${i + 1}`, 'in');
|
||||||
? p.test_input[i]?._
|
addTestdata(p.test_output[i], `${i + 1}`, 'out');
|
||||||
: typeof p.test_input[i] === 'string'
|
|
||||||
? p.test_input[i]
|
|
||||||
: '';
|
|
||||||
const output = typeof p.test_output[i]?._ === 'string'
|
|
||||||
? p.test_output[i]?._
|
|
||||||
: typeof p.test_output[i] === 'string'
|
|
||||||
? p.test_output[i]
|
|
||||||
: '';
|
|
||||||
await ProblemModel.addTestdata(domainId, pid, `${i + 1}.in`, Buffer.from(input));
|
|
||||||
await ProblemModel.addTestdata(domainId, pid, `${i + 1}.out`, Buffer.from(output));
|
|
||||||
}
|
}
|
||||||
} else if (p.test_input) {
|
} else if (p.test_input) {
|
||||||
for (let i = 0; i < p.test_input.length / 2; i++) {
|
for (let i = 0; i < p.test_input.length / 2; i++) {
|
||||||
await ProblemModel.addTestdata(domainId, pid, `${i + 1}.in`, Buffer.from(p.test_input[2 * i]));
|
addTestdata(p.test_input[2 * i], `${i + 1}`, 'in');
|
||||||
await ProblemModel.addTestdata(domainId, pid, `${i + 1}.out`, Buffer.from(p.test_input[2 * i + 1]));
|
addTestdata(p.test_input[2 * i + 1], `${i + 1}`, 'out');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await ProblemModel.edit(domainId, pid, { html: true });
|
await Promise.all(tasks);
|
||||||
if (p.solution) {
|
if (p.solution) {
|
||||||
let s = '';
|
let s = '';
|
||||||
for (const sol of p.solution) {
|
for (const sol of p.solution) {
|
||||||
@@ -131,4 +132,7 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
export async function apply(ctx: Context) {
|
export async function apply(ctx: Context) {
|
||||||
ctx.Route('problem_import_fps', '/problem/import/fps', FpsProblemImportHandler, PERM.PERM_CREATE_PROBLEM);
|
ctx.Route('problem_import_fps', '/problem/import/fps', FpsProblemImportHandler, PERM.PERM_CREATE_PROBLEM);
|
||||||
ctx.inject('ProblemAdd', 'problem_import_fps', { icon: 'copy', text: 'From FPS File' });
|
ctx.inject('ProblemAdd', 'problem_import_fps', { icon: 'copy', text: 'From FPS File' });
|
||||||
|
ctx.i18n.load('zh', {
|
||||||
|
'From FPS File': '从 FPS 文件导入',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
From FPS File: 从 FPS 文件导入
|
|
||||||
@@ -64,13 +64,13 @@ String.prototype.format = function formatStr(...args) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function isClass(obj: any, strict = false) {
|
export function isClass(obj: any, strict = false): obj is new (...args: any) => any {
|
||||||
if (typeof obj !== 'function') return false;
|
if (typeof obj !== 'function') return false;
|
||||||
const str = obj.toString();
|
|
||||||
if (obj.prototype === undefined) return false;
|
if (obj.prototype === undefined) return false;
|
||||||
if (obj.prototype.constructor !== obj) return false;
|
if (obj.prototype.constructor !== obj) return false;
|
||||||
if (str.slice(0, 5) === 'class') return true;
|
|
||||||
if (Object.getOwnPropertyNames(obj.prototype).length >= 2) return true;
|
if (Object.getOwnPropertyNames(obj.prototype).length >= 2) return true;
|
||||||
|
const str = obj.toString();
|
||||||
|
if (str.slice(0, 5) === 'class') return true;
|
||||||
if (/^function\s+\(|^function\s+anonymous\(/.test(str)) return false;
|
if (/^function\s+\(|^function\s+anonymous\(/.test(str)) return false;
|
||||||
if (strict && /^function\s+[A-Z]/.test(str)) return true;
|
if (strict && /^function\s+[A-Z]/.test(str)) return true;
|
||||||
if (/\b\(this\b|\bthis[.[]\b/.test(str)) {
|
if (/\b\(this\b|\bthis[.[]\b/.test(str)) {
|
||||||
|
|||||||
Reference in new issue
Block a user