From c05149f0f944dc073da549ece285d671fb4d7e09 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 1 Feb 2021 23:26:53 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E4=BC=98=E5=8C=96ProblemFiles.postGetL?= =?UTF-8?q?inks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/handler/discussion.ts | 3 --- packages/hydrooj/src/handler/problem.ts | 24 ++-------------------- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 38d7b95a6..b0f9a5b1d 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.17.7", + "version": "2.17.8", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/handler/discussion.ts b/packages/hydrooj/src/handler/discussion.ts index aed356bc0..7229d7ea5 100644 --- a/packages/hydrooj/src/handler/discussion.ts +++ b/packages/hydrooj/src/handler/discussion.ts @@ -26,11 +26,8 @@ export const typeMapper = { class DiscussionHandler extends Handler { ddoc?: Ddoc; - drdoc?: Drdoc; - drrdoc?: Drrdoc; - vnode?: any; @param('type', Types.String, true) diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 43d5086b9..d4d27ddb7 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -1,4 +1,4 @@ -import { isSafeInteger, flatten, pick } from 'lodash'; +import { isSafeInteger, flatten } from 'lodash'; import yaml from 'js-yaml'; import fs from 'fs-extra'; import { FilterQuery, ObjectID } from 'mongodb'; @@ -8,7 +8,6 @@ import { NoProblemError, BadRequestError, PermissionError, SolutionNotFoundError, ProblemNotFoundError, ValidationError, } from '../error'; -import { streamToBuffer } from '../utils'; import { Pdoc, User, Rdoc, PathComponent, } from '../interface'; @@ -219,24 +218,6 @@ export class ProblemDetailHandler extends ProblemHandler { } } -export class ProblemExportHandler extends ProblemDetailHandler { - async get() { - const hasPerm = this.user._id === this.pdoc.owner || this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA); - const pdoc = pick(this.pdoc, ['pid', 'acMsg', 'content', 'config', 'title', 'html', 'tag', 'category']); - const zip = new AdmZip(); - if (hasPerm) { - const files = await storage.list(`problem/${this.domainId}/${this.pdoc.docId}/`); - for (const file of files) { - // eslint-disable-next-line no-await-in-loop - const buf = await streamToBuffer(await storage.get(`${file.prefix}${file.name}`)); - zip.addFile(file.name, buf); - } - } - zip.addFile('problem.json', Buffer.from(JSON.stringify(pdoc))); - this.response.attachment(`${this.pdoc.title}.zip`, zip.toBuffer()); - } -} - export class ProblemSubmitHandler extends ProblemDetailHandler { @param('pid', Types.String, null, parsePid) async get(domainId: string, pid: string | number) { @@ -448,7 +429,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler { file, false, isJudge ? 'judge' : 'user', ); } - this.response.body.links = links; + this.response.body = { links }; } @post('filename', Types.String) @@ -710,7 +691,6 @@ export async function apply() { Route('problem_category', '/p/category/:category', ProblemCategoryHandler, PERM.PERM_VIEW_PROBLEM); Route('problem_random', '/problem/random', ProblemRandomHandler, PERM.PERM_VIEW_PROBLEM); Route('problem_detail', '/p/:pid', ProblemDetailHandler, PERM.PERM_VIEW_PROBLEM); - Route('problem_export', '/p/:pid/export', ProblemExportHandler, PERM.PERM_VIEW_PROBLEM); Route('problem_submit', '/p/:pid/submit', ProblemSubmitHandler, PERM.PERM_SUBMIT_PROBLEM); Route('problem_pretest', '/p/:pid/pretest', ProblemPretestHandler, PERM.PERM_SUBMIT_PROBLEM); Route('problem_settings', '/p/:pid/settings', ProblemSettingsHandler);