vjudge: codeforces: allow frozen cookie

This commit is contained in:
undefined committed 2021-10-22 23:17:30 +08:00
1 parent d2277aa76f
commit add74b312e
2 files changed
+15 -16

No files matched your search

+1
View File
@@ -7,6 +7,7 @@ export interface RemoteAccount {
endpoint?: string; endpoint?: string;
proxy?: string; proxy?: string;
query?: string; query?: string;
frozen?: string;
} }
declare module 'hydrooj/src/interface' { declare module 'hydrooj/src/interface' {
interface Collections { interface Collections {
+14 -16
View File
@@ -67,23 +67,21 @@ export default class CodeforcesProvider implements IBasicProvider {
} }
async getCsrfToken(url: string) { async getCsrfToken(url: string) {
const { text: html, header } = await this.get(url); const { text: html } = await this.get(url);
if (header['set-cookie']) { const { window: { document } } = new JSDOM(html);
await this.save({ cookie: header['set-cookie'] }); if (document.body.children.length < 2 && html.length < 512) {
this.cookie = header['set-cookie']; throw new Error(document.body.textContent);
} }
const $dom = new JSDOM(html); return (
if ($dom.window.document.body.children.length < 2 && html.length < 512) { document.querySelector('meta[name="X-Csrf-Token"]')
throw new Error($dom.window.document.body.textContent); || document.querySelector('input[name="csrf_token"]')
} )?.getAttribute('content');
return $dom.window.document.querySelector('meta[name="X-Csrf-Token"]').getAttribute('content');
} }
get loggedIn() { get loggedIn() {
return this.get('/').then(({ text: html }) => { return this.get('/enter').then(({ text: html }) => {
const $dom = new JSDOM(html); if (html.includes('Login into Codeforces')) return false;
if (!$dom.window.document.querySelectorAll('a[href="/enter?back=%2F"]').length) return true; return true;
return false;
}); });
} }
@@ -101,7 +99,7 @@ export default class CodeforcesProvider implements IBasicProvider {
remember: 'on', remember: 'on',
}); });
const cookie = res.header['set-cookie']; const cookie = res.header['set-cookie'];
if (cookie) { if (cookie && !this.account.frozen) {
await this.save({ cookie }); await this.save({ cookie });
this.cookie = cookie; this.cookie = cookie;
} }
@@ -203,7 +201,7 @@ export default class CodeforcesProvider implements IBasicProvider {
} }
async submitProblem(id: string, lang: string, code: string, info) { async submitProblem(id: string, lang: string, code: string, info) {
const programTypeId = lang.includes('codeforces.') ? lang.split('codeforces.')[1] : '42'; const programTypeId = lang.includes('codeforces.') ? lang.split('codeforces.')[1] : '54';
const comment = setting.langs[lang].comment; const comment = setting.langs[lang].comment;
if (comment) { if (comment) {
const msg = `Hydro submission #${info.rid}@${new Date().getTime()}`; const msg = `Hydro submission #${info.rid}@${new Date().getTime()}`;
@@ -226,7 +224,7 @@ export default class CodeforcesProvider implements IBasicProvider {
sourceFile: '', sourceFile: '',
ftaa: '', ftaa: '',
bfaa: 'f1b3f18c715565b589b7823cda7448ce', bfaa: 'f1b3f18c715565b589b7823cda7448ce',
_tta: 594, _tta: 140,
sourceCodeConfirmed: true, sourceCodeConfirmed: true,
}); });
const { text: status } = await this.get('/problemset/status?my=on'); const { text: status } = await this.get('/problemset/status?my=on');