vjudge: fix codeforces gym get problem (#423)

This commit is contained in:
guke1024 authored and GitHub committed 2022-08-31 15:39:13 +08:00
1 parent 5f4e43f4da
commit b837ae604a
3 files changed
+11 -3

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/vjudge", "name": "@hydrooj/vjudge",
"version": "1.5.0-next.10", "version": "1.5.0-next.11",
"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",
+1
View File
@@ -63,6 +63,7 @@ class Service {
await this.addProblemList(id.split('::')[1]); await this.addProblemList(id.split('::')[1]);
continue; continue;
} }
if (id.search('\\\\#') !== -1) continue;
const [pid, metastr = '{}'] = id.split('#'); const [pid, metastr = '{}'] = id.split('#');
const meta = JSON.parse(metastr); const meta = JSON.parse(metastr);
if (await ProblemModel.get(domainId, pid) || syncing[`${domainId}/${pid}`]) continue; if (await ProblemModel.get(domainId, pid) || syncing[`${domainId}/${pid}`]) continue;
+9 -2
View File
@@ -31,7 +31,7 @@ puppeteer.use(StealthPlugin()).use(PortalPlugin({
function parseProblemId(id: string) { function parseProblemId(id: string) {
const [, type, contestId, problemId] = id.startsWith('P921') const [, type, contestId, problemId] = id.startsWith('P921')
? ['', '921', '01'] ? ['', '921', '01']
: /^(P|GYM)(\d+)([A-Z][0-9]*)$/.exec(id); : /^(P|GYM)(\d+)([A-Z]+[0-9]*)$/.exec(id);
if (type === 'GYM' && (+contestId) < 100000) { if (type === 'GYM' && (+contestId) < 100000) {
return [type, ((+contestId) + 100000).toString(), problemId]; return [type, ((+contestId) + 100000).toString(), problemId];
} }
@@ -276,12 +276,19 @@ export default class CodeforcesProvider implements IBasicProvider {
async getProblem(id: string, meta: Record<string, any>) { async getProblem(id: string, meta: Record<string, any>) {
logger.info(id); logger.info(id);
if (id === 'P936E') return null; // Problem Missing if (id === 'P936E') return null; // Problem Missing
if (id.startsWith('GYM') && !Number.isNaN(Number(id[9]))) return null; // GYM Problem Missing
const [, contestId, problemId] = parseProblemId(id); const [, contestId, problemId] = parseProblemId(id);
const res = await this.get(id.startsWith('GYM') const res = await this.get(id.startsWith('GYM')
? `/gym/${contestId}/problem/${problemId}` ? `/gym/${contestId}/problem/${problemId}`
: `/problemset/problem/${contestId}/${problemId}`); : `/problemset/problem/${contestId}/${problemId}`);
if (!res.text) return await this.getPdfProblem(id, meta); if (!res.text) return await this.getPdfProblem(id, meta);
const $dom = new JSDOM(res.text.replace(/\$\$\$/g, '$')); const $dom = new JSDOM(res.text.replace(/\$\$\$/g, '$'));
const judgestatement = $dom.window.document.querySelector('html').innerHTML;
if (['<th>Actions</th>',
'Statement is not available on English language',
'ограничение по времени на тест'].find((i) => judgestatement.includes(i))) {
return null;
}
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;
const { window: { document } } = new JSDOM(text); const { window: { document } } = new JSDOM(text);
@@ -364,7 +371,7 @@ export default class CodeforcesProvider implements IBasicProvider {
return Array.from(document.querySelectorAll('.id>a')).map((i) => `P${i.innerHTML.trim()}`); return Array.from(document.querySelectorAll('.id>a')).map((i) => `P${i.innerHTML.trim()}`);
} }
if (listName === 'gym') { if (listName === 'gym') {
return Array.from(document.querySelectorAll('[data-contestId]')).map((i) => `LIST::GYM${(+i.getAttribute('data-contestId')) - 100000}`); return Array.from(document.querySelectorAll('[data-contestId]')).map((i) => `LIST::GYM${i.getAttribute('data-contestId')}`);
} }
return Array.from(document.querySelectorAll('.id a')).map((i) => { return Array.from(document.querySelectorAll('.id a')).map((i) => {
const detail = i.parentElement.parentElement.children[1].children[0]; const detail = i.parentElement.parentElement.children[1].children[0];