mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
vjudge: handle pdf problems
This commit is contained in:
1 parent
c9d4eb3d1f
commit
cc4c3700d5
2 files changed
+18
-2
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/vjudge",
|
"name": "@hydrooj/vjudge",
|
||||||
"version": "1.0.8",
|
"version": "1.0.9",
|
||||||
"description": "Submit problems to remote oj",
|
"description": "Submit problems to remote oj",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -97,13 +97,29 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getPdfProblem(id: string) {
|
||||||
|
const [, contestId, problemId] = id.startsWith('P921')
|
||||||
|
? ['', '921', '01']
|
||||||
|
: /^P(\d+)([A-Z][0-9]?)$/.exec(id);
|
||||||
|
const file = new PassThrough();
|
||||||
|
this.get(`/problemset/problem/${contestId}/${problemId}`).pipe(file);
|
||||||
|
return {
|
||||||
|
title: '__NO_TITLE__',
|
||||||
|
data: { 'config.yaml': Buffer.from(`type: remote_judge\nsubType: codeforces\ntarget: ${id}`) },
|
||||||
|
files: { 'problem.pdf': file },
|
||||||
|
tag: [],
|
||||||
|
content: '@[pdf](file://problem.pdf)',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async getProblem(id: string) {
|
async getProblem(id: string) {
|
||||||
logger.info(id);
|
logger.info(id);
|
||||||
|
if (id === 'P936E') return null; // Problem Missing
|
||||||
const [, contestId, problemId] = id.startsWith('P921')
|
const [, contestId, problemId] = id.startsWith('P921')
|
||||||
? ['', '921', '01']
|
? ['', '921', '01']
|
||||||
: /^P(\d+)([A-Z][0-9]?)$/.exec(id);
|
: /^P(\d+)([A-Z][0-9]?)$/.exec(id);
|
||||||
const res = await this.get(`/problemset/problem/${contestId}/${problemId}`);
|
const res = await this.get(`/problemset/problem/${contestId}/${problemId}`);
|
||||||
if (!res.text) return null;
|
if (!res.text) return await this.getPdfProblem(id);
|
||||||
const $dom = new JSDOM(res.text.replace(/\$\$\$/g, '$'));
|
const $dom = new JSDOM(res.text.replace(/\$\$\$/g, '$'));
|
||||||
const tag = Array.from($dom.window.document.querySelectorAll('.tag-box')).map((i) => i.textContent.trim());
|
const tag = Array.from($dom.window.document.querySelectorAll('.tag-box')).map((i) => i.textContent.trim());
|
||||||
const text = $dom.window.document.querySelector('.problem-statement').innerHTML;
|
const text = $dom.window.document.querySelector('.problem-statement').innerHTML;
|
||||||
|
|||||||
Reference in new issue
Block a user