Browse Source

Better langauges config

master
Menci 6 years ago
parent
commit
a8f80433a3
  1. 1
      app.js
  2. 123
      config-example.json
  3. 104
      language-config.json
  4. 2
      libs/submissions_process.js
  5. 2
      modules/contest.js
  6. 2
      modules/problem.js
  7. 2
      modules/submission.js
  8. 4
      views/admin_rejudge.ejs
  9. 10
      views/problem.ejs
  10. 2
      views/statistics.ejs
  11. 4
      views/submissions.ejs

1
app.js

@ -11,6 +11,7 @@ const options = commandLineArgs(optionDefinitions);
global.syzoj = { global.syzoj = {
rootDir: __dirname, rootDir: __dirname,
config: require('object-assign-deep')({}, require('./config-example.json'), require(options.config)), config: require('object-assign-deep')({}, require('./config-example.json'), require(options.config)),
languages: require('./language-config.json'),
configDir: options.config, configDir: options.config,
models: [], models: [],
modules: [], modules: [],

123
config-example.json

@ -65,110 +65,25 @@
"edit_contest_problem_list": 10, "edit_contest_problem_list": 10,
"edit_problem_tag_list": 10 "edit_problem_tag_list": 10
}, },
"languages": { "enabled_languages": [
"cpp": { "cpp",
"show": "C++", "cpp11",
"highlight": "cpp", "cpp17",
"version": "Clang 7.0.1", "csharp",
"editor": "c_cpp" "c",
}, "vala",
"cpp11": { "java",
"show": "C++ 11", "pascal",
"highlight": "cpp", "lua",
"version": "Clang 7.0.1", "luajit",
"editor": "c_cpp" "python2",
}, "python3",
"cpp17": { "nodejs",
"show": "C++ 17", "ruby",
"highlight": "cpp", "haskell",
"version": "Clang 7.0.1", "ocaml",
"editor": "c_cpp" "vbnet"
}, ],
"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"
}
},
"links": [ "links": [
{ {
"title": "LibreOJ", "title": "LibreOJ",

104
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"
}
}

2
libs/submissions_process.js

@ -5,7 +5,7 @@ const getSubmissionInfo = (s, displayConfig) => ({
userId: s.user_id, userId: s.user_id,
problemName: s.problem.title, problemName: s.problem.title,
problemId: s.problem_id, 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, codeSize: displayConfig.showCode ? syzoj.utils.formatSize(s.code_length) : null,
submitTime: syzoj.utils.formatDate(s.submit_time), submitTime: syzoj.utils.formatDate(s.submit_time),
}); });

2
modules/contest.js

@ -412,7 +412,7 @@ app.get('/contest/submission/:id', async (req, res) => {
if (judge.problem.type !== 'submit-answer') { if (judge.problem.type !== 'submit-answer') {
judge.codeLength = judge.code.length; 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', { res.render('submission', {

2
modules/problem.js

@ -592,7 +592,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
const curUser = res.locals.user; const curUser = res.locals.user;
if (!problem) throw new ErrorMessage('无此题目。'); 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]) }) }); if (!curUser) throw new ErrorMessage('请登录后继续。', { '登录': syzoj.utils.makeUrl(['login'], { 'url': syzoj.utils.makeUrl(['problem', id]) }) });
let judge_state; let judge_state;

2
modules/submission.js

