mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
vjudge: codeforces: gym: use shortand contestId
This commit is contained in:
1 parent
6f791903d4
commit
7d3f715c6c
2 files changed
+21
-15
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/vjudge",
|
"name": "@hydrooj/vjudge",
|
||||||
"version": "1.5.0-next.4",
|
"version": "1.5.0-next.5",
|
||||||
"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",
|
||||||
|
|||||||
@@ -28,6 +28,16 @@ puppeteer.use(StealthPlugin()).use(PortalPlugin({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
function parseProblemId(id: string) {
|
||||||
|
const [, type, contestId, problemId] = id.startsWith('P921')
|
||||||
|
? ['', '921', '01']
|
||||||
|
: /^(P|GYM)(\d+)([A-Z][0-9]*)$/.exec(id);
|
||||||
|
if (type === 'GYM' && (+contestId) < 100000) {
|
||||||
|
return [type, ((+contestId) + 100000).toString(), problemId];
|
||||||
|
}
|
||||||
|
return [type, contestId, problemId];
|
||||||
|
}
|
||||||
|
|
||||||
export function getDifficulty(tags: string[]) {
|
export function getDifficulty(tags: string[]) {
|
||||||
const d = tags.find((i) => /^\*\d+$/.test(i))?.split('*')[1];
|
const d = tags.find((i) => /^\*\d+$/.test(i))?.split('*')[1];
|
||||||
if (!(d && +d)) return null;
|
if (!(d && +d)) return null;
|
||||||
@@ -226,9 +236,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getPdfProblem(id: string, meta: Record<string, any>) {
|
async getPdfProblem(id: string, meta: Record<string, any>) {
|
||||||
const [, , contestId, problemId] = id.startsWith('P921')
|
const [, contestId, problemId] = parseProblemId(id);
|
||||||
? ['', '921', '01']
|
|
||||||
: /^(P|GYM)(\d+)([A-Z][0-9]*)$/.exec(id);
|
|
||||||
const file = new PassThrough();
|
const file = new PassThrough();
|
||||||
this.get(id.startsWith('GYM')
|
this.get(id.startsWith('GYM')
|
||||||
? `/gym/${contestId}/problem/${problemId}`
|
? `/gym/${contestId}/problem/${problemId}`
|
||||||
@@ -252,9 +260,7 @@ 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
|
||||||
const [, , contestId, problemId] = id.startsWith('P921')
|
const [, contestId, problemId] = parseProblemId(id);
|
||||||
? ['', '921', '01']
|
|
||||||
: /^(P|GYM)(\d+)([A-Z][0-9]*)$/.exec(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}`);
|
||||||
@@ -342,7 +348,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')}`);
|
return Array.from(document.querySelectorAll('[data-contestId]')).map((i) => `LIST::GYM${(+i.getAttribute('data-contestId')) - 100000}`);
|
||||||
}
|
}
|
||||||
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];
|
||||||
@@ -363,12 +369,12 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
if (typeof comment === 'string') code = `${comment} ${msg}\n${code}`;
|
if (typeof comment === 'string') code = `${comment} ${msg}\n${code}`;
|
||||||
else if (comment instanceof Array) code = `${comment[0]} ${msg} ${comment[1]}\n${code}`;
|
else if (comment instanceof Array) code = `${comment[0]} ${msg} ${comment[1]}\n${code}`;
|
||||||
}
|
}
|
||||||
const contestId = /(\d+)/.exec(id)?.[1];
|
const [type, contestId, problemId] = parseProblemId(id);
|
||||||
const [csrf, ftaa, bfaa] = await this.getCsrfToken((+contestId) < 100000
|
const [csrf, ftaa, bfaa] = await this.getCsrfToken(type !== 'GYM'
|
||||||
? '/problemset/submit'
|
? '/problemset/submit'
|
||||||
: `/gym/${contestId}/submit`);
|
: `/gym/${contestId}/submit`);
|
||||||
// TODO check submit time to ensure submission
|
// TODO check submit time to ensure submission
|
||||||
await this.post(`/${(+contestId) < 100000 ? 'problemset' : `gym/${contestId}`}/submit?csrf_token=${csrf}`).send({
|
await this.post(`/${type !== 'GYM' ? 'problemset' : `gym/${contestId}`}/submit?csrf_token=${csrf}`).send({
|
||||||
csrf_token: csrf,
|
csrf_token: csrf,
|
||||||
action: 'submitSolutionFormSubmitted',
|
action: 'submitSolutionFormSubmitted',
|
||||||
programTypeId,
|
programTypeId,
|
||||||
@@ -378,15 +384,15 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
ftaa,
|
ftaa,
|
||||||
bfaa,
|
bfaa,
|
||||||
_tta: this.tta(this.getCookie('39ce7')),
|
_tta: this.tta(this.getCookie('39ce7')),
|
||||||
...(+contestId < 100000)
|
...(type !== 'GYM')
|
||||||
? {
|
? {
|
||||||
submittedProblemCode: id.split('P')[1],
|
submittedProblemCode: contestId + problemId,
|
||||||
sourceCodeConfirmed: true,
|
sourceCodeConfirmed: true,
|
||||||
} : {
|
} : {
|
||||||
submittedProblemIndex: /([A-Z])$/.exec(id)?.[1],
|
submittedProblemIndex: problemId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { text: status } = await this.get((+contestId) < 100000
|
const { text: status } = await this.get(type !== 'GYM'
|
||||||
? '/problemset/status?my=on'
|
? '/problemset/status?my=on'
|
||||||
: `/gym/${contestId}/my`);
|
: `/gym/${contestId}/my`);
|
||||||
const { window: { document } } = new JSDOM(status);
|
const { window: { document } } = new JSDOM(status);
|
||||||
|
|||||||
Reference in new issue
Block a user