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",
|
"name": "@hydrooj/vjudge",
|
||||||
"version": "1.0.14",
|
"version": "1.0.15",
|
||||||
"description": "Submit problems to remote oj",
|
"description": "Submit problems to remote oj",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
@@ -10,9 +10,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hydrooj/utils": "workspace:*",
|
"@hydrooj/utils": "workspace:*",
|
||||||
"jsdom": "^16.6.0",
|
"jsdom": "^16.6.0",
|
||||||
"superagent": "^6.1.0"
|
"superagent": "^6.1.0",
|
||||||
|
"superagent-proxy": "^2.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"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;
|
handle: string;
|
||||||
password: string;
|
password: string;
|
||||||
endpoint?: string;
|
endpoint?: string;
|
||||||
|
proxy?: string;
|
||||||
}
|
}
|
||||||
declare module 'hydrooj/dist/interface' {
|
declare module 'hydrooj/dist/interface' {
|
||||||
interface Collections {
|
interface Collections {
|
||||||
|
|||||||
@@ -61,10 +61,20 @@ class Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async main() {
|
async login() {
|
||||||
const login = await this.api.ensureLogin();
|
const login = await this.api.ensureLogin();
|
||||||
if (login) logger.info(`${this.account.type}/${this.account.handle}: logged in`);
|
if (login) {
|
||||||
else return;
|
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));
|
TaskModel.consume({ type: 'remotejudge', subType: this.account.type }, this.judge.bind(this));
|
||||||
const ddocs = await DomainModel.getMulti({ mount: this.account.type }).toArray();
|
const ddocs = await DomainModel.getMulti({ mount: this.account.type }).toArray();
|
||||||
for (const ddoc of ddocs) {
|
for (const ddoc of ddocs) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/* eslint-disable no-await-in-loop */
|
/* 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 { JSDOM } from 'jsdom';
|
||||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
import { sleep } from '@hydrooj/utils/lib/utils';
|
import { sleep } from '@hydrooj/utils/lib/utils';
|
||||||
@@ -9,6 +10,7 @@ import { Logger } from 'hydrooj/dist/logger';
|
|||||||
import { PassThrough } from 'stream';
|
import { PassThrough } from 'stream';
|
||||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||||
|
|
||||||
|
proxy(superagent);
|
||||||
const logger = new Logger('codeforces');
|
const logger = new Logger('codeforces');
|
||||||
|
|
||||||
const VERDICT = {
|
const VERDICT = {
|
||||||
@@ -38,12 +40,18 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
|
|
||||||
get(url: string) {
|
get(url: string) {
|
||||||
logger.debug('get', url);
|
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) {
|
post(url: string) {
|
||||||
logger.debug('post', url, this.cookie);
|
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) {
|
tta(_39ce7: string) {
|
||||||
@@ -89,6 +97,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
password: this.account.password,
|
password: this.account.password,
|
||||||
remember: 'on',
|
remember: 'on',
|
||||||
});
|
});
|
||||||
|
console.log(res.header);
|
||||||
const cookie = res.header['set-cookie'];
|
const cookie = res.header['set-cookie'];
|
||||||
if (cookie) {
|
if (cookie) {
|
||||||
await this.save({ cookie });
|
await this.save({ cookie });
|
||||||
@@ -130,7 +139,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
const src = ele.getAttribute('src');
|
const src = ele.getAttribute('src');
|
||||||
if (!src.startsWith('http')) return;
|
if (!src.startsWith('http')) return;
|
||||||
const file = new PassThrough();
|
const file = new PassThrough();
|
||||||
superagent.get(src).pipe(file);
|
this.get(src).pipe(file);
|
||||||
const fid = String.random(8);
|
const fid = String.random(8);
|
||||||
files[`${fid}.png`] = file;
|
files[`${fid}.png`] = file;
|
||||||
ele.setAttribute('src', `file://${fid}.png`);
|
ele.setAttribute('src', `file://${fid}.png`);
|
||||||
|
|||||||
Reference in new issue
Block a user