core: 支持在题目中通过 file://name 索引至附加文件

This commit is contained in:
undefined committed 2021-01-08 13:03:35 +08:00
1 parent 99efc98d2d
commit 252a251ce4
7 files changed
+14 -34

No files matched your search

+1 -25
View File
@@ -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);
}
+2 -2
View File
@@ -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() { }
+8 -2
View File
@@ -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) {