mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: 优化ProblemFiles.postGetLinks
This commit is contained in:
1 parent
3a3983d38d
commit
c05149f0f9
3 files changed
+3
-26
No files matched your search
@@ -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",
|
||||
|
||||
@@ -26,11 +26,8 @@ export const typeMapper = {
|
||||
|
||||
class DiscussionHandler extends Handler {
|
||||
ddoc?: Ddoc;
|
||||
|
||||
drdoc?: Drdoc;
|
||||
|
||||
drrdoc?: Drrdoc;
|
||||
|
||||
vnode?: any;
|
||||
|
||||
@param('type', Types.String, true)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user