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
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user