From 252a251ce47005d819d9766d787d2e89699b7fb3 Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 8 Jan 2021 13:03:35 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E6=94=AF=E6=8C=81=E5=9C=A8=E9=A2=98?= =?UTF-8?q?=E7=9B=AE=E4=B8=AD=E9=80=9A=E8=BF=87=20file://name=20=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E8=87=B3=E9=99=84=E5=8A=A0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hydrooj/locales/en.yaml | 1 - packages/hydrooj/locales/ko.yaml | 1 - packages/hydrooj/locales/zh.yaml | 2 +- packages/hydrooj/package.json | 4 ++-- packages/hydrooj/src/handler/home.ts | 26 +----------------------- packages/hydrooj/src/handler/notfound.ts | 4 ++-- packages/hydrooj/src/handler/problem.ts | 10 +++++++-- 7 files changed, 14 insertions(+), 34 deletions(-) diff --git a/packages/hydrooj/locales/en.yaml b/packages/hydrooj/locales/en.yaml index f7e3b6d7e..b28e8eed5 100644 --- a/packages/hydrooj/locales/en.yaml +++ b/packages/hydrooj/locales/en.yaml @@ -24,7 +24,6 @@ home_account: Account Settings home_domain_account: Profile @ Domain home_domain_create: Create Domain home_domain: My Domains -home_file: My Files home_messages: Messages home_preference: Preference home_security: Security diff --git a/packages/hydrooj/locales/ko.yaml b/packages/hydrooj/locales/ko.yaml index 81dbc211c..55f9e5910 100644 --- a/packages/hydrooj/locales/ko.yaml +++ b/packages/hydrooj/locales/ko.yaml @@ -325,7 +325,6 @@ home_account: 계정 home_domain_account: 그룹 계정 home_domain_create: 그룹 생성 home_domain: 그룹 -home_file: 파일 home_messages: 메시지 home_preference: 설정 home_security: 보안 diff --git a/packages/hydrooj/locales/zh.yaml b/packages/hydrooj/locales/zh.yaml index 1bdb2422c..0ddccd525 100644 --- a/packages/hydrooj/locales/zh.yaml +++ b/packages/hydrooj/locales/zh.yaml @@ -328,7 +328,6 @@ home_account: 账户设置 home_domain_account: 当前域的设置 home_domain_create: 创建域 home_domain: 我的域 -home_file: 我的文件 home_messages: 站内消息 home_preference: 偏好设置 home_security: 安全设置 @@ -530,6 +529,7 @@ Problem Tags Visibility: 题目标签可见性 problem_create: 创建题目 problem_detail: 题目详情 problem_edit: 编辑题目 +problem_files: 题目文件 problem_import: 导入题目 problem_main: 题库 problem_settings: 题目设置 diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 394ab5043..156365f54 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.15.11", + "version": "2.15.12", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", @@ -24,7 +24,7 @@ "koa-static-cache": "^5.1.3", "lodash": "^4.17.20", "lru-cache": "^6.0.0", - "minio": "7.0.18", + "minio": "7.0.17", "moment-timezone": "^0.5.32", "mongodb": "^3.6.3", "nodemailer": "^6.4.17", diff --git a/packages/hydrooj/src/handler/home.ts b/packages/hydrooj/src/handler/home.ts index fffe63574..5118b24c7 100644 --- a/packages/hydrooj/src/handler/home.ts +++ b/packages/hydrooj/src/handler/home.ts @@ -7,7 +7,6 @@ import * as bus from '../service/bus'; import { Route, Connection, Handler, ConnectionHandler, param, Types, } from '../service/server'; -import storage from '../service/storage'; import * as misc from '../lib/misc'; import { md5 } from '../lib/crypto'; import * as mail from '../lib/mail'; @@ -210,7 +209,7 @@ class HomeSettingsHandler extends Handler { this.response.body.settings = setting.ACCOUNT_SETTINGS; } else if (category === 'domain') { this.response.body.settings = setting.DOMAIN_USER_SETTINGS; - } else throw new NotFoundError(); + } else throw new NotFoundError(category); } async post(args: any) { @@ -378,28 +377,6 @@ class HomeMessagesConnectionHandler extends ConnectionHandler { } } -class HomeFileHandler extends Handler { - async get() { - const path = [ - ['Hydro', 'homepage'], - ['domain_file', null], - ]; - const ufdocs = await storage.list(`user/${this.user._id}/`); - this.response.template = 'home_file.html'; - this.response.body = { ufdocs, path }; - } - - @param('ufid', Types.String) - async postDelete(domainId: string, target: string) { - if (!target.startsWith(`user/${this.user._id}`)) this.checkPriv(PRIV.PRIV_DELETE_FILE); - else this.checkPriv(PRIV.PRIV_DELETE_FILE_SELF); - const { size } = await storage.getMeta(target); - await storage.del(target); - await user.inc(this.user._id, 'usage', -size); - this.back(); - } -} - async function apply() { Route('homepage', '/', HomeHandler); Route('home_security', '/home/security', HomeSecurityHandler, PRIV.PRIV_USER_PROFILE); @@ -408,7 +385,6 @@ async function apply() { Route('home_domain', '/home/domain', HomeDomainHandler, PRIV.PRIV_USER_PROFILE); Route('home_domain_create', '/home/domain/create', HomeDomainCreateHandler, PRIV.PRIV_CREATE_DOMAIN); Route('home_messages', '/home/messages', HomeMessagesHandler, PRIV.PRIV_USER_PROFILE); - Route('home_file', '/home/file', HomeFileHandler, PRIV.PRIV_USER_PROFILE); Connection('home_messages_conn', '/home/messages-conn', HomeMessagesConnectionHandler, PRIV.PRIV_USER_PROFILE); } diff --git a/packages/hydrooj/src/handler/notfound.ts b/packages/hydrooj/src/handler/notfound.ts index d9e74adad..83255b5be 100644 --- a/packages/hydrooj/src/handler/notfound.ts +++ b/packages/hydrooj/src/handler/notfound.ts @@ -4,8 +4,8 @@ import { NotFoundError } from '../error'; import { Route, Handler } from '../service/server'; class NotFoundHandler extends Handler { - async prepare() { - throw new NotFoundError(); + prepare() { + throw new NotFoundError(this.request.path); } all() { } diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 4e2849bd3..959f5bd3b 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -190,7 +190,13 @@ export class ProblemDetailHandler extends ProblemHandler { }; } - async get(...args: any[]) { } // eslint-disable-line + // eslint-disable-next-line @typescript-eslint/no-unused-vars + async get(..._args: any[]) { + // Navigate to current additional file download + // e.g. ![img](a.jpg) will navigate to ![img](./pid/file/a.jpg) + this.response.body.pdoc.content = this.response.body.pdoc.content + .replace(/\(file:\/\//g, `(./${this.pdoc.docId}/file/`); + } @param('pid', Types.UnsignedInt) async postRejudge(domainId: string, pid: number) { @@ -207,7 +213,7 @@ 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_SELF)) - || this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA_SELF); + || 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) {