mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
upgrade deps
This commit is contained in:
16 files changed
+81
-95
No files matched your search
@@ -14,7 +14,7 @@
|
||||
"superagent-proxy": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jsdom": "21.1.5",
|
||||
"@types/jsdom": "21.1.6",
|
||||
"@types/superagent-proxy": "^3.0.3"
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ interface FetchOptions {
|
||||
get?: Omit<FetchOptions, 'get' | 'post'>
|
||||
}
|
||||
|
||||
const UA = `Hydro/${global.Hydro.version.hydrooj} VJudge/${global.Hydro.version.vjudge}`;
|
||||
|
||||
export class BasicFetcher {
|
||||
cookie: string[] = [];
|
||||
|
||||
@@ -26,7 +28,7 @@ export class BasicFetcher {
|
||||
get(url: string) {
|
||||
this.logger.debug('get', url);
|
||||
url = new URL(url, this.account.endpoint || this.defaultEndpoint).toString();
|
||||
let req = superagent.get(url).set('Cookie', this.cookie);
|
||||
let req = superagent.get(url).set('Cookie', this.cookie).set('User-Agent', UA);
|
||||
if (this.fetchOptions.headers) req = req.set(this.fetchOptions.headers);
|
||||
if (this.fetchOptions.get?.headers) req = req.set(this.fetchOptions.get.headers);
|
||||
return this.account.proxy ? req.proxy(this.account.proxy) : req;
|
||||
@@ -43,15 +45,17 @@ export class BasicFetcher {
|
||||
post(url: string) {
|
||||
this.logger.debug('post', url, this.cookie);
|
||||
url = new URL(url, this.account.endpoint || this.defaultEndpoint).toString();
|
||||
let req = superagent.post(url).set('Cookie', this.cookie).type(this.formType);
|
||||
let req = superagent.post(url).set('Cookie', this.cookie).set('User-Agent', UA).type(this.formType);
|
||||
if (this.fetchOptions.headers) req = req.set(this.fetchOptions.headers);
|
||||
if (this.fetchOptions.post?.headers) req = req.set(this.fetchOptions.post.headers);
|
||||
return this.account.proxy ? req.proxy(this.account.proxy) : req;
|
||||
}
|
||||
|
||||
setCookie(cookie: string | string[]) {
|
||||
setCookie(cookie: string | string[], save = false) {
|
||||
if (typeof cookie === 'string') this.cookie = [cookie];
|
||||
else this.cookie = cookie;
|
||||
if (save && 'save' in this && typeof this.save === 'function') return this.save({ cookie: this.cookie });
|
||||
return null;
|
||||
}
|
||||
|
||||
setEndpoint(endpoint: string) {
|
||||
|
||||
@@ -72,10 +72,7 @@ export default class CSGOJProvider extends BasicFetcher implements IBasicProvide
|
||||
if (await this.loggedIn) return true;
|
||||
logger.info('retry login');
|
||||
const { header } = await this.get('/csgoj/user/login_ajax');
|
||||
if (header['set-cookie']) {
|
||||
await this.save({ cookie: header['set-cookie'] });
|
||||
this.cookie = header['set-cookie'];
|
||||
}
|
||||
if (header['set-cookie']) await this.setCookie(header['set-cookie'], true);
|
||||
await this.post('/csgoj/user/login_ajax')
|
||||
.set('referer', 'https://cpc.csgrandeur.cn/')
|
||||
.send({
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import { PassThrough } from 'stream';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import { } from 'superagent';
|
||||
import charset from 'superagent-charset';
|
||||
import proxy from 'superagent-proxy';
|
||||
import {
|
||||
@@ -42,10 +41,7 @@ export default class HDUOJProvider extends BasicFetcher implements IBasicProvide
|
||||
|
||||
async getCsrfToken(url: string) {
|
||||
const { header } = await this.get(url);
|
||||
if (header['set-cookie']) {
|
||||
await this.save({ cookie: header['set-cookie'] });
|
||||
this.cookie = header['set-cookie'];
|
||||
}
|
||||
if (header['set-cookie']) await this.setCookie(header['set-cookie'], true);
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -69,7 +65,7 @@ export default class HDUOJProvider extends BasicFetcher implements IBasicProvide
|
||||
|
||||
async getProblem(id: string) {
|
||||
logger.info(id);
|
||||
const res = await superagent.get('/showproblem.php')
|
||||
const res = await this.get('/showproblem.php')
|
||||
.query({ pid: id.split('P')[1] })
|
||||
.buffer(true)
|
||||
.charset('gbk');
|
||||
@@ -197,7 +193,7 @@ export default class HDUOJProvider extends BasicFetcher implements IBasicProvide
|
||||
|| STATUS.STATUS_SYSTEM_ERROR;
|
||||
if (status === STATUS.STATUS_JUDGING) continue;
|
||||
if (status === STATUS.STATUS_COMPILE_ERROR) {
|
||||
const { text: info } = await superagent.get(`http://acm.hdu.edu.cn/viewerror.php?rid=${id}`)
|
||||
const { text: info } = await this.get(`http://acm.hdu.edu.cn/viewerror.php?rid=${id}`)
|
||||
.buffer(true)
|
||||
.charset('gbk');
|
||||
const ceInfo = new JSDOM(info);
|
||||
|
||||
@@ -145,7 +145,7 @@ export class HUSTOJ extends BasicFetcher implements IBasicProvider {
|
||||
});
|
||||
console.log(res.text);
|
||||
this.state.username = username;
|
||||
if (res.headers['set-cookie']) this.cookie = res.headers['set-cookie'];
|
||||
if (res.headers['set-cookie']) this.setCookie(res.headers['set-cookie']);
|
||||
this.save({ cookie: this.cookie });
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ export class YBTBAS extends YBT {
|
||||
this.config.login.check = '退出登录';
|
||||
this.config.login.extra = async () => {
|
||||
const captcha = await this.get('/login_xx.php').responseType('arraybuffer');
|
||||
if (captcha.headers['set-cookie']) this.cookie = captcha.headers['set-cookie'];
|
||||
if (captcha.headers['set-cookie']) this.setCookie(captcha.headers['set-cookie']);
|
||||
if (!global.parseCaptcha) await sleep(30000);
|
||||
if (!global.parseCaptcha) return { login: '登录' };
|
||||
return {
|
||||
|
||||
@@ -64,10 +64,7 @@ export default class POJProvider extends BasicFetcher implements IBasicProvider
|
||||
|
||||
async getCsrfToken(url: string) {
|
||||
const { header } = await this.get(url);
|
||||
if (header['set-cookie']) {
|
||||
await this.save({ cookie: header['set-cookie'] });
|
||||
this.cookie = header['set-cookie'];
|
||||
}
|
||||
if (header['set-cookie']) await this.setCookie(header['set-cookie']);
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
@@ -39,11 +39,7 @@ export default class SPOJProvider extends BasicFetcher implements IBasicProvider
|
||||
login_user: this.account.handle,
|
||||
password: this.account.password,
|
||||
});
|
||||
const cookie = res.header['set-cookie'];
|
||||
if (cookie) {
|
||||
await this.save({ cookie });
|
||||
this.cookie = cookie;
|
||||
}
|
||||
if (res.header['set-cookie']) await this.setCookie(res.header['set-cookie'], true);
|
||||
if (await this.loggedIn) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -31,10 +31,7 @@ export default class UOJProvider extends BasicFetcher implements IBasicProvider
|
||||
|
||||
async getCsrfToken(url: string) {
|
||||
const { text: html, header } = await this.get(url);
|
||||
if (header['set-cookie']) {
|
||||
await this.save({ cookie: header['set-cookie'] });
|
||||
this.cookie = header['set-cookie'];
|
||||
}
|
||||
if (header['set-cookie']) await this.setCookie(header['set-cookie'], true);
|
||||
let value = /_token *: *"(.+?)"/g.exec(html);
|
||||
if (value) return value[1];
|
||||
value = /_token" value="(.+?)"/g.exec(html);
|
||||
@@ -58,9 +55,10 @@ export default class UOJProvider extends BasicFetcher implements IBasicProvider
|
||||
password: this.account.password,
|
||||
});
|
||||
if (header['set-cookie'] && this.cookie.length === 1) {
|
||||
header['set-cookie'].push(...this.cookie);
|
||||
await this.save({ cookie: header['set-cookie'] });
|
||||
this.cookie = header['set-cookie'];
|
||||
const cookie = Array.isArray(header['set-cookie']) ? header['set-cookie'] : [header['set-cookie']];
|
||||
cookie.push(...this.cookie);
|
||||
await this.save({ cookie });
|
||||
this.cookie = cookie;
|
||||
}
|
||||
if (text === 'ok') return true;
|
||||
return text;
|
||||
|
||||
Reference in new issue
Block a user