judge: update files api endpoint

This commit is contained in:
undefined committed 2024-01-04 17:38:30 +08:00
1 parent 2de1151b24
commit 3ede50a237
3 files changed
+10 -13

No files matched your search

+1 -1
View File
@@ -125,7 +125,7 @@ export default class Hydro implements Session {
async fetchFile(name: string) { async fetchFile(name: string) {
name = name.split('#')[0]; 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 target = path.join(getConfig('tmp_dir'), name.replace(/\//g, '_'));
const w = fs.createWriteStream(target); const w = fs.createWriteStream(target);
this.get(res.body.url).pipe(w); this.get(res.body.url).pipe(w);
+8 -11
View File
@@ -153,9 +153,14 @@ export class JudgeFilesDownloadHandler extends Handler {
} }
noCheckPermView = true; noCheckPermView = true;
@post('files', Types.Set) @post('id', Types.String, true)
@post('pid', Types.UnsignedInt) @post('files', Types.Set, true)
async post(domainId: string, files: Set<string>, pid: number) { @post('pid', Types.UnsignedInt, true)
async post(domainId: string, id: string, files: Set<string>, pid: number) {
if (id) {
this.response.body = { url: await storage.signDownloadLink(`submission/${id}`, 'code', true, 'judge') };
return;
}
const pdoc = await problem.get(domainId, pid); const pdoc = await problem.get(domainId, pid);
if (!pdoc) this.response.body.links = null; if (!pdoc) this.response.body.links = null;
const links = {}; 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) { export async function processJudgeFileCallback(rid: ObjectId, filename: string, filePath: string) {
const rdoc = await record.get(rid); const rdoc = await record.get(rid);
const [pdoc, udoc] = await Promise.all([ const [pdoc, udoc] = await Promise.all([
@@ -301,7 +299,6 @@ class JudgeConnectionHandler extends ConnectionHandler {
export async function apply(ctx) { export async function apply(ctx) {
ctx.Route('judge_files_download', '/judge/files', JudgeFilesDownloadHandler, builtin.PRIV.PRIV_JUDGE); 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_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); ctx.Connection('judge_conn', '/judge/conn', JudgeConnectionHandler, builtin.PRIV.PRIV_JUDGE);
} }
+1 -1
View File
@@ -87,7 +87,7 @@ export interface KoaContext extends Koa.Context {
request: Koa.Request & { body: any, files: Files }; request: Koa.Request & { body: any, files: Files };
session: Record<string, any>; session: Record<string, any>;
render: (name: string, args: any) => Promise<void>; render: (name: string, args: any) => Promise<void>;
renderHTML: (name: string, args: any) => Promise<string>; renderHTML: (name: string, args: any) => string | Promise<string>;
getUrl: (name: string, args: any) => string; getUrl: (name: string, args: any) => string;
translate: (key: string) => string; translate: (key: string) => string;
} }