mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
feats::
统一语言配置位置 支持langs继承 支持归类
This commit is contained in:
1 parent
5902b4d4b6
commit
377ef55d49
27 files changed
+253
-658
No files matched your search
@@ -125,6 +125,7 @@ Click here to chat with me: 点击这里与我聊天
|
||||
click to add: 点击添加
|
||||
CLOSE: 关闭
|
||||
Code blocks: 代码区块
|
||||
Code language settings: 编程语言设置
|
||||
Code language: 代码语言
|
||||
Code: 代码
|
||||
collapse: 收缩
|
||||
@@ -416,9 +417,6 @@ Judged At: 评测时间
|
||||
Judged By: 评测机
|
||||
Judging Queue: 评测队列
|
||||
Keep current expiration: 保持当前过期设置
|
||||
LANG_TEXTS: 编译语言代号 -> 语言名称
|
||||
Language file settings: 评测机语言(langs.yaml)
|
||||
Language Highlight ID: 编译语言代号 -> 高亮语言代号
|
||||
Language: 语言
|
||||
last active at: 最后活动于
|
||||
last login at: 最后登录于
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.24.22",
|
||||
"version": "2.25.0",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
@@ -11,7 +11,7 @@
|
||||
"node": ">=14"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hydrooj/utils": "^1.0.13",
|
||||
"@hydrooj/utils": "^1.0.14",
|
||||
"adm-zip": "^0.5.5",
|
||||
"ansi_up": "^5.0.1",
|
||||
"cookies": "^0.8.0",
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
langs:
|
||||
type: yaml
|
||||
desc: Code language settings
|
||||
default:
|
||||
__hint__:
|
||||
- All keys started with _ will be ignored
|
||||
- Entries named like [foo], [foo].[bar] [foo].[baz] will be merged into one category.
|
||||
- A entry named [foo].[bar] will inhert all options defined in entry [foo] if not overwritten
|
||||
- code_file option defaults to foo.[name]
|
||||
- highlight option defaults to [name]
|
||||
- if highlight option was set, monaco option defaults to [highlight], otherwise defaults to [name]
|
||||
- Compile step will be ignored if compile option was not set
|
||||
- Key marked with a ? means the option is optional
|
||||
- (name):
|
||||
compile?: Compile Command
|
||||
code_file?: Where to write code file when compiling
|
||||
execute?: Command to execute the program
|
||||
highlight?: PrismJS highlight mode
|
||||
monaco?: Monaco editor mode
|
||||
time_limit_rate: Time limit rate
|
||||
target: Compiler output file
|
||||
display: Display name
|
||||
c:
|
||||
compile: /usr/bin/gcc -Wall --std=c99 -o ${name} foo.c -lm
|
||||
highlight: c astyle-c
|
||||
monaco: cpp
|
||||
display: C
|
||||
cc:
|
||||
compile: /usr/bin/g++ -Wall -std=c++11 -o ${name} foo.cc -lm
|
||||
code_file: foo.cc
|
||||
highlight: cpp astyle-c
|
||||
monaco: cpp
|
||||
display: C++
|
||||
cc.std98:
|
||||
compile: /usr/bin/g++ -Wall -std=c++98 -o ${name} foo.cc -lm
|
||||
display: C++ 98
|
||||
cc.std11:
|
||||
display: C++ 11
|
||||
cc.std17:
|
||||
compile: /usr/bin/g++ -Wall -std=c++17 -o ${name} foo.cc -lm
|
||||
display: C++ 17
|
||||
pas:
|
||||
compile: /usr/bin/fpc -O2 -o${dir}/${name} foo.pas
|
||||
highlight: pascal
|
||||
display: Pascal
|
||||
java:
|
||||
compile: /usr/bin/javac -d ${dir} -encoding utf8 ./Main.java
|
||||
code_file: Main.java
|
||||
target: Main.class
|
||||
execute: /usr/bin/java Main
|
||||
time_limit_rate: 2
|
||||
highlight: java astyle-java
|
||||
monaco: java
|
||||
display: Java
|
||||
py:
|
||||
compile: /usr/bin/python -c "import py_compile; py_compile.compile('${dir}/foo.py', '${dir}/${name}', doraise=True)"
|
||||
code_file: foo.py
|
||||
execute: /usr/bin/python ${name}
|
||||
highlight: python
|
||||
display: Python
|
||||
py.py2:
|
||||
display: Python 2
|
||||
py.py3:
|
||||
compile: /usr/bin/python3 -c "import py_compile; py_compile.compile('${dir}/foo.py', '${dir}/${name}', doraise=True)"
|
||||
execute: /usr/bin/python3 ${name}
|
||||
display: Python 3
|
||||
php:
|
||||
execute: /usr/bin/php foo.php
|
||||
display: PHP
|
||||
rs:
|
||||
compile: /usr/bin/rustc -O -o ${dir}/${name} ${dir}/foo.rs
|
||||
highlight: rust
|
||||
display: Rust
|
||||
hs:
|
||||
compile: /usr/bin/ghc -O -outputdir /tmp -o ${name} foo.hs
|
||||
highlight: haskell
|
||||
display: Haskell
|
||||
js:
|
||||
execute: /usr/bin/jsc ${dir}/foo.js
|
||||
highlight: javascript
|
||||
display: Javascript (JSC)
|
||||
go:
|
||||
compile: /usr/bin/go build -o ${name} foo.go
|
||||
display: Golang
|
||||
rb:
|
||||
execute: /usr/bin/ruby foo.rb
|
||||
highlight: ruby
|
||||
display: Ruby
|
||||
cs:
|
||||
compile: /usr/bin/mcs -optimize+ -out:${dir}/${name} ${dir}/foo.cs
|
||||
execute: /usr/bin/mono ${name}
|
||||
highlight: csharp astyle-cs
|
||||
monaco: csharp
|
||||
display: Csharp
|
||||
jl:
|
||||
execute: /usr/bin/julia ${dir}/foo.jl
|
||||
highlight: julia
|
||||
display: Julia
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ObjectID } from 'mongodb';
|
||||
import { parseLang } from '@hydrooj/utils/lib/lang';
|
||||
import { JudgeResultBody, Rdoc, TestCase } from '../interface';
|
||||
import { sleep } from '../utils';
|
||||
import { Logger } from '../logger';
|
||||
@@ -9,6 +10,7 @@ import * as builtin from '../model/builtin';
|
||||
import * as contest from '../model/contest';
|
||||
import domain from '../model/domain';
|
||||
import task from '../model/task';
|
||||
import * as system from '../model/system';
|
||||
import * as bus from '../service/bus';
|
||||
import {
|
||||
Route, Handler, Connection, ConnectionHandler, post, Types,
|
||||
@@ -119,12 +121,22 @@ class JudgeConnectionHandler extends ConnectionHandler {
|
||||
processing: any = null;
|
||||
closed = false;
|
||||
query: any = { type: 'judge' };
|
||||
ip: string;
|
||||
|
||||
async prepare() {
|
||||
logger.info('Judge daemon connected from ', this.request.ip);
|
||||
const xff = system.get('server.xff');
|
||||
this.ip = xff ? this.request.headers[xff] || this.request.ip : this.request.ip;
|
||||
logger.info('Judge daemon connected from ', this.ip);
|
||||
this.send({ language: system.lang });
|
||||
this.sendLanguageConfig = this.sendLanguageConfig.bind(this);
|
||||
bus.on('system/setting', this.sendLanguageConfig);
|
||||
this.newTask();
|
||||
}
|
||||
|
||||
async sendLanguageConfig() {
|
||||
this.send({ language: system.lang });
|
||||
}
|
||||
|
||||
async newTask() {
|
||||
if (this.processing) return;
|
||||
let t;
|
||||
@@ -157,7 +169,8 @@ class JudgeConnectionHandler extends ConnectionHandler {
|
||||
}
|
||||
|
||||
async cleanup() {
|
||||
logger.info('Judge daemon disconnected from ', this.request.ip);
|
||||
logger.info('Judge daemon disconnected from ', this.ip);
|
||||
bus.off('system/setting', this.sendLanguageConfig);
|
||||
if (this.processing) {
|
||||
await record.reset(this.processing.domainId, this.processing.rid, false);
|
||||
await task.add(this.processing);
|
||||
|
||||
@@ -519,23 +519,6 @@ export const CATEGORIES = {
|
||||
],
|
||||
};
|
||||
|
||||
export const LANG_TEXTS = {
|
||||
c: 'C',
|
||||
cc: 'C++',
|
||||
cs: 'C#',
|
||||
pas: 'Pascal',
|
||||
java: 'Java',
|
||||
py: 'Python',
|
||||
py3: 'Python 3',
|
||||
php: 'PHP',
|
||||
rs: 'Rust',
|
||||
hs: 'Haskell',
|
||||
js: 'JavaScript',
|
||||
go: 'Go',
|
||||
rb: 'Ruby',
|
||||
jl: 'Julia',
|
||||
};
|
||||
|
||||
global.Hydro.model.builtin = {
|
||||
Permission,
|
||||
PERM,
|
||||
@@ -547,7 +530,6 @@ global.Hydro.model.builtin = {
|
||||
BUILTIN_ROLES,
|
||||
DEFAULT_NODES,
|
||||
CATEGORIES,
|
||||
LANG_TEXTS,
|
||||
STATUS,
|
||||
STATUS_TEXTS,
|
||||
STATUS_CODES,
|
||||
|
||||
@@ -3,6 +3,7 @@ import moment from 'moment-timezone';
|
||||
import { Dictionary } from 'lodash';
|
||||
import yaml from 'js-yaml';
|
||||
import { retry } from '@hydrooj/utils/lib/utils';
|
||||
import { parseLang } from '@hydrooj/utils/lib/lang';
|
||||
import * as builtin from './builtin';
|
||||
import { Setting as _Setting } from '../interface';
|
||||
import { Logger } from '../logger';
|
||||
@@ -98,10 +99,30 @@ export const SystemSetting = (...settings: _Setting[]) => {
|
||||
}
|
||||
};
|
||||
|
||||
const LangSettingNode = {
|
||||
family: 'setting_usage',
|
||||
key: 'codeLang',
|
||||
value: 'c',
|
||||
name: 'codeLang',
|
||||
desc: 'Default Code Language',
|
||||
flag: 0,
|
||||
subType: '',
|
||||
type: 'select',
|
||||
range: {},
|
||||
};
|
||||
|
||||
bus.on('system/setting', (args) => {
|
||||
if (!args['hydrooj.lang']) return;
|
||||
const lang = parseLang(args['hydrooj.lang']);
|
||||
const range = {};
|
||||
for (const key in lang) range[key] = lang[key].display;
|
||||
LangSettingNode.range = range;
|
||||
});
|
||||
|
||||
PreferenceSetting(
|
||||
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'),
|
||||
LangSettingNode,
|
||||
Setting('setting_usage', 'codeTemplate', '', 'textarea', 'Default Code Template',
|
||||
'If left blank, the built-in template of the corresponding language will be used.'),
|
||||
);
|
||||
@@ -165,7 +186,6 @@ SystemSetting(
|
||||
Setting('setting_limits', 'limit.problem_files_max', 100, 'number', 'limit.problem_files_max', 'Max files per problem'),
|
||||
Setting('setting_basic', 'default.priv', builtin.PRIV.PRIV_DEFAULT, 'number', 'default.priv', 'Default Privilege'),
|
||||
Setting('setting_basic', 'problem.categories', builtin.CATEGORIES, 'yaml', 'problem.categories', 'Problem Categories'),
|
||||
Setting('setting_basic', 'lang.texts', builtin.LANG_TEXTS, 'yaml', 'lang.texts', 'LANG_TEXTS'),
|
||||
Setting('setting_basic', 'pagination.problem', 100, 'number', 'pagination.problem', 'Problems per page'),
|
||||
Setting('setting_basic', 'pagination.contest', 20, 'number', 'pagination.contest', 'Contests per page'),
|
||||
Setting('setting_basic', 'pagination.discussion', 50, 'number', 'pagination.discussion', 'Discussions per page'),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { parseLang } from '@hydrooj/utils/lib/lang';
|
||||
import { SYSTEM_SETTINGS } from './setting';
|
||||
import { NumberKeys } from '../typeutils';
|
||||
import { SystemKeys } from '../interface';
|
||||
@@ -70,8 +71,13 @@ export async function runConfig() {
|
||||
await bus.emit('database/config');
|
||||
}
|
||||
|
||||
// eslint-disable-next-line import/no-mutable-exports
|
||||
export let lang = {};
|
||||
|
||||
bus.on('system/setting', (args) => {
|
||||
for (const key in args) set(key, args[key], false);
|
||||
if (!args['hydrooj.lang']) return;
|
||||
lang = parseLang(args['hydrooj.lang']);
|
||||
});
|
||||
|
||||
global.Hydro.model.system = {
|
||||
@@ -80,4 +86,5 @@ global.Hydro.model.system = {
|
||||
getMany,
|
||||
inc,
|
||||
set,
|
||||
lang,
|
||||
};
|
||||
Reference in new issue
Block a user