diff --git a/packages/hydrojudge/src/hosts/hydro.ts b/packages/hydrojudge/src/hosts/hydro.ts index 409b196fe..94a20ebb9 100644 --- a/packages/hydrojudge/src/hosts/hydro.ts +++ b/packages/hydrojudge/src/hosts/hydro.ts @@ -125,7 +125,7 @@ export default class Hydro implements Session { async fetchFile(name: string) { name = name.split('#')[0]; - const res = await this.post('judge/code', { id: name }); + const res = await this.post('judge/files', { id: name }); const target = path.join(getConfig('tmp_dir'), name.replace(/\//g, '_')); const w = fs.createWriteStream(target); this.get(res.body.url).pipe(w); diff --git a/packages/hydrooj/src/handler/judge.ts b/packages/hydrooj/src/handler/judge.ts index 1a4f45ed9..d4b79c3fc 100644 --- a/packages/hydrooj/src/handler/judge.ts +++ b/packages/hydrooj/src/handler/judge.ts @@ -153,9 +153,14 @@ export class JudgeFilesDownloadHandler extends Handler { } noCheckPermView = true; - @post('files', Types.Set) - @post('pid', Types.UnsignedInt) - async post(domainId: string, files: Set, pid: number) { + @post('id', Types.String, true) + @post('files', Types.Set, true) + @post('pid', Types.UnsignedInt, true) + async post(domainId: string, id: string, files: Set, pid: number) { + if (id) { + this.response.body = { url: await storage.signDownloadLink(`submission/${id}`, 'code', true, 'judge') }; + return; + } const pdoc = await problem.get(domainId, pid); if (!pdoc) this.response.body.links = null; const links = {}; @@ -170,13 +175,6 @@ export class JudgeFilesDownloadHandler extends Handler { } } -export class SubmissionDataDownloadHandler extends Handler { - @post('id', Types.String) - async post(domainId: string, id: string) { - this.response.body = { url: await storage.signDownloadLink(`submission/${id}`, 'code', true, 'judge') }; - } -} - export async function processJudgeFileCallback(rid: ObjectId, filename: string, filePath: string) { const rdoc = await record.get(rid); const [pdoc, udoc] = await Promise.all([ @@ -301,7 +299,6 @@ class JudgeConnectionHandler extends ConnectionHandler { export async function apply(ctx) { ctx.Route('judge_files_download', '/judge/files', JudgeFilesDownloadHandler, builtin.PRIV.PRIV_JUDGE); ctx.Route('judge_files_upload', '/judge/upload', JudgeFileUpdateHandler, builtin.PRIV.PRIV_JUDGE); - ctx.Route('judge_submission_download', '/judge/code', SubmissionDataDownloadHandler, builtin.PRIV.PRIV_JUDGE); ctx.Connection('judge_conn', '/judge/conn', JudgeConnectionHandler, builtin.PRIV.PRIV_JUDGE); } diff --git a/packages/hydrooj/src/service/server.ts b/packages/hydrooj/src/service/server.ts index eb0e660f2..efc8cc7e0 100644 --- a/packages/hydrooj/src/service/server.ts +++ b/packages/hydrooj/src/service/server.ts @@ -87,7 +87,7 @@ export interface KoaContext extends Koa.Context { request: Koa.Request & { body: any, files: Files }; session: Record; render: (name: string, args: any) => Promise; - renderHTML: (name: string, args: any) => Promise; + renderHTML: (name: string, args: any) => string | Promise; getUrl: (name: string, args: any) => string; translate: (key: string) => string; }