From 735ed8e744b9d5eb3881140ef11bf3460ee2a6e4 Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 2 Mar 2021 22:52:29 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E6=8F=90=E5=8F=96=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hydrojudge/src/sandbox.ts | 3 +- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/entry/common.ts | 4 +- packages/hydrooj/src/interface.ts | 2 +- packages/hydrooj/src/lib/validator.ts | 36 ------- packages/hydrooj/src/model/builtin.ts | 25 +---- packages/hydrooj/src/model/setting.ts | 138 ++++++++++++++------------ 7 files changed, 81 insertions(+), 129 deletions(-) diff --git a/packages/hydrojudge/src/sandbox.ts b/packages/hydrojudge/src/sandbox.ts index 030e9aa4a..d0c139599 100644 --- a/packages/hydrojudge/src/sandbox.ts +++ b/packages/hydrojudge/src/sandbox.ts @@ -1,13 +1,12 @@ import Axios from 'axios'; import fs from 'fs-extra'; -import { argv } from 'yargs'; import * as STATUS from './status'; import { SystemError } from './error'; import { cmd, parseMemoryMB } from './utils'; import { getConfig } from './config'; const env = ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOME=/w']; -const axios = Axios.create({ baseURL: argv.sandbox as string || 'http://localhost:5050' }); +const axios = Axios.create({ baseURL: getConfig('sandbox_host') }); const statusMap = { 'Time Limit Exceeded': STATUS.STATUS_TIME_LIMIT_EXCEEDED, diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 8089c787d..ee0cc86fe 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.18.5", + "version": "2.19.0", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/entry/common.ts b/packages/hydrooj/src/entry/common.ts index 8f3d537e3..10c27d292 100644 --- a/packages/hydrooj/src/entry/common.ts +++ b/packages/hydrooj/src/entry/common.ts @@ -108,8 +108,8 @@ export async function setting(pending: string[], fail: string[], modelSetting: t } map[cfg[key].category || 'system']( modelSetting.Setting( - name, `${name}.${key}`, cfg[key].range, val, - cfg[key].type || 'text', cfg[key].name || key, cfg[key].desc || '', + name, `${name}.${key}`, val, cfg[key].type || 'text', + cfg[key].name || key, cfg[key].desc || '', ), ); } diff --git a/packages/hydrooj/src/interface.ts b/packages/hydrooj/src/interface.ts index 3525418a4..f42897618 100644 --- a/packages/hydrooj/src/interface.ts +++ b/packages/hydrooj/src/interface.ts @@ -45,7 +45,7 @@ export interface SystemKeys { export interface Setting { family: string, key: string, - range: Array<[string, string]> | Dictionary, + range: [string, string][] | Record, value: any, type: string, name: string, diff --git a/packages/hydrooj/src/lib/validator.ts b/packages/hydrooj/src/lib/validator.ts index a84c8ff95..fb073e294 100644 --- a/packages/hydrooj/src/lib/validator.ts +++ b/packages/hydrooj/src/lib/validator.ts @@ -119,39 +119,3 @@ global.Hydro.lib.validator = { isDescription, checkDescription, }; -/* -ID_RE = re.compile(r'[^\\/\s\u3000]([^\\/\n\r]*[^\\/\s\u3000])?') - -def is_id(s): - return bool(ID_RE.fullmatch(s)) - -def check_category_name(s): - if not is_id(s): - raise error.ValidationError('category_name') - -def check_node_name(s): - if not is_id(s): - raise error.ValidationError('node_name') - -def is_intro(s): - return isinstance(s, str) and 0 < len(s.strip()) < 500 - -def check_intro(s): - if not is_intro(s): - raise error.ValidationError('intro') - -def is_description(s): - return isinstance(s, str) and len(s) < 65536 - -def check_description(s): - if not is_description(s): - raise error.ValidationError('description') - -def is_lang(i): - return i in export const ant.language.LANG_TEXTS - -def check_lang(i): - if not is_lang(i): - raise error.ValidationError('lang') - -*/ diff --git a/packages/hydrooj/src/model/builtin.ts b/packages/hydrooj/src/model/builtin.ts index 408d400af..1607eb934 100644 --- a/packages/hydrooj/src/model/builtin.ts +++ b/packages/hydrooj/src/model/builtin.ts @@ -311,7 +311,7 @@ export const DEFAULT_NODES = { { pic: 'share', name: '分享' }, { pic: 'solution', name: '题解' }, ], - Vijos: [ + Hydro: [ { pic: 'hydro', name: 'Hydro' }, { pic: null, name: '团队' }, { pic: null, name: '月赛' }, @@ -517,27 +517,6 @@ export const LANG_TEXTS = { rb: 'Ruby', }; -export const LANG_HIGHLIGHT_ID = { - c: 'c', - cc: 'cpp', - cs: 'csharp', - pas: 'pascal', - java: 'java', - py: 'python', - py3: 'python', - php: 'php', - rs: 'rust', - hs: 'haskell', - js: 'javascript', - go: 'go', - rb: 'ruby', -}; - -export function registerLanguage(id: string, display: string, highlight: string) { - LANG_TEXTS[id] = display; - LANG_HIGHLIGHT_ID[id] = highlight; -} - export const STATUS = { STATUS_WAITING: 0, STATUS_ACCEPTED: 1, @@ -626,7 +605,6 @@ export const CONSTANT = { global.Hydro.model.builtin = { Permission, - registerLanguage, CONSTANT, PERM, PERMS, @@ -638,7 +616,6 @@ global.Hydro.model.builtin = { DEFAULT_NODES, CATEGORIES, LANG_TEXTS, - LANG_HIGHLIGHT_ID, STATUS, STATUS_TEXTS, STATUS_CODES, diff --git a/packages/hydrooj/src/model/setting.ts b/packages/hydrooj/src/model/setting.ts index 155c1f6ac..3d313ce55 100644 --- a/packages/hydrooj/src/model/setting.ts +++ b/packages/hydrooj/src/model/setting.ts @@ -17,7 +17,7 @@ for (const country of countries) { for (const t of tz) tzs.add(t); } const timezones = Array.from(tzs).sort().map((tz) => [tz, tz]) as [string, string][]; -export const langRange: Dictionary = {}; +const langRange: Dictionary = {}; for (const lang in global.Hydro.locales) { langRange[lang] = global.Hydro.locales[lang].__langname; @@ -38,15 +38,27 @@ export const DOMAIN_USER_SETTINGS_BY_KEY: SettingDict = {}; export const DOMAIN_SETTINGS_BY_KEY: SettingDict = {}; export const SYSTEM_SETTINGS_BY_KEY: SettingDict = {}; -export type SettingType = 'text' | 'number' | 'markdown' | 'password' | 'select' | 'boolean' | 'textarea'; +export type SettingType = 'text' | 'yaml' | 'number' | 'markdown' | 'password' | 'boolean' | 'textarea' | [string, string][] | Record; export const Setting = ( - family: string, key: string, range: Array<[string, string]> | Dictionary = null, - value: any = null, type: SettingType = 'text', name = '', - desc = '', flag = 0, -): _Setting => ({ - family, key, range, value, type, name, desc, flag, -}); + family: string, key: string, value: any = null, + type: SettingType = 'text', name = '', desc = '', flag = 0, +): _Setting => { + if (type === 'yaml' && typeof value !== 'string') { + value = yaml.dump(value); + type = 'textarea'; + } + return { + family, + key, + value, + name, + desc, + flag, + type: typeof type === 'object' ? 'select' : type, + range: typeof type === 'object' ? type : null, + }; +}; export const PreferenceSetting = (...settings: _Setting[]) => { for (const setting of settings) { @@ -82,76 +94,77 @@ export const SystemSetting = (...settings: _Setting[]) => { }; PreferenceSetting( - Setting('setting_display', 'viewLang', langRange, null, 'select', 'UI Language'), - Setting('setting_display', 'timeZone', timezones, 'Asia/Shanghai', 'select', 'Timezone'), - Setting('setting_usage', 'codeLang', builtin.LANG_TEXTS, 'c', 'select', 'Default Code Language'), - Setting('setting_usage', 'codeTemplate', null, '', 'textarea', 'Default Code Template', + Setting('setting_display', 'viewLang', null, langRange, 'UI Language'), + Setting('setting_display', 'timeZone', 'Asia/Shanghai', timezones, 'Timezone'), + Setting('setting_usage', 'codeLang', 'c', builtin.LANG_TEXTS, 'Default Code Language'), + Setting('setting_usage', 'codeTemplate', '', 'textarea', 'Default Code Template', 'If left blank, the built-in template of the corresponding language will be used.'), ); AccountSetting( - Setting('setting_info', 'gravatar', null, null, 'text', 'Gravatar Email', + Setting('setting_info', 'gravatar', null, 'text', 'Gravatar Email', 'We use Gravatar to present your avatar icon.'), - Setting('setting_info', 'qq', null, null, 'text', 'QQ'), - Setting('setting_info', 'gender', builtin.USER_GENDER_RANGE, builtin.USER_GENDER_OTHER, 'select', 'Gender'), - Setting('setting_info', 'bio', null, null, 'markdown', 'Bio'), - Setting('setting_customize', 'backgroundImage', null, + Setting('setting_info', 'qq', null, 'text', 'QQ'), + Setting('setting_info', 'gender', builtin.USER_GENDER_OTHER, builtin.USER_GENDER_RANGE, 'Gender'), + Setting('setting_info', 'bio', null, 'markdown', 'Bio'), + Setting('setting_customize', 'backgroundImage', '/components/profile/backgrounds/1.jpg', 'text', 'Profile Background Image', 'Choose the background image in your profile page.'), - Setting('setting_storage', 'usage', null, 0, 'number', 'Userfile Usage', null, FLAG_DISABLED | FLAG_HIDDEN), - Setting('setting_storage', 'checkincnt', null, 0, 'number', 'Check In Counter', null, FLAG_DISABLED | FLAG_HIDDEN), - Setting('setting_storage', 'lastcheckin', null, 0, 'number', 'Last checkin time', null, FLAG_DISABLED | FLAG_HIDDEN), + Setting('setting_storage', 'usage', 0, 'number', 'Userfile Usage', null, FLAG_DISABLED | FLAG_HIDDEN), + Setting('setting_storage', 'checkincnt', 0, 'number', 'Check In Counter', null, FLAG_DISABLED | FLAG_HIDDEN), + Setting('setting_storage', 'lastcheckin', 0, 'number', 'Last checkin time', null, FLAG_DISABLED | FLAG_HIDDEN), ); DomainSetting( - Setting('setting_domain', 'name', null, 'New domain', 'text', 'name'), - Setting('setting_domain', 'gravatar', null, '', 'text', 'gravatar', 'Will be used as the domain icon.'), - Setting('setting_domain', 'bulletin', null, '', 'markdown', 'Bulletin'), - Setting('setting_storage', 'pidCounter', null, 0, 'number', 'Problem ID Counter', null, FLAG_HIDDEN | FLAG_DISABLED), - Setting('setting_storage', 'host', null, '', 'text', 'Custom host', null, FLAG_HIDDEN | FLAG_DISABLED), + Setting('setting_domain', 'name', 'New domain', 'text', 'name'), + Setting('setting_domain', 'gravatar', '', 'text', 'gravatar', 'Will be used as the domain icon.'), + Setting('setting_domain', 'bulletin', '', 'markdown', 'Bulletin'), + Setting('setting_storage', 'pidCounter', 0, 'number', 'Problem ID Counter', null, FLAG_HIDDEN | FLAG_DISABLED), + Setting('setting_storage', 'host', '', 'text', 'Custom host', null, FLAG_HIDDEN | FLAG_DISABLED), ); DomainUserSetting( - Setting('setting_info', 'displayName', null, null, 'text', 'display name'), - Setting('setting_storage', 'nAccept', null, 0, 'number', 'nAccept', null, FLAG_HIDDEN | FLAG_DISABLED), - Setting('setting_storage', 'nSubmit', null, 0, 'number', 'nSubmit', null, FLAG_HIDDEN | FLAG_DISABLED), - Setting('setting_storage', 'nLike', null, 0, 'number', 'nLike', null, FLAG_HIDDEN | FLAG_DISABLED), - Setting('setting_storage', 'rp', null, 1500, 'number', 'RP', null, FLAG_HIDDEN | FLAG_DISABLED), - Setting('setting_storage', 'rpdelta', null, 0, 'number', 'RP.delta', null, FLAG_HIDDEN | FLAG_DISABLED), - Setting('setting_storage', 'level', null, 0, 'number', 'level', null, FLAG_HIDDEN | FLAG_DISABLED), + Setting('setting_info', 'displayName', null, 'text', 'display name'), + Setting('setting_storage', 'nAccept', 0, 'number', 'nAccept', null, FLAG_HIDDEN | FLAG_DISABLED), + Setting('setting_storage', 'nSubmit', 0, 'number', 'nSubmit', null, FLAG_HIDDEN | FLAG_DISABLED), + Setting('setting_storage', 'nLike', 0, 'number', 'nLike', null, FLAG_HIDDEN | FLAG_DISABLED), + Setting('setting_storage', 'rp', 1500, 'number', 'RP', null, FLAG_HIDDEN | FLAG_DISABLED), + Setting('setting_storage', 'rpdelta', 0, 'number', 'RP.delta', null, FLAG_HIDDEN | FLAG_DISABLED), + Setting('setting_storage', 'level', 0, 'number', 'level', null, FLAG_HIDDEN | FLAG_DISABLED), ); SystemSetting( - Setting('setting_file', 'file.endPoint', null, null, 'text', 'Storage engine endPoint'), - Setting('setting_file', 'file.accessKey', null, null, 'text', 'Storage engine accessKey'), - Setting('setting_file', 'file.secretKey', null, null, 'password', 'Storage engine secret', null, FLAG_SECRET), - Setting('setting_file', 'file.bucket', null, 'hydro', 'text', 'Storage engine bucket'), - Setting('setting_file', 'file.region', null, 'us-east-1', 'text', 'Storage engine region'), - Setting('setting_file', 'file.endPointForUser', null, '/fs/', 'text', 'EndPoint for user'), - Setting('setting_file', 'file.endPointForJudge', null, '/fs/', 'text', 'EndPoint for judge'), - Setting('setting_smtp', 'smtp.user', null, null, 'text', 'SMTP Username'), - Setting('setting_smtp', 'smtp.pass', null, null, 'password', 'SMTP Password', null, FLAG_SECRET), - Setting('setting_smtp', 'smtp.host', null, null, 'text', 'SMTP Server Host'), - 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, 'boolean', 'SSL'), - Setting('setting_server', 'server.name', null, 'Hydro', 'text', 'Server Name'), - Setting('setting_server', 'server.worker', null, 1, 'number', 'Server Workers Number'), - Setting('setting_server', 'server.hostname', null, 'oj.undefined.moe', 'text', 'Server Hostname'), - Setting('setting_server', 'server.host', null, 'oj.undefined.moe', 'text', 'Server Host'), - Setting('setting_server', 'server.url', null, '/', 'text', 'Server BaseURL'), - Setting('setting_server', 'server.cdn', null, '/', 'text', 'CDN Prefix', 'Ends with /'), - Setting('setting_server', 'server.port', null, 8888, 'number', 'Server Port'), - Setting('setting_server', 'server.xff', null, null, 'text', 'IP Header', 'e.g. x-forwarded-for (lowercase)'), - Setting('setting_server', 'server.language', langRange, 'zh_CN', 'select', 'Default display language'), - Setting('setting_basic', 'problem.categories', null, yaml.dump(builtin.CATEGORIES), 'textarea', 'Problem Categories'), - Setting('setting_session', 'session.keys', null, [String.random(32)], 'text', 'session.keys', null, FLAG_HIDDEN), - Setting('setting_session', 'session.secure', null, false, 'boolean', 'session.secure'), - Setting('setting_session', 'session.saved_expire_seconds', null, 3600 * 24 * 30, 'number', 'Saved session expire seconds'), - Setting('setting_session', 'session.unsaved_expire_seconds', null, 3600 * 3, 'number', 'Unsaved session expire seconds'), - Setting('setting_storage', 'db.ver', null, 0, 'number', 'Database version', null, FLAG_DISABLED | FLAG_HIDDEN), - Setting('setting_storage', 'user', null, 1, 'number', 'User Counter', null, FLAG_DISABLED | FLAG_HIDDEN), - Setting('setting_storage', 'installid', null, String.random(64), 'text', 'Installation ID', null, FLAG_HIDDEN | FLAG_DISABLED), + Setting('setting_file', 'file.endPoint', null, 'text', 'Storage engine endPoint'), + Setting('setting_file', 'file.accessKey', null, 'text', 'Storage engine accessKey'), + Setting('setting_file', 'file.secretKey', null, 'password', 'Storage engine secret', null, FLAG_SECRET), + Setting('setting_file', 'file.bucket', 'hydro', 'text', 'Storage engine bucket'), + Setting('setting_file', 'file.region', 'us-east-1', 'text', 'Storage engine region'), + Setting('setting_file', 'file.endPointForUser', '/fs/', 'text', 'EndPoint for user'), + Setting('setting_file', 'file.endPointForJudge', '/fs/', 'text', 'EndPoint for judge'), + Setting('setting_smtp', 'smtp.user', null, 'text', 'SMTP Username'), + Setting('setting_smtp', 'smtp.pass', null, 'password', 'SMTP Password', null, FLAG_SECRET), + Setting('setting_smtp', 'smtp.host', null, 'text', 'SMTP Server Host'), + Setting('setting_smtp', 'smtp.port', 465, 'number', 'SMTP Server Port'), + Setting('setting_smtp', 'smtp.from', null, 'text', 'Mail From'), + Setting('setting_smtp', 'smtp.secure', false, 'boolean', 'SSL'), + Setting('setting_server', 'server.name', 'Hydro', 'text', 'Server Name'), + Setting('setting_server', 'server.worker', 1, 'number', 'Server Workers Number'), + Setting('setting_server', 'server.hostname', 'oj.undefined.moe', 'text', 'Server Hostname'), + Setting('setting_server', 'server.host', 'oj.undefined.moe', 'text', 'Server Host'), + Setting('setting_server', 'server.url', '/', 'text', 'Server BaseURL'), + Setting('setting_server', 'server.cdn', '/', 'text', 'CDN Prefix', 'Ends with /'), + Setting('setting_server', 'server.port', 8888, 'number', 'Server Port'), + Setting('setting_server', 'server.xff', null, 'text', 'IP Header', 'e.g. x-forwarded-for (lowercase)'), + Setting('setting_server', 'server.language', 'zh_CN', langRange, 'Default display language'), + Setting('setting_basic', 'problem.categories', builtin.CATEGORIES, 'yaml', 'Problem Categories'), + Setting('setting_basic', 'lang.texts', builtin.LANG_TEXTS, 'yaml', 'LANG_TEXTS'), + Setting('setting_session', 'session.keys', [String.random(32)], 'text', 'session.keys', null, FLAG_HIDDEN), + Setting('setting_session', 'session.secure', false, 'boolean', 'session.secure'), + Setting('setting_session', 'session.saved_expire_seconds', 3600 * 24 * 30, 'number', 'Saved session expire seconds'), + Setting('setting_session', 'session.unsaved_expire_seconds', 3600 * 3, 'number', 'Unsaved session expire seconds'), + Setting('setting_storage', 'db.ver', 0, 'number', 'Database version', null, FLAG_DISABLED | FLAG_HIDDEN), + Setting('setting_storage', 'user', 1, 'number', 'User Counter', null, FLAG_DISABLED | FLAG_HIDDEN), + Setting('setting_storage', 'installid', String.random(64), 'text', 'Installation ID', null, FLAG_HIDDEN | FLAG_DISABLED), ); bus.once('app/started', async () => { @@ -168,7 +181,6 @@ bus.once('app/started', async () => { }); global.Hydro.model.setting = { - langRange, Setting, PreferenceSetting, AccountSetting,