fix(remote_judger/codeforces): fetch submission

This commit is contained in:
Baoshuo Ren 2023-11-12 15:38:45 +08:00
parent a734c829b9
commit 0098031da1
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -341,9 +341,12 @@ export default class CodeforcesProvider implements IBasicProvider {
this.csrf = document this.csrf = document
.querySelector('meta[name="X-Csrf-Token"]') .querySelector('meta[name="X-Csrf-Token"]')
.getAttribute('content'); .getAttribute('content');
return document
const submission = document
.querySelector('[data-submission-id]') .querySelector('[data-submission-id]')
.getAttribute('data-submission-id'); .getAttribute('data-submission-id');
return type !== 'GYM' ? submission : `${contestId}#${submission}`;
} }
async ensureIsOwnSubmission(id: string) { async ensureIsOwnSubmission(id: string) {
@ -354,21 +357,30 @@ export default class CodeforcesProvider implements IBasicProvider {
let count = 0; let count = 0;
let fail = 0; let fail = 0;
const contestId = id.includes('#') ? id.split('#')[0] : null;
const submissionId = id.includes('#') ? id.split('#')[1] : id;
while (count < 360 && fail < 60) { while (count < 360 && fail < 60) {
count++; count++;
await sleep(500); await sleep(500);
try { try {
const { body } = await this.post('/data/submitSource') const { body } = await this.post('/data/submitSource')
.set(
'referer',
contestId
? `https://codeforces.com/gym/${contestId}/my`
: 'https://codeforces.com/problemset/status?my=on'
)
.send({ .send({
csrf_token: this.csrf, csrf_token: this.csrf,
submissionId: id, submissionId: submissionId,
}) })
.retry(3); .retry(3);
if (body.compilationError === 'true') { if (body.compilationError === 'true') {
return await end({ return await end({
id, id: submissionId,
error: true, error: true,
status: 'Compile Error', status: 'Compile Error',
message: crlf(body['checkerStdoutAndStderr#1'], LF), message: crlf(body['checkerStdoutAndStderr#1'], LF),
@ -439,7 +451,7 @@ export default class CodeforcesProvider implements IBasicProvider {
Object.entries({ Object.entries({
比赛: stripHtml(body.contestName).result, 比赛: stripHtml(body.contestName).result,
题目: stripHtml(body.problemName).result, 题目: stripHtml(body.problemName).result,
: `<a href="https://codeforces.com${body.href}">${id}</a>`, : `<a href="https://codeforces.com${body.href}">${submissionId}</a>`,
: `<a href="https://codeforces.com/profile/${remote_handle}">${remote_handle}</a>`, : `<a href="https://codeforces.com/profile/${remote_handle}">${remote_handle}</a>`,
状态: stripHtml(body.verdict).result, 状态: stripHtml(body.verdict).result,
}) })
@ -453,7 +465,7 @@ export default class CodeforcesProvider implements IBasicProvider {
'</div>'; '</div>';
return await end({ return await end({
id, id: submissionId,
status, status,
score: status === 'Accepted' ? 100 : 0, score: status === 'Accepted' ? 100 : 0,
time, time,
@ -469,7 +481,7 @@ export default class CodeforcesProvider implements IBasicProvider {
} }
return await end({ return await end({
id, id: submissionId,
error: true, error: true,
status: 'Judgment Failed', status: 'Judgment Failed',
message: 'Failed to fetch submission details.', message: 'Failed to fetch submission details.',