vjudge: fix (#790)

This commit is contained in:
panda authored and GitHub committed 2024-04-22 17:30:20 +08:00
1 parent 59f859ef2b
commit f04b55d69b
3 files changed
+12 -4

No files matched your search

+5 -3
View File
@@ -12,10 +12,11 @@ interface FetchOptions {
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 {
cookie: string[] = [];
UA: string = defaultUA;
constructor(
public account: RemoteAccount, private defaultEndpoint: string,
@@ -23,12 +24,13 @@ export class BasicFetcher {
public fetchOptions: FetchOptions = {},
) {
if (account.cookie) this.cookie = account.cookie;
if (account.UA) this.UA = account.UA;
}
get(url: string) {
this.logger.debug('get', url);
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.get?.headers) req = req.set(this.fetchOptions.get.headers);
return this.account.proxy ? req.proxy(this.account.proxy) : req;
@@ -45,7 +47,7 @@ export class BasicFetcher {
post(url: string) {
this.logger.debug('post', url, this.cookie);
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.post?.headers) req = req.set(this.fetchOptions.post.headers);
return this.account.proxy ? req.proxy(this.account.proxy) : req;
+1
View File
@@ -12,6 +12,7 @@ export interface RemoteAccount {
frozen?: string;
problemLists?: string[];
enableOn?: string[];
UA?: string;
}
declare module 'hydrooj' {
interface Collections {
+6 -1
View File
@@ -278,7 +278,7 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
: `/problemset/submit/${contestId}/${problemId}`;
const [csrf, ftaa, bfaa] = await this.getCsrfToken(endpoint);
// 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,
action: 'submitSolutionFormSubmitted',
programTypeId,
@@ -298,6 +298,11 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
end({ status: STATUS.STATUS_SYSTEM_ERROR, message });
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'
? '/problemset/status?my=on'
: `/gym/${contestId}/my`);