mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-08 13:38:41 +00:00
chore(remote_judger): user-agent as constant
This commit is contained in:
parent
7bc11120b9
commit
246c7fb615
@ -30,3 +30,6 @@ export interface IBasicProvider {
|
|||||||
export interface BasicProvider {
|
export interface BasicProvider {
|
||||||
new (account: RemoteAccount): IBasicProvider;
|
new (account: RemoteAccount): IBasicProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const USER_AGENT =
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36 S2OJ/3.1.0';
|
||||||
|
@ -2,7 +2,7 @@ import { JSDOM } from 'jsdom';
|
|||||||
import superagent from 'superagent';
|
import superagent from 'superagent';
|
||||||
import proxy from 'superagent-proxy';
|
import proxy from 'superagent-proxy';
|
||||||
import sleep from '../utils/sleep';
|
import sleep from '../utils/sleep';
|
||||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
import { IBasicProvider, RemoteAccount, USER_AGENT } from '../interface';
|
||||||
import Logger from '../utils/logger';
|
import Logger from '../utils/logger';
|
||||||
|
|
||||||
proxy(superagent);
|
proxy(superagent);
|
||||||
@ -84,10 +84,7 @@ export default class AtcoderProvider implements IBasicProvider {
|
|||||||
.redirects(0)
|
.redirects(0)
|
||||||
.ok(res => res.status < 400)
|
.ok(res => res.status < 400)
|
||||||
.set('Cookie', this.cookie)
|
.set('Cookie', this.cookie)
|
||||||
.set(
|
.set('User-Agent', USER_AGENT);
|
||||||
'User-Agent',
|
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36 S2OJ/3.1.0'
|
|
||||||
);
|
|
||||||
if (this.account.proxy) return req.proxy(this.account.proxy);
|
if (this.account.proxy) return req.proxy(this.account.proxy);
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
@ -101,10 +98,7 @@ export default class AtcoderProvider implements IBasicProvider {
|
|||||||
.redirects(0)
|
.redirects(0)
|
||||||
.ok(res => res.status < 400)
|
.ok(res => res.status < 400)
|
||||||
.set('Cookie', this.cookie)
|
.set('Cookie', this.cookie)
|
||||||
.set(
|
.set('User-Agent', USER_AGENT);
|
||||||
'User-Agent',
|
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36 S2OJ/3.1.0'
|
|
||||||
);
|
|
||||||
if (this.account.proxy) return req.proxy(this.account.proxy);
|
if (this.account.proxy) return req.proxy(this.account.proxy);
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import superagent from 'superagent';
|
|||||||
import proxy from 'superagent-proxy';
|
import proxy from 'superagent-proxy';
|
||||||
import sleep from '../utils/sleep';
|
import sleep from '../utils/sleep';
|
||||||
import mathSum from 'math-sum';
|
import mathSum from 'math-sum';
|
||||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
import { IBasicProvider, RemoteAccount, USER_AGENT } from '../interface';
|
||||||
import { normalize, VERDICT } from '../verdict';
|
import { normalize, VERDICT } from '../verdict';
|
||||||
import Logger from '../utils/logger';
|
import Logger from '../utils/logger';
|
||||||
|
|
||||||
@ -95,10 +95,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
const req = superagent
|
const req = superagent
|
||||||
.get(url)
|
.get(url)
|
||||||
.set('Cookie', this.cookie)
|
.set('Cookie', this.cookie)
|
||||||
.set(
|
.set('User-Agent', USER_AGENT);
|
||||||
'User-Agent',
|
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36 S2OJ/3.1.0'
|
|
||||||
);
|
|
||||||
if (this.account.proxy) return req.proxy(this.account.proxy);
|
if (this.account.proxy) return req.proxy(this.account.proxy);
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
@ -110,10 +107,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
.post(url)
|
.post(url)
|
||||||
.type('form')
|
.type('form')
|
||||||
.set('Cookie', this.cookie)
|
.set('Cookie', this.cookie)
|
||||||
.set(
|
.set('User-Agent', USER_AGENT);
|
||||||
'User-Agent',
|
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36 S2OJ/3.1.0'
|
|
||||||
);
|
|
||||||
if (this.account.proxy) return req.proxy(this.account.proxy);
|
if (this.account.proxy) return req.proxy(this.account.proxy);
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { JSDOM } from 'jsdom';
|
|||||||
import superagent from 'superagent';
|
import superagent from 'superagent';
|
||||||
import proxy from 'superagent-proxy';
|
import proxy from 'superagent-proxy';
|
||||||
import Logger from '../utils/logger';
|
import Logger from '../utils/logger';
|
||||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
import { IBasicProvider, RemoteAccount, USER_AGENT } from '../interface';
|
||||||
import { parseTimeMS, parseMemoryMB } from '../utils/parse';
|
import { parseTimeMS, parseMemoryMB } from '../utils/parse';
|
||||||
import sleep from '../utils/sleep';
|
import sleep from '../utils/sleep';
|
||||||
|
|
||||||
@ -106,7 +106,10 @@ export default class UOJProvider implements IBasicProvider {
|
|||||||
logger.debug('get', url);
|
logger.debug('get', url);
|
||||||
if (!url.includes('//'))
|
if (!url.includes('//'))
|
||||||
url = `${this.account.endpoint || 'https://uoj.ac'}${url}`;
|
url = `${this.account.endpoint || 'https://uoj.ac'}${url}`;
|
||||||
const req = superagent.get(url).set('Cookie', this.cookie);
|
const req = superagent
|
||||||
|
.get(url)
|
||||||
|
.set('Cookie', this.cookie)
|
||||||
|
.set('User-Agent', USER_AGENT);
|
||||||
if (this.account.proxy) return req.proxy(this.account.proxy);
|
if (this.account.proxy) return req.proxy(this.account.proxy);
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
@ -115,7 +118,11 @@ export default class UOJProvider implements IBasicProvider {
|
|||||||
logger.debug('post', url, this.cookie);
|
logger.debug('post', url, this.cookie);
|
||||||
if (!url.includes('//'))
|
if (!url.includes('//'))
|
||||||
url = `${this.account.endpoint || 'https://uoj.ac'}${url}`;
|
url = `${this.account.endpoint || 'https://uoj.ac'}${url}`;
|
||||||
const req = superagent.post(url).set('Cookie', this.cookie).type('form');
|
const req = superagent
|
||||||
|
.post(url)
|
||||||
|
.set('Cookie', this.cookie)
|
||||||
|
.set('User-Agent', USER_AGENT)
|
||||||
|
.type('form');
|
||||||
if (this.account.proxy) return req.proxy(this.account.proxy);
|
if (this.account.proxy) return req.proxy(this.account.proxy);
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user