mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: use problem.md for export
This commit is contained in:
1 parent
69f84b4a28
commit
3e517aa840
6 files changed
+12
-17
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.39.7",
|
"version": "2.39.8",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -114,13 +114,6 @@ TaskModel.Worker.addHandler('import.syzoj', syzojSync);
|
|||||||
class ProblemImportSYZOJHandler extends Handler {
|
class ProblemImportSYZOJHandler extends Handler {
|
||||||
async get() {
|
async get() {
|
||||||
this.response.template = 'problem_import_syzoj.html';
|
this.response.template = 'problem_import_syzoj.html';
|
||||||
this.response.body = {
|
|
||||||
path: [
|
|
||||||
['Hydro', 'homepage'],
|
|
||||||
['problem_main', 'problem_main'],
|
|
||||||
['problem_import_syzoj', null],
|
|
||||||
],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async v2(domainId: string, target: string, hidden = false, url: string) {
|
async v2(domainId: string, target: string, hidden = false, url: string) {
|
||||||
@@ -359,8 +352,10 @@ class ProblemImportHydroHandler extends Handler {
|
|||||||
const pdoc: ProblemDoc = yaml.load(content) as any;
|
const pdoc: ProblemDoc = yaml.load(content) as any;
|
||||||
const current = await problem.get(domainId, pdoc.pid);
|
const current = await problem.get(domainId, pdoc.pid);
|
||||||
const pid = current ? undefined : pdoc.pid;
|
const pid = current ? undefined : pdoc.pid;
|
||||||
|
const overrideContent = fs.existsSync(path.join(tmpdir, i, 'problem.md'))
|
||||||
|
? fs.readFileSync(path.join(tmpdir, i, 'problem.md'), 'utf8') : '';
|
||||||
const docId = await problem.add(
|
const docId = await problem.add(
|
||||||
domainId, pid, pdoc.title, pdoc.content,
|
domainId, pid, pdoc.title, overrideContent || pdoc.content,
|
||||||
keepUser ? pdoc.owner : this.user._id, pdoc.tag, pdoc.hidden,
|
keepUser ? pdoc.owner : this.user._id, pdoc.tag, pdoc.hidden,
|
||||||
);
|
);
|
||||||
if (files.includes('testdata')) {
|
if (files.includes('testdata')) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class Logger {
|
|||||||
static readonly INFO = 2;
|
static readonly INFO = 2;
|
||||||
static readonly WARN = 2;
|
static readonly WARN = 2;
|
||||||
static readonly DEBUG = 3;
|
static readonly DEBUG = 3;
|
||||||
static baseLevel = process.env.DEV ? 3 : 2;
|
static baseLevel = process.env.DEV ? 4 : 2;
|
||||||
static levels: Record<string, number> = {};
|
static levels: Record<string, number> = {};
|
||||||
private code: number;
|
private code: number;
|
||||||
private displayName: string;
|
private displayName: string;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import pipeStream from 'vj/utils/pipeStream';
|
|||||||
import i18n from 'vj/utils/i18n';
|
import i18n from 'vj/utils/i18n';
|
||||||
import request from 'vj/utils/request';
|
import request from 'vj/utils/request';
|
||||||
import Notification from 'vj/components/notification';
|
import Notification from 'vj/components/notification';
|
||||||
import { pick } from 'lodash';
|
|
||||||
|
|
||||||
let isBeforeUnloadTriggeredByLibrary = !window.isSecureContext;
|
let isBeforeUnloadTriggeredByLibrary = !window.isSecureContext;
|
||||||
function onBeforeUnload(e) {
|
function onBeforeUnload(e) {
|
||||||
@@ -47,7 +46,7 @@ export default async function download(name, targets) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// eslint-disable-next-line no-use-before-define
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||||
stopDownload();
|
stopDownload();
|
||||||
Notification.error(i18n('Download Error', [targets[i].filename, e.toString()]));
|
Notification.error(i18n('Download Error', [targets[i].filename, e.toString()]));
|
||||||
}
|
}
|
||||||
@@ -73,17 +72,18 @@ export async function downloadProblemSet(pids, name = 'Export') {
|
|||||||
filename: `${pid}/problem.yaml`,
|
filename: `${pid}/problem.yaml`,
|
||||||
content: dump({
|
content: dump({
|
||||||
pid: pdoc.pid,
|
pid: pdoc.pid,
|
||||||
content: pdoc.content,
|
|
||||||
owner: pdoc.owner,
|
owner: pdoc.owner,
|
||||||
title: pdoc.title,
|
title: pdoc.title,
|
||||||
tag: pdoc.tag,
|
tag: pdoc.tag,
|
||||||
nSubmit: pdoc.nSubmit,
|
nSubmit: pdoc.nSubmit,
|
||||||
nAccept: pdoc.nAccept,
|
nAccept: pdoc.nAccept,
|
||||||
data: (pdoc.data || []).map((i) => pick(i, ['name'])),
|
|
||||||
additional_file: (pdoc.additional_file || []).map((i) => pick(i, ['name'])),
|
|
||||||
difficulty: pdoc.difficulty,
|
difficulty: pdoc.difficulty,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
targets.push({
|
||||||
|
filename: `${pid}/problem.md`,
|
||||||
|
content: pdoc.content,
|
||||||
|
});
|
||||||
let { links } = await request.post(
|
let { links } = await request.post(
|
||||||
`/d/${UiContext.domainId}/p/${pid}/files`,
|
`/d/${UiContext.domainId}/p/${pid}/files`,
|
||||||
{ operation: 'get_links', files: (pdoc.data || []).map((i) => i.name), type: 'testdata' },
|
{ operation: 'get_links', files: (pdoc.data || []).map((i) => i.name), type: 'testdata' },
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.22.8",
|
"version": "4.22.9",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
this.cookie = header['set-cookie'];
|
this.cookie = header['set-cookie'];
|
||||||
}
|
}
|
||||||
const $dom = new JSDOM(html);
|
const $dom = new JSDOM(html);
|
||||||
if ($dom.window.document.body.children.length < 2 && html.length < 1000) {
|
if ($dom.window.document.body.children.length < 2 && html.length < 512) {
|
||||||
throw new Error($dom.window.document.body.textContent);
|
throw new Error($dom.window.document.body.textContent);
|
||||||
}
|
}
|
||||||
return $dom.window.document.querySelector('meta[name="X-Csrf-Token"]').getAttribute('content');
|
return $dom.window.document.querySelector('meta[name="X-Csrf-Token"]').getAttribute('content');
|
||||||
|
|||||||
Reference in new issue
Block a user