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