mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
解离sandbox模块,完善迁移工具
This commit is contained in:
1 parent
42cbd020d5
commit
2d2b2930f0
6 files changed
+106
-77
No files matched your search
@@ -195,6 +195,25 @@ async function service() {
|
||||
}
|
||||
}
|
||||
|
||||
async function script() {
|
||||
for (const i of active) {
|
||||
if (i.script && !i.fail) {
|
||||
try {
|
||||
console.time(`Script init: ${i.id}`);
|
||||
const exports = {};
|
||||
const module = { exports }; // eslint-disable-line no-unused-vars
|
||||
eval(i.script);
|
||||
console.timeEnd(`Script init: ${i.id}`);
|
||||
} catch (e) {
|
||||
i.fail = true;
|
||||
fail.push(i.id);
|
||||
console.error(`Script Load Fail: ${i.id}`);
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function install() {
|
||||
const setup = require('./service/setup');
|
||||
await setup.setup();
|
||||
@@ -279,6 +298,7 @@ async function load() {
|
||||
for (const i in global.Hydro.service) {
|
||||
if (global.Hydro.service[i].postInit) await global.Hydro.service[i].postInit();
|
||||
}
|
||||
await script();
|
||||
await server.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ const db = require('../service/db.js');
|
||||
const coll = db.collection('discussion');
|
||||
const collReply = db.collection('discussion.reply');
|
||||
const collStatus = db.collection('discussion.status');
|
||||
const collNode = db.collection('discussion.node');
|
||||
|
||||
async function add(parentType, parentId, owner, title, content, ip = null, highlight = false) {
|
||||
const res = await coll.insertOne({
|
||||
@@ -132,6 +133,10 @@ function getStatus(did, uid) {
|
||||
return collStatus.findOne({ did, uid });
|
||||
}
|
||||
|
||||
function getNode(_id) {
|
||||
return collNode.findOne({ _id });
|
||||
}
|
||||
|
||||
async function getVnode(ddoc, handler) {
|
||||
if (ddoc.parentType === 'problem') {
|
||||
const pdoc = await problem.getById(ddoc.parentId);
|
||||
@@ -141,7 +146,11 @@ async function getVnode(ddoc, handler) {
|
||||
} if (ddoc.parentType === 'contest') {
|
||||
const tdoc = await contest.get(ddoc.parentId);
|
||||
return { ...tdoc, parentType: ddoc.parentType, parentId: ddoc.parentId };
|
||||
} return null;
|
||||
} if (ddoc.parentType === 'node') {
|
||||
const ndoc = await getNode(ddoc.parentId);
|
||||
return { ...ndoc, parentType: ddoc.parentType, parentId: ddoc.parentId };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function getListVnodes(ddocs, handler) {
|
||||
|
||||
Reference in new issue
Block a user