vjudge: codeforces: fix login check

pull/555/head
undefined 2 years ago
parent fc0704c53f
commit 9f1169b3e0
No known key found for this signature in database

@ -1,6 +1,6 @@
{
"name": "@hydrooj/vjudge",
"version": "1.8.5",
"version": "1.8.6",
"description": "Submit problems to remote oj",
"main": "src/model.ts",
"repository": "https://github.com/hydro-dev/Hydro.git",

@ -33,10 +33,11 @@ export class BasicFetcher {
}
async html(url: string) {
const { text: html } = await this.get(url);
const { text: html, headers } = await this.get(url);
const $dom = new JSDOM(html);
$dom.window.html = html;
return $dom.window as DOMWindow & { html: string };
$dom.window.headers = headers;
return $dom.window as DOMWindow & { html: string, headers: any };
}
post(url: string) {

@ -21,7 +21,10 @@ class AccountService {
await coll.updateOne({ _id: account._id }, { $set: data });
});
this.problemLists = Set.union(this.api.entryProblemLists || ['main'], this.account.problemLists || []);
this.main().catch((e) => logger.error(`Error occured in ${account.type}/${account.handle}`, e));
this.main().catch((e) => {
logger.error(`Error occured in ${account.type}/${account.handle}`);
console.error(e);
});
}
async addProblemList(name: string) {

@ -83,37 +83,37 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
}
async getCsrfToken(url: string) {
const { document, html } = await this.html(url);
const { document, html, headers } = await this.html(url);
if (document.body.children.length < 2 && html.length < 512) {
throw new Error(document.body.textContent);
throw new Error(document.body.textContent!);
}
const ftaa = this.getCookie('70a7c28f3de');
const bfaa = /_bfaa = "(.{32})"/.exec(html)?.[1] || this.getCookie('raa') || this.getCookie('bfaa');
const ftaa = this.getCookie('70a7c28f3de') || 'n/a';
const bfaa = this.getCookie('raa') || this.getCookie('bfaa') || 'n/a';
return [
(
document.querySelector('meta[name="X-Csrf-Token"]')
|| document.querySelector('input[name="csrf_token"]')
)?.getAttribute('content'),
ftaa, bfaa,
ftaa, bfaa, headers,
];
}
get loggedIn() {
return this.get('/enter').then((res) => {
return this.get('/').then((res) => {
const html = res.text;
if (html.includes('Login into Codeforces')) return false;
if (html.length < 1000 && html.includes('Redirecting...')) {
logger.debug('Got a redirect', html);
return false;
}
return true;
return html.includes('header-bell__img');
});
}
async ensureLogin() {
if (await this.loggedIn) return true;
logger.info('retry normal login');
const [csrf, ftaa, bfaa] = await this.getCsrfToken('/enter');
const [csrf, ftaa, bfaa, header] = await this.getCsrfToken('/enter');
if (header['set-cookie']) this.setCookie(header['set-cookie']);
const res = await this.post('/enter').send({
csrf_token: csrf,
action: 'enter',

Loading…
Cancel
Save