mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
markdown preview
This commit is contained in:
1 parent
86f67a0ec3
commit
5ca424da0b
15 files changed
+123
-104
No files matched your search
@@ -48,6 +48,7 @@ class DomainCreateHandler extends Handler {
|
||||
async post({ id, name }) {
|
||||
await domain.add(id, this.user._id, name);
|
||||
this.response.body = { domainId: id };
|
||||
this.response.redirect = this.url('homepage', { domainId: id });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
const { PERM_JUDGE, PERM_LOGGEDIN } = require('../permission');
|
||||
const file = require('../model/file');
|
||||
const user = require('../model/user');
|
||||
const markdown = require('../lib/markdown');
|
||||
const db = require('../service/db');
|
||||
const { Route, Handler } = require('../service/server');
|
||||
|
||||
@@ -54,12 +55,21 @@ class SwitchLanguageHandler extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
class MarkdownHandler extends Handler {
|
||||
async post({ text, safe = true }) {
|
||||
this.response.body = safe
|
||||
? markdown.safe.render(text)
|
||||
: markdown.unsafe.render(text);
|
||||
}
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
Route('file_download', '/fs/:id/:secret', FileDownloadHandler);
|
||||
Route('file_download_with_name', '/fs/:id/:name/:secret', FileDownloadHandler);
|
||||
Route('status', '/status', StatusHandler);
|
||||
Route('status_update', '/status/update', StatusUpdateHandler);
|
||||
Route('switch_language', '/language/:lang', SwitchLanguageHandler);
|
||||
Route('markdown', '/markdown', MarkdownHandler);
|
||||
}
|
||||
|
||||
apply.updateStatus = function updateStatus(args) {
|
||||
|
||||
+10
-2
@@ -14,7 +14,7 @@ const RecordHandler = contest.ContestHandlerMixin(Handler);
|
||||
|
||||
class RecordListHandler extends RecordHandler {
|
||||
async get({
|
||||
domainId, page = 1, tid, uidOrName,
|
||||
domainId, page = 1, pid, tid, uidOrName,
|
||||
}) {
|
||||
this.response.template = 'record_main.html';
|
||||
const q = { tid };
|
||||
@@ -24,6 +24,7 @@ class RecordListHandler extends RecordHandler {
|
||||
{ _id: parseInt(uidOrName) },
|
||||
];
|
||||
}
|
||||
if (pid) q.pid = pid;
|
||||
const rdocs = await record.getMany(domainId, q, { _id: -1 }, page, await system.get('RECORD_PER_PAGE'));
|
||||
const [udict, pdict] = await Promise.all([
|
||||
user.getList(domainId, rdocs.map((rdoc) => rdoc.uid)),
|
||||
@@ -34,7 +35,14 @@ class RecordListHandler extends RecordHandler {
|
||||
['record_main', null],
|
||||
];
|
||||
this.response.body = {
|
||||
path, page, rdocs, pdict, udict,
|
||||
path,
|
||||
page,
|
||||
rdocs,
|
||||
pdict,
|
||||
udict,
|
||||
fliterPid: pid,
|
||||
fliterTid: tid,
|
||||
fliterUidOrName: uidOrName,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,16 @@ async function _parseDagJson(domainId, dag) {
|
||||
for (const nid of node.requireNids) {
|
||||
assert(ids.has(nid), `required nid ${nid} not found`);
|
||||
}
|
||||
const tasks = [];
|
||||
for (const i in node.pids) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const pdoc = await problem.get(domainId, node.pids[i]); // FIXME no-await-in-loop
|
||||
assert(pdoc, `Problem not found: ${node.pids[i]}`);
|
||||
node.pids[i] = pdoc.docId;
|
||||
tasks.push(problem.get(domainId, node.pids[i]).then((pdoc) => {
|
||||
if (!pdoc) throw new ProblemNotFoundError(domainId, node.pids[i]);
|
||||
node.pids[i] = pdoc.docId;
|
||||
}));
|
||||
}
|
||||
// FIXME no-await-in-loop
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Promise.all(tasks);
|
||||
const newNode = {
|
||||
_id: parseInt(node._id),
|
||||
title: node.title,
|
||||
|
||||
@@ -2,7 +2,7 @@ const { Route, Handler } = require('../service/server');
|
||||
const { NotFoundError } = require('../error');
|
||||
|
||||
class WikiHandler extends Handler {
|
||||
async get({ name: page }) {
|
||||
async get({ page }) {
|
||||
if (!global.Hydro.wiki[page]) throw new NotFoundError(page);
|
||||
const contents = global.Hydro.wiki[page];
|
||||
const path = [
|
||||
|
||||
Reference in new issue
Block a user