mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
vjudge: fix login check (handle redirect)
This commit is contained in:
1 parent
cb95b89452
commit
e32f285876
2 files changed
+13
-8
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/vjudge",
|
"name": "@hydrooj/vjudge",
|
||||||
"version": "1.6.4",
|
"version": "1.6.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",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import StealthPlugin from 'puppeteer-extra-plugin-stealth';
|
|||||||
import superagent from 'superagent';
|
import superagent from 'superagent';
|
||||||
import proxy from 'superagent-proxy';
|
import proxy from 'superagent-proxy';
|
||||||
import {
|
import {
|
||||||
buildContent, Logger, SettingModel, sleep, STATUS,
|
buildContent, Logger, SettingModel, sleep, STATUS, Time,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||||
import { VERDICT } from '../verdict';
|
import { VERDICT } from '../verdict';
|
||||||
@@ -120,6 +120,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
cookies = await page.cookies();
|
cookies = await page.cookies();
|
||||||
}
|
}
|
||||||
this.cookie = cookies.map((i) => `${i.name}=${i.value}`);
|
this.cookie = cookies.map((i) => `${i.name}=${i.value}`);
|
||||||
|
logger.debug('Cookie:', this.cookie);
|
||||||
await this.save({ cookie: this.cookie });
|
await this.save({ cookie: this.cookie });
|
||||||
await page.close();
|
await page.close();
|
||||||
}
|
}
|
||||||
@@ -198,6 +199,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
get loggedIn() {
|
get loggedIn() {
|
||||||
return this.get('/enter').then(({ text: html }) => {
|
return this.get('/enter').then(({ text: html }) => {
|
||||||
if (html.includes('Login into Codeforces')) return false;
|
if (html.includes('Login into Codeforces')) return false;
|
||||||
|
if (html.length < 1000 && html.includes('Redirecting...')) return false;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -221,6 +223,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async puppeteerLogin() {
|
async puppeteerLogin() {
|
||||||
|
await this.ensureBrowser();
|
||||||
if (!this.puppeteer) return false;
|
if (!this.puppeteer) return false;
|
||||||
const page = await this.puppeteer.newPage();
|
const page = await this.puppeteer.newPage();
|
||||||
await page.goto(`${this.account.endpoint}/enter`, { waitUntil: 'networkidle2' });
|
await page.goto(`${this.account.endpoint}/enter`, { waitUntil: 'networkidle2' });
|
||||||
@@ -228,24 +231,26 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
logger.info(`Login portal opened: ${url}`);
|
logger.info(`Login portal opened: ${url}`);
|
||||||
await page.waitForRequest((req) => {
|
await page.waitForRequest((req) => {
|
||||||
if (req.method() !== 'POST') return false;
|
if (req.method() !== 'POST') return false;
|
||||||
if (!req.url().endsWith('/enter')) return false;
|
// sometimes we have validation query strings, ignore them
|
||||||
return true;
|
return req.url().split('?')[0].endsWith('/enter');
|
||||||
}, { timeout: 24 * 3600 * 1000 });
|
}, { timeout: Time.day });
|
||||||
await page.waitForTimeout(10 * 1000);
|
await page.waitForTimeout(10 * 1000);
|
||||||
await this.clearPage(page);
|
await this.clearPage(page);
|
||||||
|
await this.puppeteer?.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async ensureLogin() {
|
async ensureLogin() {
|
||||||
await this.ensureBrowser();
|
|
||||||
if (await this.loggedIn) return true;
|
if (await this.loggedIn) return true;
|
||||||
logger.info('retry normal login');
|
logger.info('retry normal login');
|
||||||
await this.normalLogin();
|
await this.normalLogin();
|
||||||
if (await this.loggedIn) return true;
|
if (await this.loggedIn) return true;
|
||||||
if (!this.puppeteer) return false;
|
|
||||||
logger.info('starting puppeteer login');
|
logger.info('starting puppeteer login');
|
||||||
await this.puppeteerLogin();
|
await this.puppeteerLogin();
|
||||||
if (await this.loggedIn) return true;
|
if (await this.loggedIn) {
|
||||||
|
logger.success('Logged in');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user