From a8f80433a3003e93d7a66e535c69eed01d463159 Mon Sep 17 00:00:00 2001 From: Menci Date: Sat, 1 Dec 2018 02:14:46 +0800 Subject: [PATCH] Better langauges config --- app.js | 1 + config-example.json | 123 ++++++------------------------------ language-config.json | 104 ++++++++++++++++++++++++++++++ libs/submissions_process.js | 2 +- modules/contest.js | 2 +- modules/problem.js | 2 +- modules/submission.js | 2 +- views/admin_rejudge.ejs | 4 +- views/problem.ejs | 10 +-- views/statistics.ejs | 2 +- views/submissions.ejs | 4 +- 11 files changed, 138 insertions(+), 118 deletions(-) create mode 100644 language-config.json diff --git a/app.js b/app.js index 4b9eb6e..20e8fc1 100644 --- a/app.js +++ b/app.js @@ -11,6 +11,7 @@ const options = commandLineArgs(optionDefinitions); global.syzoj = { rootDir: __dirname, config: require('object-assign-deep')({}, require('./config-example.json'), require(options.config)), + languages: require('./language-config.json'), configDir: options.config, models: [], modules: [], diff --git a/config-example.json b/config-example.json index 8b3043e..edf2043 100644 --- a/config-example.json +++ b/config-example.json @@ -65,110 +65,25 @@ "edit_contest_problem_list": 10, "edit_problem_tag_list": 10 }, - "languages": { - "cpp": { - "show": "C++", - "highlight": "cpp", - "version": "Clang 7.0.1", - "editor": "c_cpp" - }, - "cpp11": { - "show": "C++ 11", - "highlight": "cpp", - "version": "Clang 7.0.1", - "editor": "c_cpp" - }, - "cpp17": { - "show": "C++ 17", - "highlight": "cpp", - "version": "Clang 7.0.1", - "editor": "c_cpp" - }, - "csharp": { - "show": "C#", - "highlight": "csharp", - "version": "Mono 5.16.0.220", - "editor": "csharp" - }, - "c": { - "show": "C", - "highlight": "c", - "version": "Clang 7.0.1", - "editor": "c_cpp" - }, - "vala": { - "show": "Vala", - "highlight": "vala", - "version": "Vala 0.40.8, Clang 7.0.1", - "editor": "vala" - }, - "java": { - "show": "Java", - "highlight": "java", - "version": "OpenJDK 10.0.2", - "editor": "java" - }, - "pascal": { - "show": "Pascal", - "highlight": "pascal", - "version": "Free Pascal 3.0.4", - "editor": "pascal" - }, - "lua": { - "show": "Lua", - "highlight": "lua", - "version": "Lua 5.3.3", - "editor": "lua" - }, - "luajit": { - "show": "LuaJIT", - "highlight": "lua", - "version": "LuaJIT 2.1.0", - "editor": "lua" - }, - "python2": { - "show": "Python 2", - "highlight": "python", - "version": "PyPy 6.0.0 (Python 2.7.13)", - "editor": "python" - }, - "python3": { - "show": "Python 3", - "highlight": "python", - "version": "PyPy 6.0.0 (Python 3.5.3)", - "editor": "python" - }, - "nodejs": { - "show": "Node.js", - "highlight": "js", - "version": "10.14.0", - "editor": "javascript" - }, - "ruby": { - "show": "Ruby", - "highlight": "ruby", - "version": "2.5.1", - "editor": "ruby" - }, - "haskell": { - "show": "Haskell", - "highlight": "haskell", - "version": "GHC 8.6.2", - "editor": "haskell" - }, - "ocaml": { - "show": "OCaml", - "highlight": "ocaml", - "version": "Ocaml 4.05.0", - "editor": "ocaml" - }, - "vbnet": { - "show": "Visual Basic", - "highlight": "vbnet", - "version": "Mono 4.7", - "editor": "vbscript" - } - }, + "enabled_languages": [ + "cpp", + "cpp11", + "cpp17", + "csharp", + "c", + "vala", + "java", + "pascal", + "lua", + "luajit", + "python2", + "python3", + "nodejs", + "ruby", + "haskell", + "ocaml", + "vbnet" + ], "links": [ { "title": "LibreOJ", diff --git a/language-config.json b/language-config.json new file mode 100644 index 0000000..e663b60 --- /dev/null +++ b/language-config.json @@ -0,0 +1,104 @@ +{ + "cpp": { + "show": "C++", + "highlight": "cpp", + "version": "Clang 7.0.1", + "editor": "c_cpp" + }, + "cpp11": { + "show": "C++ 11", + "highlight": "cpp", + "version": "Clang 7.0.1", + "editor": "c_cpp" + }, + "cpp17": { + "show": "C++ 17", + "highlight": "cpp", + "version": "Clang 7.0.1", + "editor": "c_cpp" + }, + "csharp": { + "show": "C#", + "highlight": "csharp", + "version": "Mono 5.16.0.220", + "editor": "csharp" + }, + "c": { + "show": "C", + "highlight": "c", + "version": "Clang 7.0.1", + "editor": "c_cpp" + }, + "vala": { + "show": "Vala", + "highlight": "vala", + "version": "Vala 0.40.8, Clang 7.0.1", + "editor": "vala" + }, + "java": { + "show": "Java", + "highlight": "java", + "version": "OpenJDK 10.0.2", + "editor": "java" + }, + "pascal": { + "show": "Pascal", + "highlight": "pascal", + "version": "Free Pascal 3.0.4", + "editor": "pascal" + }, + "lua": { + "show": "Lua", + "highlight": "lua", + "version": "Lua 5.3.3", + "editor": "lua" + }, + "luajit": { + "show": "LuaJIT", + "highlight": "lua", + "version": "LuaJIT 2.1.0", + "editor": "lua" + }, + "python2": { + "show": "Python 2", + "highlight": "python", + "version": "PyPy 6.0.0 (Python 2.7.13)", + "editor": "python" + }, + "python3": { + "show": "Python 3", + "highlight": "python", + "version": "PyPy 6.0.0 (Python 3.5.3)", + "editor": "python" + }, + "nodejs": { + "show": "Node.js", + "highlight": "js", + "version": "10.14.0", + "editor": "javascript" + }, + "ruby": { + "show": "Ruby", + "highlight": "ruby", + "version": "2.5.1", + "editor": "ruby" + }, + "haskell": { + "show": "Haskell", + "highlight": "haskell", + "version": "GHC 8.6.2", + "editor": "haskell" + }, + "ocaml": { + "show": "OCaml", + "highlight": "ocaml", + "version": "Ocaml 4.05.0", + "editor": "ocaml" + }, + "vbnet": { + "show": "Visual Basic", + "highlight": "vbnet", + "version": "Mono 4.7", + "editor": "vbscript" + } +} diff --git a/libs/submissions_process.js b/libs/submissions_process.js index faa5714..2eeb679 100644 --- a/libs/submissions_process.js +++ b/libs/submissions_process.js @@ -5,7 +5,7 @@ const getSubmissionInfo = (s, displayConfig) => ({ userId: s.user_id, problemName: s.problem.title, problemId: s.problem_id, - language: displayConfig.showCode ? ((s.language != null && s.language !== '') ? syzoj.config.languages[s.language].show : null) : null, + language: displayConfig.showCode ? ((s.language != null && s.language !== '') ? syzoj.languages[s.language].show : null) : null, codeSize: displayConfig.showCode ? syzoj.utils.formatSize(s.code_length) : null, submitTime: syzoj.utils.formatDate(s.submit_time), }); diff --git a/modules/contest.js b/modules/contest.js index 9a9165d..303de97 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -412,7 +412,7 @@ app.get('/contest/submission/:id', async (req, res) => { if (judge.problem.type !== 'submit-answer') { judge.codeLength = judge.code.length; - judge.code = await syzoj.utils.highlight(judge.code, syzoj.config.languages[judge.language].highlight); + judge.code = await syzoj.utils.highlight(judge.code, syzoj.languages[judge.language].highlight); } res.render('submission', { diff --git a/modules/problem.js b/modules/problem.js index fe42845..6a01cf3 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -592,7 +592,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1 const curUser = res.locals.user; if (!problem) throw new ErrorMessage('无此题目。'); - if (problem.type !== 'submit-answer' && !syzoj.config.languages[req.body.language]) throw new ErrorMessage('不支持该语言。'); + if (problem.type !== 'submit-answer' && !syzoj.languages[req.body.language]) throw new ErrorMessage('不支持该语言。'); if (!curUser) throw new ErrorMessage('请登录后继续。', { '登录': syzoj.utils.makeUrl(['login'], { 'url': syzoj.utils.makeUrl(['problem', id]) }) }); let judge_state; diff --git a/modules/submission.js b/modules/submission.js index 27146c8..c602d42 100644 --- a/modules/submission.js +++ b/modules/submission.js @@ -147,7 +147,7 @@ app.get('/submission/:id', async (req, res) => { if (judge.problem.type !== 'submit-answer') { judge.codeLength = judge.code.length; - judge.code = await syzoj.utils.highlight(judge.code, syzoj.config.languages[judge.language].highlight); + judge.code = await syzoj.utils.highlight(judge.code, syzoj.languages[judge.language].highlight); } displayConfig.showRejudge = await judge.problem.isAllowedEditBy(res.locals.user); diff --git a/views/admin_rejudge.ejs b/views/admin_rejudge.ejs index f300906..d1b6cf2 100644 --- a/views/admin_rejudge.ejs +++ b/views/admin_rejudge.ejs @@ -19,8 +19,8 @@ diff --git a/views/problem.ejs b/views/problem.ejs index ea311d3..ea20c25 100644 --- a/views/problem.ejs +++ b/views/problem.ejs @@ -310,15 +310,15 @@ div[class*=ace_br] {
diff --git a/views/statistics.ejs b/views/statistics.ejs index bf1adea..41746fd 100644 --- a/views/statistics.ejs +++ b/views/statistics.ejs @@ -83,7 +83,7 @@ function getColorOfScore(score) { <% if (problem.type !== 'submit-answer') { %> <%= judge.total_time %> ms <%= parseInt(judge.max_memory) || 0 %> K - <%= syzoj.config.languages[judge.language].show %> / <%= syzoj.utils.formatSize(judge.code.length) %> + <%= syzoj.languages[judge.language].show %> / <%= syzoj.utils.formatSize(judge.code.length) %> <% } else { %> <%= syzoj.utils.formatSize(judge.max_memory) %> <% } %> diff --git a/views/submissions.ejs b/views/submissions.ejs index 1ce55e9..f9fae7d 100644 --- a/views/submissions.ejs +++ b/views/submissions.ejs @@ -38,8 +38,8 @@