讨论节点

This commit is contained in:
masnn committed 2020-05-26 13:07:17 +08:00
1 parent 5e51bd2fe0
commit 7d27e56018
20 files changed
+154 -47

No files matched your search

+61
View File
@@ -5,6 +5,66 @@ const BUILTIN_ROLES = [
{ _id: 'default', perm: perm.PERM_DEFAULT, count: 0 },
{ _id: 'root', perm: perm.PERM_ALL, count: 0 },
];
const DEFAULT_NODES = {
探索: [
{ pic: 'qa', name: '问答' },
{ pic: 'share', name: '分享' },
{ pic: 'solution', name: '题解' },
],
Vijos: [
{ pic: 'vijos', name: 'Vijos' },
{ pic: null, name: '团队' },
{ pic: null, name: '月赛' },
{ pic: 'advice', name: '建议' },
],
数据结构: [
{ pic: null, name: '散列表' },
{ pic: null, name: '搜索树' },
{ pic: null, name: '栈和队列' },
{ pic: null, name: '图' },
{ pic: null, name: '堆' },
],
算法: [
{ pic: null, name: '数论' },
{ pic: null, name: '几何' },
{ pic: null, name: '图论' },
{ pic: null, name: '网络流' },
{ pic: null, name: '动态规划' },
{ pic: null, name: '背包' },
{ pic: null, name: '排序' },
{ pic: null, name: '搜索' },
{ pic: null, name: '并查集' },
{ pic: null, name: '贪心' },
{ pic: null, name: '博弈论' },
],
在线题库: [
{ pic: null, name: 'CodeForces' },
{ pic: null, name: 'TopCoder' },
{ pic: null, name: 'POJ' },
{ pic: null, name: 'BZOJ' },
{ pic: null, name: 'USACO' },
{ pic: null, name: 'RQNOJ' },
{ pic: null, name: 'UOJ' },
{ pic: null, name: 'LOJ' },
{ pic: null, name: '洛谷' },
],
泛: [
{ pic: null, name: '数学' },
{ pic: null, name: '编程' },
{ pic: null, name: '数据库' },
{ pic: null, name: 'C' },
{ pic: null, name: 'C++' },
{ pic: null, name: 'Pascal' },
{ pic: null, name: 'Java' },
{ pic: null, name: 'PHP' },
{ pic: null, name: 'Python' },
{ pic: null, name: '游戏' },
{ pic: null, name: '保送' },
{ pic: null, name: 'ACM' },
],
};
const CATEGORIES = {
动态规划: [
'LCS',
@@ -232,6 +292,7 @@ const STATUS_CODES = {
global.Hydro.model.builtin = module.exports = {
BUILTIN_ROLES,
DEFAULT_NODES,
CATEGORIES,
VIEW_LANGS,
FOOTER_EXTRA_HTMLS,
+7 -2
View File
@@ -3,7 +3,7 @@ const problem = require('./problem');
const contest = require('./contest');
const { PERM_VIEW_PROBLEM_HIDDEN } = require('../permission');
const { DocumentNotFoundError } = require('../error');
const db = require('../service/db.js');
const db = require('../service/db');
const coll = db.collection('discussion');
const collReply = db.collection('discussion.reply');
@@ -133,6 +133,10 @@ function getStatus(did, uid) {
return collStatus.findOne({ did, uid });
}
function addNode(_id, category) {
return collNode.insertOne({ _id, category });
}
function getNode(_id) {
return collNode.findOne({ _id });
}
@@ -148,7 +152,7 @@ async function getVnode(ddoc, handler) {
return { ...tdoc, type: ddoc.parentType, id: ddoc.parentId };
} if (ddoc.parentType === 'node') {
const ndoc = await getNode(ddoc.parentId);
return { ...ndoc, type: ddoc.parentType, id: ddoc.parentId };
return { title: ndoc._id, type: ddoc.parentType, id: ddoc.parentId };
}
return {
title: 'Missing Node',
@@ -185,6 +189,7 @@ global.Hydro.model.discussion = module.exports = {
delTailReply,
setStar,
getStatus,
addNode,
getVnode,
getListVnodes,
};
+12 -8
View File
@@ -5,6 +5,10 @@ const hash = require('../lib/hash.hydro');
const coll = db.collection('file');
function _timestamp() {
return Math.floor(Number(new Date()) / 1000000);
}
async function add(stream, filename, meta = {}) {
const file = await coll.insertOne(meta);
const w = fs.openUploadStreamWithId(file.insertedId, filename);
@@ -43,11 +47,11 @@ async function dec(_id) {
async function get(_id, secret = null) {
const file = await coll.findOne({ _id });
if (typeof secret !== 'undefined') {
const timestamp = Math.floor(Number(new Date())).toString();
if (!(
hash.check(file.secret, timestamp, secret)
|| hash.check(file.secret, timestamp - 1, secret))) {
throw new ForbiddenError();
const timestamp = _timestamp();
if (!hash.check(file.secret, timestamp.toString(), secret)) {
if (!hash.check(file.secret, timestamp.toString() - 1, secret)) {
throw new ForbiddenError();
}
}
}
return fs.openDownloadStream(_id);
@@ -59,11 +63,11 @@ function getMeta(_id) {
async function url(_id, name) {
const file = await coll.findOne({ _id });
const secret = hash.hash(file.secret, Math.floor(Number(new Date())).toString());
if (name) return `/fs/${_id}/${secret}?name=${Buffer.from(name).toString('base64')}`;
const secret = hash.hash(file.secret, _timestamp().toString());
if (name) return `/fs/${_id}/${Buffer.from(name).toString('base64')}/${secret}`;
return `/fs/${_id}/${secret}`;
}
global.Hydro.model.blacklist = module.exports = {
global.Hydro.model.file = module.exports = {
add, get, del, inc, dec, getMeta, url,
};
+1
View File
@@ -13,4 +13,5 @@ module.exports = {
task: require('./task'),
message: require('./message'),
setting: require('./setting'),
file: require('./file'),
};
+2 -2
View File
@@ -21,8 +21,8 @@ async function send(from, to, content) {
$setOnInsert: {
from: Math.min(from, to),
to: Math.max(from, to),
fromUnread: false,
toUnread: true,
fromUnread: from > to,
toUnread: from < to,
},
}, { upsert: true });
return await coll.findOne({ // eslint-disable-line no-return-await
+1 -1
View File
@@ -1,5 +1,5 @@
const { OpcountExceededError } = require('../error');
const db = require('../service/db.js');
const db = require('../service/db');
const coll = db.collection('opcount');
+1 -1
View File
@@ -4,7 +4,7 @@ const { STATUS_WAITING } = require('./builtin').STATUS;
const task = require('./task');
const problem = require('./problem');
const { RecordNotFoundError } = require('../error');
const db = require('../service/db.js');
const db = require('../service/db');
const coll = db.collection('record');
+1 -1
View File
@@ -1,7 +1,7 @@
const { ObjectID } = require('bson');
const { SolutionNotFoundError } = require('../error');
const validator = require('../lib/validator');
const db = require('../service/db.js');
const db = require('../service/db');
const coll = db.collection('solution');
const collStatus = db.collection('solution.status');
+1 -1
View File
@@ -1,4 +1,4 @@
const db = require('../service/db.js');
const db = require('../service/db');
const coll = db.collection('system');
+1 -1
View File
@@ -1,4 +1,4 @@
const db = require('../service/db.js');
const db = require('../service/db');
const coll = db.collection('task');
+1 -1
View File
@@ -1,4 +1,4 @@
const db = require('../service/db.js');
const db = require('../service/db');
const { ValidationError } = require('../error');
const coll = db.collection('token');
+1 -1
View File
@@ -1,7 +1,7 @@
const assert = require('assert');
const validator = require('../lib/validator');
const { ValidationError, TrainingNotFoundError, TrainingAlreadyEnrollError } = require('../error');
const db = require('../service/db.js');
const db = require('../service/db');
const coll = db.collection('traning');
const collStatus = db.collection('training.status');
+1 -1
View File
@@ -31,7 +31,7 @@ class USER {
}
checkPassword(password) {
const h = global.Hydro.lib[`hash.${this.hashType}`];
const h = global.Hydro.lib[`hash.${this.hashType || 'hydro'}`];
if (!h) throw new Error('Unknown hash method');
return h.check(password, this.salt(), this.hash());
}