From 95df2cfaf209db2f8db25148dd173181cae5a9ab Mon Sep 17 00:00:00 2001 From: undefined Date: Sun, 19 Sep 2021 21:30:11 +0800 Subject: [PATCH] core: customizable discussion nodes (#213) --- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/handler/domain.ts | 8 ++- packages/hydrooj/src/model/builtin.ts | 80 +++++++++++++------------- packages/hydrooj/src/model/setting.ts | 1 + 4 files changed, 47 insertions(+), 44 deletions(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 680aaf504..8b5f7b5dd 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.36.7", + "version": "2.36.8", "bin": "bin/hydrooj.js", "main": "src/loader", "module": "src/loader", diff --git a/packages/hydrooj/src/handler/domain.ts b/packages/hydrooj/src/handler/domain.ts index c8f1221c0..54a980d90 100644 --- a/packages/hydrooj/src/handler/domain.ts +++ b/packages/hydrooj/src/handler/domain.ts @@ -1,3 +1,4 @@ +import { load } from 'js-yaml'; import { Dictionary } from 'lodash'; import moment from 'moment-timezone'; import { @@ -8,7 +9,7 @@ import type { DomainDoc } from '../interface'; import avatar from '../lib/avatar'; import paginate from '../lib/paginate'; import { - DEFAULT_NODES, PERM, PERMS_BY_FAMILY, PRIV, + PERM, PERMS_BY_FAMILY, PRIV, } from '../model/builtin'; import * as discussion from '../model/discussion'; import domain from '../model/domain'; @@ -72,8 +73,9 @@ class DomainDashboardHandler extends ManageHandler { } async postInitDiscussionNode({ domainId }) { - for (const category of Object.keys(DEFAULT_NODES)) { - for (const item of DEFAULT_NODES[category]) { + const nodes = load(system.get('discussion.nodes')); + for (const category of Object.keys(nodes)) { + for (const item of nodes[category]) { // eslint-disable-next-line no-await-in-loop const curr = await discussion.getNode(domainId, item.name); // eslint-disable-next-line no-await-in-loop diff --git a/packages/hydrooj/src/model/builtin.ts b/packages/hydrooj/src/model/builtin.ts index 37b18a98f..8d88965c3 100644 --- a/packages/hydrooj/src/model/builtin.ts +++ b/packages/hydrooj/src/model/builtin.ts @@ -276,55 +276,55 @@ export const DEFAULT_NODES = { ], Hydro: [ { pic: 'hydro', name: 'Hydro' }, - { pic: null, name: '团队' }, - { pic: null, name: '月赛' }, + { name: '团队' }, + { name: '月赛' }, { pic: 'advice', name: '建议' }, ], 数据结构: [ - { pic: null, name: '散列表' }, - { pic: null, name: '搜索树' }, - { pic: null, name: '栈和队列' }, - { pic: null, name: '图' }, - { pic: null, name: '堆' }, + { name: '散列表' }, + { name: '搜索树' }, + { name: '栈和队列' }, + { name: '图' }, + { 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: '博弈论' }, + { name: '数论' }, + { name: '几何' }, + { name: '图论' }, + { name: '网络流' }, + { name: '动态规划' }, + { name: '背包' }, + { name: '排序' }, + { name: '搜索' }, + { name: '并查集' }, + { name: '贪心' }, + { 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: '洛谷' }, + { name: 'CodeForces' }, + { name: 'TopCoder' }, + { name: 'POJ' }, + { name: 'BZOJ' }, + { name: 'USACO' }, + { name: 'RQNOJ' }, + { name: 'UOJ' }, + { name: 'LOJ' }, + { 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: 'Julia' }, - { pic: null, name: '游戏' }, - { pic: null, name: '保送' }, - { pic: null, name: 'ACM' }, + { name: '数学' }, + { name: '编程' }, + { name: '数据库' }, + { name: 'C' }, + { name: 'C++' }, + { name: 'Pascal' }, + { name: 'Java' }, + { name: 'PHP' }, + { name: 'Python' }, + { name: 'Julia' }, + { name: '游戏' }, + { name: '保送' }, + { name: 'ACM' }, ], }; diff --git a/packages/hydrooj/src/model/setting.ts b/packages/hydrooj/src/model/setting.ts index 827e9bfa7..107f7b900 100644 --- a/packages/hydrooj/src/model/setting.ts +++ b/packages/hydrooj/src/model/setting.ts @@ -192,6 +192,7 @@ SystemSetting( Setting('setting_limits', 'limit.submission', 30, 'number', 'limit.submission', 'Max submission count per minute'), Setting('setting_limits', 'limit.pretest', 60, 'number', 'limit.pretest', 'Max pretest count per minute'), Setting('setting_basic', 'default.priv', builtin.PRIV.PRIV_DEFAULT, 'number', 'default.priv', 'Default Privilege', FLAG_PRO), + Setting('setting_basic', 'discussion.nodes', builtin.DEFAULT_NODES, 'yaml', 'discussion.nodes', 'Discussion Nodes'), Setting('setting_basic', 'problem.categories', builtin.CATEGORIES, 'yaml', 'problem.categories', 'Problem Categories'), Setting('setting_basic', 'pagination.problem', 100, 'number', 'pagination.problem', 'Problems per page'), Setting('setting_basic', 'pagination.contest', 20, 'number', 'pagination.contest', 'Contests per page'),