mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
vjudge: update codeforces handle
This commit is contained in:
1 parent
9a8557d215
commit
4e7c3077f9
3 files changed
+24
-8
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/vjudge",
|
||||
"version": "1.5.0-next.1",
|
||||
"version": "1.5.0-next.2",
|
||||
"description": "Submit problems to remote oj",
|
||||
"main": "package.json",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
@@ -23,7 +23,7 @@ class Service {
|
||||
this.api = new Provider(account, async (data) => {
|
||||
await coll.updateOne({ _id: account._id }, { $set: data });
|
||||
});
|
||||
this.main();
|
||||
this.main().catch((e) => logger.error(`Error occured in ${account.type}/${account.handle}`, e));
|
||||
}
|
||||
|
||||
async judge(task) {
|
||||
@@ -36,6 +36,7 @@ class Service {
|
||||
await next({ status: STATUS.STATUS_JUDGING, message: `ID = ${rid}` });
|
||||
await this.api.waitForSubmission(rid, next, end);
|
||||
} catch (e) {
|
||||
if (process.env.DEV) logger.error(e);
|
||||
end({ status: STATUS.STATUS_SYSTEM_ERROR, message: e.message });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ export default class CodeforcesProvider implements IBasicProvider {
|
||||
|
||||
async getPage() {
|
||||
const page = await this.puppeteer.newPage();
|
||||
const url = await page.openPortal();
|
||||
logger.info('portal=', url);
|
||||
for (const str of this.cookie) {
|
||||
const [name, value] = str.split(';')[0].split('=');
|
||||
await page.setCookie({ name, value, domain: 'codeforces.com' });
|
||||
@@ -65,7 +67,11 @@ export default class CodeforcesProvider implements IBasicProvider {
|
||||
}
|
||||
|
||||
async clearPage(page: Page) {
|
||||
const cookies = await page.cookies();
|
||||
let cookies = await page.cookies();
|
||||
while (!cookies.find((i) => i.name === 'evercookie_etag').value) {
|
||||
await sleep(1000);
|
||||
cookies = await page.cookies();
|
||||
}
|
||||
this.cookie = cookies.map((i) => `${i.name}=${i.value}`);
|
||||
await this.save({ cookie: this.cookie });
|
||||
await page.close();
|
||||
@@ -106,11 +112,19 @@ export default class CodeforcesProvider implements IBasicProvider {
|
||||
async checkLogin() {
|
||||
await this.ensureBrowser();
|
||||
const page = await this.getPage();
|
||||
await page.goto(`${this.account.endpoint}/enter`);
|
||||
await page.goto(`${this.account.endpoint}/enter`, { waitUntil: 'networkidle2' });
|
||||
const html = await page.content();
|
||||
const cookies = await page.cookies();
|
||||
this.cookie = cookies.map((i) => `${i.name}=${i.value}`);
|
||||
await this.save({ cookie: this.cookie });
|
||||
let cookies = await page.cookies();
|
||||
let c = 0;
|
||||
while (!cookies.find((i) => i.name === 'evercookie_etag').value && c <= 60) {
|
||||
await sleep(1000);
|
||||
cookies = await page.cookies();
|
||||
c++;
|
||||
}
|
||||
if (c < 60) {
|
||||
this.cookie = cookies.map((i) => `${i.name}=${i.value}`);
|
||||
await this.save({ cookie: this.cookie });
|
||||
}
|
||||
const ftaa = cookies.find((i) => i.name === '70a7c28f3de')?.value;
|
||||
const bfaa = /_bfaa = "(.{32})"/.exec(html)?.[1];
|
||||
await page.close();
|
||||
@@ -164,7 +178,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
||||
async puppeteerLogin() {
|
||||
if (!this.puppeteer) return false;
|
||||
const page = await this.puppeteer.newPage();
|
||||
await page.goto(`${this.account.endpoint}/enter`);
|
||||
await page.goto(`${this.account.endpoint}/enter`, { waitUntil: 'networkidle2' });
|
||||
const url = await page.openPortal();
|
||||
logger.info(`Login portal opened: ${url}`);
|
||||
await page.waitForRequest((req) => {
|
||||
@@ -184,6 +198,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
||||
logger.info('retry normal login');
|
||||
await this.normalLogin();
|
||||
if (await this.loggedIn) return true;
|
||||
if (!this.puppeteer) return false;
|
||||
logger.info('starting puppeteer login');
|
||||
await this.puppeteerLogin();
|
||||
if (await this.loggedIn) return true;
|
||||
|
||||
Reference in new issue
Block a user