mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: buildContent by default
This commit is contained in:
1 parent
29eff97c1a
commit
0fcbcf4f1a
5 files changed
+27
-4
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.26.23",
|
"version": "2.26.24",
|
||||||
"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",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
} from '../service/server';
|
} from '../service/server';
|
||||||
import { isPid, parsePid } from '../lib/validator';
|
import { isPid, parsePid } from '../lib/validator';
|
||||||
import download from '../lib/download';
|
import download from '../lib/download';
|
||||||
|
import { buildContent } from '../lib/content';
|
||||||
|
|
||||||
const RE_SYZOJ = /(https?):\/\/([^/]+)\/(problem|p)\/([0-9]+)\/?/i;
|
const RE_SYZOJ = /(https?):\/\/([^/]+)\/(problem|p)\/([0-9]+)\/?/i;
|
||||||
const logger = new Logger('import.syzoj');
|
const logger = new Logger('import.syzoj');
|
||||||
@@ -142,8 +143,9 @@ class ProblemImportSYZOJHandler extends Handler {
|
|||||||
text: `${url}download/additional_file`,
|
text: `${url}download/additional_file`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const c = buildContent(content, 'markdown');
|
||||||
const docId = await problem.add(
|
const docId = await problem.add(
|
||||||
domainId, target, p.title, JSON.stringify(content), this.user._id, p.tags || [], hidden,
|
domainId, target, p.title, c, this.user._id, p.tags || [], hidden,
|
||||||
);
|
);
|
||||||
const r = download(`${url}testdata/download`);
|
const r = download(`${url}testdata/download`);
|
||||||
const file = path.resolve(os.tmpdir(), 'hydro', `import_${domainId}_${docId}.zip`);
|
const file = path.resolve(os.tmpdir(), 'hydro', `import_${domainId}_${docId}.zip`);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { STATUS } from './model/builtin';
|
|||||||
import RecordModel from './model/record';
|
import RecordModel from './model/record';
|
||||||
import StorageModel from './model/storage';
|
import StorageModel from './model/storage';
|
||||||
import { size } from './lib/misc';
|
import { size } from './lib/misc';
|
||||||
|
import { buildContent } from './lib/content';
|
||||||
|
|
||||||
const logger = new Logger('upgrade');
|
const logger = new Logger('upgrade');
|
||||||
type UpgradeScript = void | (() => Promise<boolean | void>);
|
type UpgradeScript = void | (() => Promise<boolean | void>);
|
||||||
@@ -373,6 +374,25 @@ const scripts: UpgradeScript[] = [
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
async function _28_29() {
|
||||||
|
const _FRESH_INSTALL_IGNORE = 1;
|
||||||
|
await iterateAllProblem(['content', 'html'], async (pdoc) => {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(pdoc.content);
|
||||||
|
if (parsed instanceof Array) {
|
||||||
|
await problem.edit(pdoc.domainId, pdoc.docId, { content: buildContent(parsed, pdoc.html ? 'html' : 'markdown') });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const res = {};
|
||||||
|
for (const key in parsed) {
|
||||||
|
if (typeof parsed[key] === 'string') res[key] = parsed[key];
|
||||||
|
else res[key] = buildContent(parsed[key]);
|
||||||
|
}
|
||||||
|
await problem.edit(pdoc.domainId, pdoc.docId, { content: JSON.stringify(res) });
|
||||||
|
} catch { }
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default scripts;
|
export default scripts;
|
||||||
@@ -9,6 +9,7 @@ import { BadRequestError, ValidationError } from 'hydrooj/dist/error';
|
|||||||
import { ProblemAdd } from 'hydrooj/dist/lib/ui';
|
import { ProblemAdd } from 'hydrooj/dist/lib/ui';
|
||||||
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 { buildContent } from 'hydrooj/dist/lib/content';
|
||||||
import type { ContentNode, ProblemConfig } from 'hydrooj';
|
import type { ContentNode, ProblemConfig } from 'hydrooj';
|
||||||
|
|
||||||
fs.ensureDirSync('/tmp/hydro/import-qduoj');
|
fs.ensureDirSync('/tmp/hydro/import-qduoj');
|
||||||
@@ -76,7 +77,7 @@ class ImportQduojHandler extends Handler {
|
|||||||
if (+pdoc.display_id) pdoc.display_id = `P${pdoc.display_id}`;
|
if (+pdoc.display_id) pdoc.display_id = `P${pdoc.display_id}`;
|
||||||
const n = await problem.get(domainId, pdoc.display_id);
|
const n = await problem.get(domainId, pdoc.display_id);
|
||||||
if (n) pdoc.display_id = null;
|
if (n) pdoc.display_id = null;
|
||||||
const pid = await problem.add(domainId, pdoc.display_id, pdoc.title, JSON.stringify(content), this.user._id, pdoc.tags);
|
const pid = await problem.add(domainId, pdoc.display_id, pdoc.title, buildContent(content, 'html'), this.user._id, pdoc.tags);
|
||||||
const config: ProblemConfig = {
|
const config: ProblemConfig = {
|
||||||
time: `${pdoc.time_limit}ms`,
|
time: `${pdoc.time_limit}ms`,
|
||||||
memory: `${pdoc.memory_limit}m`,
|
memory: `${pdoc.memory_limit}m`,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/import-qduoj",
|
"name": "@hydrooj/import-qduoj",
|
||||||
"version": "1.1.8",
|
"version": "1.1.9",
|
||||||
"description": "Import QDUOJ problem export",
|
"description": "Import QDUOJ problem export",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
Reference in new issue
Block a user