mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: change pdoc.content to plain text
This commit is contained in:
1 parent
ccef433c68
commit
653d18b57b
5 files changed
+17
-29
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.20.53",
|
||||
"version": "2.21.0",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -46,6 +46,7 @@ export async function load(call: Entry) {
|
||||
}
|
||||
bus.once('app/exit', () => {
|
||||
fs.removeSync(lockfile);
|
||||
fs.removeSync(path.resolve(os.tmpdir(), 'hydro', 'public'));
|
||||
});
|
||||
const opts = options();
|
||||
await db.start(opts);
|
||||
|
||||
@@ -21,7 +21,7 @@ import { PERM, PRIV } from '../model/builtin';
|
||||
import storage from '../service/storage';
|
||||
import * as bus from '../service/bus';
|
||||
import {
|
||||
Route, Connection, Handler, ConnectionHandler, Types, param, post, route, get,
|
||||
Route, Connection, Handler, ConnectionHandler, Types, param, post, route, query,
|
||||
} from '../service/server';
|
||||
|
||||
export const parseCategory = (value: string) => flatten(value.split('+').map((e) => e.split(','))).map((e) => e.trim());
|
||||
@@ -56,6 +56,7 @@ export class ProblemMainHandler extends ProblemHandler {
|
||||
@param('q', Types.String, true)
|
||||
async get(domainId: string, page = 1, q = '') {
|
||||
this.response.template = 'problem_main.html';
|
||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||
const query: FilterQuery<Pdoc> = {};
|
||||
let psdict = {};
|
||||
const path: PathComponent[] = [
|
||||
@@ -186,13 +187,8 @@ export class ProblemDetailHandler extends ProblemHandler {
|
||||
async get(..._args: any[]) {
|
||||
// Navigate to current additional file download
|
||||
// e.g.  will navigate to 
|
||||
if (typeof this.response.body.pdoc.content === 'string') {
|
||||
this.response.body.pdoc.content = this.response.body.pdoc.content
|
||||
.replace(/\(file:\/\//g, `(./${this.pdoc.docId}/file/`);
|
||||
} else {
|
||||
this.response.body.pdoc.content = JSON.parse(JSON.stringify(this.response.body.pdoc.content)
|
||||
.replace(/\(file:\/\//g, `(./${this.pdoc.docId}/file/`));
|
||||
}
|
||||
this.response.body.pdoc.content = this.response.body.pdoc.content
|
||||
.replace(/\(file:\/\//g, `(./${this.pdoc.docId}/file/`);
|
||||
}
|
||||
|
||||
@param('pid', Types.UnsignedInt)
|
||||
@@ -340,9 +336,6 @@ export class ProblemEditHandler extends ProblemManageHandler {
|
||||
domainId: string, pid: string | number, title: string, content: string,
|
||||
newPid: string = '', hidden = false, tag: string[] = [],
|
||||
) {
|
||||
try {
|
||||
content = JSON.parse(content);
|
||||
} catch { /* Ignore */ }
|
||||
if (newPid !== this.pdoc.pid && await problem.get(domainId, newPid)) throw new BadRequestError('new pid exists');
|
||||
const $update: Partial<Pdoc> = {
|
||||
title, content, pid: newPid, hidden, tag: tag ?? [],
|
||||
@@ -418,7 +411,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
||||
}
|
||||
|
||||
export class ProblemFileDownloadHandler extends ProblemDetailHandler {
|
||||
@get('type', Types.Range(['additional_file', 'testdata']), true)
|
||||
@query('type', Types.Range(['additional_file', 'testdata']), true)
|
||||
@param('filename', Types.String)
|
||||
@param('noDisposition', Types.Boolean)
|
||||
async get(domainId: string, type = 'additional_file', filename: string, noDisposition = false) {
|
||||
@@ -573,9 +566,6 @@ export class ProblemCreateHandler extends Handler {
|
||||
@post('hidden', Types.Boolean)
|
||||
@post('tag', Types.String, true, null, parseCategory)
|
||||
async post(domainId: string, title: string, content: string, pid: string, hidden = false, tag: string[] = []) {
|
||||
try {
|
||||
content = JSON.parse(content);
|
||||
} catch { /* Ignore */ }
|
||||
if (pid && await problem.get(domainId, pid)) throw new BadRequestError('invalid pid');
|
||||
const docId = await problem.add(domainId, pid, title, content, this.user._id, tag ?? [], hidden);
|
||||
this.response.body = { pid: pid || docId };
|
||||
|
||||
@@ -177,7 +177,7 @@ declare module './model/problem' {
|
||||
docId: number,
|
||||
pid: string,
|
||||
title: string,
|
||||
content: Content,
|
||||
content: string,
|
||||
nSubmit: number,
|
||||
nAccept: number,
|
||||
tag: string[],
|
||||
|
||||
@@ -253,18 +253,15 @@ const scripts: UpgradeScript[] = [
|
||||
});
|
||||
return true;
|
||||
},
|
||||
async function _16_18() {
|
||||
await iterateAllProblem(['title', 'pid'], async (pdoc) => {
|
||||
if (pdoc.domainId !== 'bzoj') return;
|
||||
if (pdoc.docId > 100000) return;
|
||||
console.log(pdoc.title, pdoc.docId, pdoc.pid);
|
||||
await problem.edit(pdoc.domainId, pdoc.docId, { docId: pdoc.docId + 100000 });
|
||||
});
|
||||
await iterateAllProblem(['pid', 'title'], async (pdoc) => {
|
||||
if (pdoc.domainId !== 'bzoj') return;
|
||||
console.log(pdoc.title, pdoc.docId, pdoc.pid);
|
||||
if (pdoc.pid.startsWith('P')) pdoc.pid = pdoc.pid.split('P')[1];
|
||||
await problem.edit(pdoc.domainId, pdoc.docId, { docId: +pdoc.pid });
|
||||
async function _16_17() {
|
||||
return true;
|
||||
},
|
||||
async function _17_18() {
|
||||
const _FRESH_INSTALL_IGNORE = 1;
|
||||
await iterateAllProblem(['content'], async (pdoc) => {
|
||||
if (typeof pdoc.content !== 'string') {
|
||||
await problem.edit(pdoc.domainId, pdoc.docId, { content: JSON.stringify(pdoc.content) });
|
||||
}
|
||||
});
|
||||
},
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user