mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
vjudge: fix (#790)
This commit is contained in:
1 parent
59f859ef2b
commit
f04b55d69b
3 files changed
+12
-4
No files matched your search
@@ -12,10 +12,11 @@ interface FetchOptions {
|
|||||||
get?: Omit<FetchOptions, 'get' | 'post'>
|
get?: Omit<FetchOptions, 'get' | 'post'>
|
||||||
}
|
}
|
||||||
|
|
||||||
const UA = `Hydro/${global.Hydro.version.hydrooj} VJudge/${global.Hydro.version.vjudge}`;
|
const defaultUA = `Hydro/${global.Hydro.version.hydrooj} VJudge/${global.Hydro.version.vjudge}`;
|
||||||
|
|
||||||
export class BasicFetcher {
|
export class BasicFetcher {
|
||||||
cookie: string[] = [];
|
cookie: string[] = [];
|
||||||
|
UA: string = defaultUA;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public account: RemoteAccount, private defaultEndpoint: string,
|
public account: RemoteAccount, private defaultEndpoint: string,
|
||||||
@@ -23,12 +24,13 @@ export class BasicFetcher {
|
|||||||
public fetchOptions: FetchOptions = {},
|
public fetchOptions: FetchOptions = {},
|
||||||
) {
|
) {
|
||||||
if (account.cookie) this.cookie = account.cookie;
|
if (account.cookie) this.cookie = account.cookie;
|
||||||
|
if (account.UA) this.UA = account.UA;
|
||||||
}
|
}
|
||||||
|
|
||||||
get(url: string) {
|
get(url: string) {
|
||||||
this.logger.debug('get', url);
|
this.logger.debug('get', url);
|
||||||
url = new URL(url, this.account.endpoint || this.defaultEndpoint).toString();
|
url = new URL(url, this.account.endpoint || this.defaultEndpoint).toString();
|
||||||
let req = superagent.get(url).set('Cookie', this.cookie).set('User-Agent', UA);
|
let req = superagent.get(url).set('Cookie', this.cookie).set('User-Agent', this.UA);
|
||||||
if (this.fetchOptions.headers) req = req.set(this.fetchOptions.headers);
|
if (this.fetchOptions.headers) req = req.set(this.fetchOptions.headers);
|
||||||
if (this.fetchOptions.get?.headers) req = req.set(this.fetchOptions.get.headers);
|
if (this.fetchOptions.get?.headers) req = req.set(this.fetchOptions.get.headers);
|
||||||
return this.account.proxy ? req.proxy(this.account.proxy) : req;
|
return this.account.proxy ? req.proxy(this.account.proxy) : req;
|
||||||
@@ -45,7 +47,7 @@ export class BasicFetcher {
|
|||||||
post(url: string) {
|
post(url: string) {
|
||||||
this.logger.debug('post', url, this.cookie);
|
this.logger.debug('post', url, this.cookie);
|
||||||
url = new URL(url, this.account.endpoint || this.defaultEndpoint).toString();
|
url = new URL(url, this.account.endpoint || this.defaultEndpoint).toString();
|
||||||
let req = superagent.post(url).set('Cookie', this.cookie).set('User-Agent', UA).type(this.formType);
|
let req = superagent.post(url).set('Cookie', this.cookie).set('User-Agent', this.UA).type(this.formType);
|
||||||
if (this.fetchOptions.headers) req = req.set(this.fetchOptions.headers);
|
if (this.fetchOptions.headers) req = req.set(this.fetchOptions.headers);
|
||||||
if (this.fetchOptions.post?.headers) req = req.set(this.fetchOptions.post.headers);
|
if (this.fetchOptions.post?.headers) req = req.set(this.fetchOptions.post.headers);
|
||||||
return this.account.proxy ? req.proxy(this.account.proxy) : req;
|
return this.account.proxy ? req.proxy(this.account.proxy) : req;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export interface RemoteAccount {
|
|||||||
frozen?: string;
|
frozen?: string;
|
||||||
problemLists?: string[];
|
problemLists?: string[];
|
||||||
enableOn?: string[];
|
enableOn?: string[];
|
||||||
|
UA?: string;
|
||||||
}
|
}
|
||||||
declare module 'hydrooj' {
|
declare module 'hydrooj' {
|
||||||
interface Collections {
|
interface Collections {
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
|
|||||||
: `/problemset/submit/${contestId}/${problemId}`;
|
: `/problemset/submit/${contestId}/${problemId}`;
|
||||||
const [csrf, ftaa, bfaa] = await this.getCsrfToken(endpoint);
|
const [csrf, ftaa, bfaa] = await this.getCsrfToken(endpoint);
|
||||||
// TODO check submit time to ensure submission
|
// TODO check submit time to ensure submission
|
||||||
const { text: submit } = await this.post(`${endpoint}?csrf_token=${csrf}`).send({
|
const { text: submit, redirects } = await this.post(`${endpoint}?csrf_token=${csrf}`).send({
|
||||||
csrf_token: csrf,
|
csrf_token: csrf,
|
||||||
action: 'submitSolutionFormSubmitted',
|
action: 'submitSolutionFormSubmitted',
|
||||||
programTypeId,
|
programTypeId,
|
||||||
@@ -298,6 +298,11 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
|
|||||||
end({ status: STATUS.STATUS_SYSTEM_ERROR, message });
|
end({ status: STATUS.STATUS_SYSTEM_ERROR, message });
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (redirects.length === 0 || !redirects.toString().includes('my')) {
|
||||||
|
// Submit failed so the request is not redirected
|
||||||
|
end({ status: STATUS.STATUS_SYSTEM_ERROR, message: 'Submit failed' });
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const { document } = await this.html(type !== 'GYM'
|
const { document } = await this.html(type !== 'GYM'
|
||||||
? '/problemset/status?my=on'
|
? '/problemset/status?my=on'
|
||||||
: `/gym/${contestId}/my`);
|
: `/gym/${contestId}/my`);
|
||||||
|
|||||||
Reference in new issue
Block a user