mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
优化安装流程
This commit is contained in:
1 parent
63d55cedf4
commit
508f5644c3
30 files changed
+279
-139
No files matched your search
@@ -242,7 +242,7 @@ async function edit(domainId, tid, $set, type = document.TYPE_CONTEST) {
|
||||
* @param {string} domainId
|
||||
* @param {ObjectID} tid
|
||||
* @param {number} type
|
||||
* @returns {Tdoc}
|
||||
* @returns {Promise<Tdoc>}
|
||||
*/
|
||||
async function get(domainId, tid, type = document.TYPE_CONTEST) {
|
||||
let tdoc;
|
||||
|
||||
@@ -2,9 +2,18 @@ const { ObjectID } = require('bson');
|
||||
const problem = require('./problem');
|
||||
const document = require('./document');
|
||||
const contest = require('./contest');
|
||||
const training = require('./training');
|
||||
const { PERM_VIEW_PROBLEM_HIDDEN } = require('../permission');
|
||||
const { DocumentNotFoundError } = require('../error');
|
||||
|
||||
const typeDisplay = {
|
||||
[document.TYPE_PROBLEM]: 'problem',
|
||||
[document.TYPE_CONTEST]: 'contest',
|
||||
[document.TYPE_DISCUSSION_NODE]: 'node',
|
||||
[document.TYPE_TRAINING]: 'training',
|
||||
[document.TYPE_HOMEWORK]: 'homework',
|
||||
};
|
||||
|
||||
function add(domainId, parentType, parentId, owner, title, content, ip = null, highlight = false) {
|
||||
return document.add(
|
||||
domainId, content, owner, document.TYPE_DISCUSSION,
|
||||
@@ -115,9 +124,7 @@ function getStatus(domainId, did, uid) {
|
||||
}
|
||||
|
||||
function addNode(domainId, _id, category) {
|
||||
return document.add(
|
||||
domainId, _id, 1, document.TYPE_DISCUSSION_NODE, null, null, null, { category },
|
||||
);
|
||||
return document.add(domainId, category, 1, document.TYPE_DISCUSSION_NODE, _id);
|
||||
}
|
||||
|
||||
function getNode(domainId, _id) {
|
||||
@@ -125,17 +132,32 @@ function getNode(domainId, _id) {
|
||||
}
|
||||
|
||||
async function getVnode(domainId, ddoc, handler) {
|
||||
if (ddoc.parentType === 'problem') {
|
||||
if (ddoc.parentType === document.TYPE_PROBLEM) {
|
||||
const pdoc = await problem.getById(domainId, ddoc.parentId);
|
||||
if (!pdoc) return null;
|
||||
if (pdoc.hidden && handler) handler.checkPerm(PERM_VIEW_PROBLEM_HIDDEN);
|
||||
return { ...pdoc, type: ddoc.parentType, id: ddoc.parentId };
|
||||
} if (ddoc.parentType === 'contest') {
|
||||
}
|
||||
if (ddoc.parentType === document.TYPE_CONTEST) {
|
||||
const tdoc = await contest.get(domainId, ddoc.parentId);
|
||||
return { ...tdoc, type: ddoc.parentType, id: ddoc.parentId };
|
||||
} if (ddoc.parentType === 'node') {
|
||||
}
|
||||
if (ddoc.parentType === document.TYPE_DISCUSSION_NODE) {
|
||||
const ndoc = await getNode(domainId, ddoc.parentId);
|
||||
return { title: ndoc._id, type: ddoc.parentType, id: ddoc.parentId };
|
||||
return {
|
||||
...ndoc,
|
||||
title: ddoc.parentId,
|
||||
type: ddoc.parentType,
|
||||
id: ddoc.parentId,
|
||||
};
|
||||
}
|
||||
if (ddoc.parentType === document.TYPE_TRAINING) {
|
||||
const tdoc = await training.get(domainId, ddoc.parentId);
|
||||
return { ...tdoc, type: ddoc.parentType, id: ddoc.parentId };
|
||||
}
|
||||
if (ddoc.parentType === document.TYPE_HOMEWORK) {
|
||||
const tdoc = await contest.get(domainId, ddoc.parentId, document.TYPE_HOMEWORK);
|
||||
return { ...tdoc, type: ddoc.parentType, id: ddoc.parentId };
|
||||
}
|
||||
return {
|
||||
title: 'Missing Node',
|
||||
@@ -147,13 +169,15 @@ async function getVnode(domainId, ddoc, handler) {
|
||||
async function getListVnodes(domainId, ddocs, handler) {
|
||||
const res = {};
|
||||
for (const ddoc of ddocs) {
|
||||
if (!res[ddoc.parentType]) res[ddoc.parentType] = {};
|
||||
// FIXME no-await-in-loop
|
||||
res[ddoc._id] = await getVnode(domainId, ddoc, handler); // eslint-disable-line no-await-in-loop
|
||||
res[ddoc.parentType][ddoc.parentId] = await getVnode(domainId, ddoc, handler); // eslint-disable-line no-await-in-loop
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
global.Hydro.model.discussion = module.exports = {
|
||||
typeDisplay,
|
||||
add,
|
||||
get,
|
||||
edit,
|
||||
|
||||
+6
-2
@@ -30,8 +30,12 @@ function del(_id) {
|
||||
}
|
||||
|
||||
async function inc(_id) {
|
||||
const file = await coll.findOne({ _id });
|
||||
file.count++;
|
||||
const doc = await coll.findOneAndUpdate(
|
||||
{ _id },
|
||||
{ $inc: { count: 1 } },
|
||||
{ returnOriginal: false },
|
||||
);
|
||||
return (doc.value || {}).count;
|
||||
}
|
||||
|
||||
async function dec(_id) {
|
||||
|
||||
@@ -14,5 +14,6 @@ module.exports = {
|
||||
task: require('./task'),
|
||||
message: require('./message'),
|
||||
setting: require('./setting'),
|
||||
discussion: require('./discussion'),
|
||||
file: require('./file'),
|
||||
};
|
||||
@@ -45,7 +45,7 @@ async function get(domainId, pid, uid = null) {
|
||||
const pdoc = Number.isInteger(pid)
|
||||
? await document.get(domainId, document.TYPE_PROBLEM, pid)
|
||||
: (await document.getMulti(domainId, document.TYPE_PROBLEM, { pid }).toArray())[0];
|
||||
if (!pdoc) throw new ProblemNotFoundError(pid);
|
||||
if (!pdoc) throw new ProblemNotFoundError(domainId, pid);
|
||||
if (uid) {
|
||||
pdoc.psdoc = await document.getStatus(domainId, document.TYPE_PROBLEM, pdoc.docId, uid);
|
||||
}
|
||||
@@ -110,10 +110,15 @@ async function random(domainId, query) {
|
||||
} return null;
|
||||
}
|
||||
|
||||
async function getList(domainId, pids) {
|
||||
async function getList(domainId, pids, doThrow = true) {
|
||||
const r = {};
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
for (const pid of pids) r[pid] = await get(domainId, pid);
|
||||
if (doThrow) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
for (const pid of pids) r[pid] = await get(domainId, pid);
|
||||
} else {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
for (const pid of pids) r[pid] = await get(domainId, pid).catch((e) => e);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
+24
-11
@@ -41,7 +41,7 @@ const ACCOUNT_SETTINGS = [
|
||||
const SETTINGS = [...PREFERENCE_SETTINGS, ...ACCOUNT_SETTINGS];
|
||||
const SETTINGS_BY_KEY = {};
|
||||
|
||||
for (const setting in SETTINGS) SETTINGS_BY_KEY[setting.key] = setting;
|
||||
for (const setting of SETTINGS) SETTINGS_BY_KEY[setting.key] = setting;
|
||||
|
||||
const SYSTEM_SETTINGS = [
|
||||
Setting('setting_basic', 'user.register', null, false, 'checkbox', 'Allow register'),
|
||||
@@ -49,19 +49,32 @@ const SYSTEM_SETTINGS = [
|
||||
Setting('setting_smtp', 'smtp.user', null, null, 'text', 'SMTP Username'),
|
||||
Setting('setting_smtp', 'smtp.pass', null, null, 'password', 'SMTP Password'),
|
||||
Setting('setting_smtp', 'smtp.host', null, null, 'text', 'SMTP Server Host'),
|
||||
Setting('setting_smtp', 'smtp.port', null, 465, 'text', 'SMTP Server Port'),
|
||||
Setting('setting_smtp', 'smtp.port', null, 465, 'number', 'SMTP Server Port'),
|
||||
Setting('setting_smtp', 'smtp.from', null, null, 'text', 'Mail From'),
|
||||
Setting('setting_smtp', 'smtp.secure', null, false, 'checkbox', 'SSL'),
|
||||
Setting('setting_server', 'listen.port', null, 8888, 'text', 'Server Port', ''),
|
||||
Setting('setting_constant', 'PROBLEM_PER_PAGE', null, 100, 'text', 'Problems per Page'),
|
||||
Setting('setting_constant', 'CONTEST_PER_PAGE', null, 20, 'text', 'Contests per Page'),
|
||||
Setting('setting_constant', 'DISCUSSION_PER_PAGE', null, 50, 'text', 'Discussion per Page'),
|
||||
Setting('setting_constant', 'RECORD_PER_PAGE', null, 100, 'text', 'Record per Page'),
|
||||
Setting('setting_constant', 'SOLUTION_PER_PAGE', null, 20, 'text', 'Solutions per Page'),
|
||||
Setting('setting_constant', 'TRAINING_PER_PAGE', null, 10, 'text', 'Training per Page'),
|
||||
Setting('setting_constant', 'REPLY_PER_PAGE', null, 50, 'text', 'Reply per Page'),
|
||||
Setting('setting_server', 'server.hostname', null, null, 'text', 'Server Hostname'),
|
||||
Setting('setting_server', 'server.host', null, null, 'text', 'Server Host'),
|
||||
Setting('setting_server', 'server.url', null, null, 'text', 'Server BaseURL'),
|
||||
Setting('setting_server', 'server.port', null, 8888, 'number', 'Server Port'),
|
||||
Setting('setting_constant', 'PROBLEM_PER_PAGE', null, 100, 'number', 'Problems per Page'),
|
||||
Setting('setting_constant', 'CONTEST_PER_PAGE', null, 20, 'number', 'Contests per Page'),
|
||||
Setting('setting_constant', 'DISCUSSION_PER_PAGE', null, 50, 'number', 'Discussion per Page'),
|
||||
Setting('setting_constant', 'RECORD_PER_PAGE', null, 100, 'number', 'Record per Page'),
|
||||
Setting('setting_constant', 'SOLUTION_PER_PAGE', null, 20, 'number', 'Solutions per Page'),
|
||||
Setting('setting_constant', 'TRAINING_PER_PAGE', null, 10, 'number', 'Training per Page'),
|
||||
Setting('setting_constant', 'REPLY_PER_PAGE', null, 50, 'number', 'Reply per Page'),
|
||||
];
|
||||
|
||||
const SYSTEM_SETTINGS_BY_KEY = {};
|
||||
|
||||
for (const setting of SYSTEM_SETTINGS) SYSTEM_SETTINGS_BY_KEY[setting.key] = setting;
|
||||
|
||||
global.Hydro.model.setting = module.exports = {
|
||||
Setting, PREFERENCE_SETTINGS, ACCOUNT_SETTINGS, SETTINGS, SETTINGS_BY_KEY, SYSTEM_SETTINGS,
|
||||
Setting,
|
||||
PREFERENCE_SETTINGS,
|
||||
ACCOUNT_SETTINGS,
|
||||
SETTINGS,
|
||||
SETTINGS_BY_KEY,
|
||||
SYSTEM_SETTINGS,
|
||||
SYSTEM_SETTINGS_BY_KEY,
|
||||
};
|
||||
Reference in new issue
Block a user