@ -147,7 +147,7 @@ app.get('/submission/:id', async (req, res) => {
if (judge.problem.type !== 'submit-answer') { if (judge.problem.type !== 'submit-answer') {
judge.codeLength = judge.code.length; 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); displayConfig.showRejudge = await judge.problem.isAllowedEditBy(res.locals.user);

4
views/admin_rejudge.ejs

@ -19,8 +19,8 @@
<div class="menu"> <div class="menu">
<div class="item" data-value="">不限</div> <div class="item" data-value="">不限</div>
<div class="item" data-value="submit-answer">提交答案</div> <div class="item" data-value="submit-answer">提交答案</div>
<% for (let lang in syzoj.config.languages) { %> <% for (let lang of syzoj.config.enabled_languages) { %>
<div class="item" data-value="<%= lang %>"><%= syzoj.config.languages[lang].show %></div> <div class="item" data-value="<%= lang %>"><%= syzoj.languages[lang].show %></div>
<% } %> <% } %>
</div> </div>
</div> </div>

10
views/problem.ejs

@ -310,15 +310,15 @@ div[class*=ace_br] {
<div class="four wide column" style="margin-right: -25px; "> <div class="four wide column" style="margin-right: -25px; ">
<div class="ui attached vertical fluid pointing menu" id="languages-menu" style="height: 370px; overflow-y: scroll; overflow-x: hidden; "> <div class="ui attached vertical fluid pointing menu" id="languages-menu" style="height: 370px; overflow-y: scroll; overflow-x: hidden; ">
<% <%
let language = Object.getOwnPropertyNames(syzoj.config.languages).shift(); let language = syzoj.config.enabled_languages;;
if (state) { if (state) {
language = state.language; language = state.language;
} else if (lastLanguage) language = lastLanguage; } else if (lastLanguage) language = lastLanguage;
%> %>
<% for (lang in syzoj.config.languages) { %> <% for (lang of syzoj.config.enabled_languages) { %>
<a class="item<%= lang === language ? ' active' : '' %>" data-value="<%= lang %>" data-mode="<%= syzoj.config.languages[lang].editor %>"> <a class="item<%= lang === language ? ' active' : '' %>" data-value="<%= lang %>" data-mode="<%= syzoj.languages[lang].editor %>">
<%= syzoj.config.languages[lang].show %> <%= syzoj.languages[lang].show %>
<div class="ui right floated" style="opacity: 0.4; margin-top: 8px; font-size: 0.7em; "><%= syzoj.config.languages[lang].version %></div> <div class="ui right floated" style="opacity: 0.4; margin-top: 8px; font-size: 0.7em; "><%= syzoj.languages[lang].version %></div>
</a> </a>
<% } %> <% } %>
</div> </div>

2
views/statistics.ejs

@ -83,7 +83,7 @@ function getColorOfScore(score) {
<% if (problem.type !== 'submit-answer') { %> <% if (problem.type !== 'submit-answer') { %>
<td><%= judge.total_time %> ms</td> <td><%= judge.total_time %> ms</td>
<td><%= parseInt(judge.max_memory) || 0 %> K</td> <td><%= parseInt(judge.max_memory) || 0 %> K</td>
<td><a href="<%= syzoj.utils.makeUrl(['submission', judge.id]) %>"><%= syzoj.config.languages[judge.language].show %></a> / <%= syzoj.utils.formatSize(judge.code.length) %></td> <td><a href="<%= syzoj.utils.makeUrl(['submission', judge.id]) %>"><%= syzoj.languages[judge.language].show %></a> / <%= syzoj.utils.formatSize(judge.code.length) %></td>
<% } else { %> <% } else { %>
<td><%= syzoj.utils.formatSize(judge.max_memory) %></td> <td><%= syzoj.utils.formatSize(judge.max_memory) %></td>
<% } %> <% } %>

4
views/submissions.ejs

@ -38,8 +38,8 @@
<div class="menu"> <div class="menu">
<div class="item" data-value=""><b>不限</b></div> <div class="item" data-value=""><b>不限</b></div>
<div class="item" data-value="submit-answer"><b>提交答案</b></div> <div class="item" data-value="submit-answer"><b>提交答案</b></div>
<% for (let lang in syzoj.config.languages) { %> <% for (let lang of syzoj.config.enabled_languages) { %>
<div class="item" data-value="<%= lang %>"><b><%= syzoj.config.languages[lang].show %></b></div> <div class="item" data-value="<%= lang %>"><b><%= syzoj.languages[lang].show %></b></div>
<% } %> <% } %>
</div> </div>
</div> </div>

Loading…
Cancel
Save