mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
vjudge: allow proxy
This commit is contained in:
1 parent
3f1037bb65
commit
62cc229724
4 files changed
+32
-10
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/vjudge",
|
||||
"version": "1.0.14",
|
||||
"version": "1.0.15",
|
||||
"description": "Submit problems to remote oj",
|
||||
"main": "package.json",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
@@ -10,9 +10,11 @@
|
||||
"dependencies": {
|
||||
"@hydrooj/utils": "workspace:*",
|
||||
"jsdom": "^16.6.0",
|
||||
"superagent": "^6.1.0"
|
||||
"superagent": "^6.1.0",
|
||||
"superagent-proxy": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jsdom": "^16.2.11"
|
||||
"@types/jsdom": "^16.2.11",
|
||||
"@types/superagent-proxy": "^2.0.0"
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ export interface RemoteAccount {
|
||||
handle: string;
|
||||
password: string;
|
||||
endpoint?: string;
|
||||
proxy?: string;
|
||||
}
|
||||
declare module 'hydrooj/dist/interface' {
|
||||
interface Collections {
|
||||
|
||||
@@ -61,10 +61,20 @@ class Service {
|
||||
}
|
||||
}
|
||||
|
||||
async main() {
|
||||
async login() {
|
||||
const login = await this.api.ensureLogin();
|
||||
if (login) logger.info(`${this.account.type}/${this.account.handle}: logged in`);
|
||||
else return;
|
||||
if (login) {
|
||||
logger.info(`${this.account.type}/${this.account.handle}: logged in`);
|
||||
return true;
|
||||
}
|
||||
logger.warn(`${this.account.type}/${this.account.handle}: login fail`);
|
||||
return false;
|
||||
}
|
||||
|
||||
async main() {
|
||||
const res = await this.login();
|
||||
if (!res) return;
|
||||
setInterval(() => this.login(), 1 * 3600 * 1000);
|
||||
TaskModel.consume({ type: 'remotejudge', subType: this.account.type }, this.judge.bind(this));
|
||||
const ddocs = await DomainModel.getMulti({ mount: this.account.type }).toArray();
|
||||
for (const ddoc of ddocs) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import superagent from 'superagent';
|
||||
import * as superagent from 'superagent';
|
||||
import proxy from 'superagent-proxy';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||
import { sleep } from '@hydrooj/utils/lib/utils';
|
||||
@@ -9,6 +10,7 @@ import { Logger } from 'hydrooj/dist/logger';
|
||||
import { PassThrough } from 'stream';
|
||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||
|
||||
proxy(superagent);
|
||||
const logger = new Logger('codeforces');
|
||||
|
||||
const VERDICT = {
|
||||
@@ -38,12 +40,18 @@ export default class CodeforcesProvider implements IBasicProvider {
|
||||
|
||||
get(url: string) {
|
||||
logger.debug('get', url);
|
||||
return superagent.get(`${this.account.endpoint || 'https://codeforces.com'}${url}`).set('Cookie', this.cookie);
|
||||
if (!url.includes('//')) url = `${this.account.endpoint || 'https://codeforces.com'}${url}`;
|
||||
const req = superagent.get(url).set('Cookie', this.cookie);
|
||||
if (this.account.proxy) return req.proxy(this.account.proxy);
|
||||
return req;
|
||||
}
|
||||
|
||||
post(url: string) {
|
||||
logger.debug('post', url, this.cookie);
|
||||
return superagent.post(`${this.account.endpoint || 'https://codeforces.com'}${url}`).type('form').set('Cookie', this.cookie);
|
||||
if (!url.includes('//')) url = `${this.account.endpoint || 'https://codeforces.com'}${url}`;
|
||||
const req = superagent.post(url).type('form').set('Cookie', this.cookie);
|
||||
if (this.account.proxy) return req.proxy(this.account.proxy);
|
||||
return req;
|
||||
}
|
||||
|
||||
tta(_39ce7: string) {
|
||||
@@ -89,6 +97,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
||||
password: this.account.password,
|
||||
remember: 'on',
|
||||
});
|
||||
console.log(res.header);
|
||||
const cookie = res.header['set-cookie'];
|
||||
if (cookie) {
|
||||
await this.save({ cookie });
|
||||
@@ -130,7 +139,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
||||
const src = ele.getAttribute('src');
|
||||
if (!src.startsWith('http')) return;
|
||||
const file = new PassThrough();
|
||||
superagent.get(src).pipe(file);
|
||||
this.get(src).pipe(file);
|
||||
const fid = String.random(8);
|
||||
files[`${fid}.png`] = file;
|
||||
ele.setAttribute('src', `file://${fid}.png`);
|
||||
|
||||
Reference in new issue
Block a user