From 246c7fb6159f1524d2ad938ed336a3567ece11ca Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 24 Jan 2023 16:04:02 +0800 Subject: [PATCH] chore(remote_judger): user-agent as constant --- remote_judger/src/interface.ts | 3 +++ remote_judger/src/providers/atcoder.ts | 12 +++--------- remote_judger/src/providers/codeforces.ts | 12 +++--------- remote_judger/src/providers/uoj.ts | 13 ++++++++++--- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/remote_judger/src/interface.ts b/remote_judger/src/interface.ts index 208573d..77af4c5 100644 --- a/remote_judger/src/interface.ts +++ b/remote_judger/src/interface.ts @@ -30,3 +30,6 @@ export interface IBasicProvider { export interface BasicProvider { 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'; diff --git a/remote_judger/src/providers/atcoder.ts b/remote_judger/src/providers/atcoder.ts index fd38931..97d05ad 100644 --- a/remote_judger/src/providers/atcoder.ts +++ b/remote_judger/src/providers/atcoder.ts @@ -2,7 +2,7 @@ import { JSDOM } from 'jsdom'; import superagent from 'superagent'; import proxy from 'superagent-proxy'; import sleep from '../utils/sleep'; -import { IBasicProvider, RemoteAccount } from '../interface'; +import { IBasicProvider, RemoteAccount, USER_AGENT } from '../interface'; import Logger from '../utils/logger'; proxy(superagent); @@ -84,10 +84,7 @@ export default class AtcoderProvider implements IBasicProvider { .redirects(0) .ok(res => res.status < 400) .set('Cookie', this.cookie) - .set( - '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' - ); + .set('User-Agent', USER_AGENT); if (this.account.proxy) return req.proxy(this.account.proxy); return req; } @@ -101,10 +98,7 @@ export default class AtcoderProvider implements IBasicProvider { .redirects(0) .ok(res => res.status < 400) .set('Cookie', this.cookie) - .set( - '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' - ); + .set('User-Agent', USER_AGENT); if (this.account.proxy) return req.proxy(this.account.proxy); return req; } diff --git a/remote_judger/src/providers/codeforces.ts b/remote_judger/src/providers/codeforces.ts index 3cec070..c50b4a6 100644 --- a/remote_judger/src/providers/codeforces.ts +++ b/remote_judger/src/providers/codeforces.ts @@ -3,7 +3,7 @@ import superagent from 'superagent'; import proxy from 'superagent-proxy'; import sleep from '../utils/sleep'; import mathSum from 'math-sum'; -import { IBasicProvider, RemoteAccount } from '../interface'; +import { IBasicProvider, RemoteAccount, USER_AGENT } from '../interface'; import { normalize, VERDICT } from '../verdict'; import Logger from '../utils/logger'; @@ -95,10 +95,7 @@ export default class CodeforcesProvider implements IBasicProvider { const req = superagent .get(url) .set('Cookie', this.cookie) - .set( - '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' - ); + .set('User-Agent', USER_AGENT); if (this.account.proxy) return req.proxy(this.account.proxy); return req; } @@ -110,10 +107,7 @@ export default class CodeforcesProvider implements IBasicProvider { .post(url) .type('form') .set('Cookie', this.cookie) - .set( - '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' - ); + .set('User-Agent', USER_AGENT); if (this.account.proxy) return req.proxy(this.account.proxy); return req; } diff --git a/remote_judger/src/providers/uoj.ts b/remote_judger/src/providers/uoj.ts index 673a439..9268df9 100644 --- a/remote_judger/src/providers/uoj.ts +++ b/remote_judger/src/providers/uoj.ts @@ -2,7 +2,7 @@ import { JSDOM } from 'jsdom'; import superagent from 'superagent'; import proxy from 'superagent-proxy'; import Logger from '../utils/logger'; -import { IBasicProvider, RemoteAccount } from '../interface'; +import { IBasicProvider, RemoteAccount, USER_AGENT } from '../interface'; import { parseTimeMS, parseMemoryMB } from '../utils/parse'; import sleep from '../utils/sleep'; @@ -106,7 +106,10 @@ export default class UOJProvider implements IBasicProvider { logger.debug('get', url); if (!url.includes('//')) 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); return req; } @@ -115,7 +118,11 @@ export default class UOJProvider implements IBasicProvider { logger.debug('post', url, this.cookie); if (!url.includes('//')) 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); return req; }