From 5dce70d40b71ae12e158b16a8378e194e437434f Mon Sep 17 00:00:00 2001 From: Menci Date: Mon, 7 Aug 2017 18:55:30 +0800 Subject: [PATCH] Code style --- app.js | 3 +++ {modules => libs}/enums.js | 0 modules/judge.js => libs/judger.js | 0 models/judge_state.js | 5 +++-- modules/api_v2.js | 2 +- modules/problem.js | 4 ++-- 6 files changed, 9 insertions(+), 5 deletions(-) rename {modules => libs}/enums.js (100%) rename modules/judge.js => libs/judger.js (100%) diff --git a/app.js b/app.js index 2086ef7..f7cb031 100644 --- a/app.js +++ b/app.js @@ -112,6 +112,9 @@ global.syzoj = { this.db.sync(); }); }, + lib(name) { + return require(`./libs/${name}`); + }, model(name) { return require(`./models/${name}`); }, diff --git a/modules/enums.js b/libs/enums.js similarity index 100% rename from modules/enums.js rename to libs/enums.js diff --git a/modules/judge.js b/libs/judger.js similarity index 100% rename from modules/judge.js rename to libs/judger.js diff --git a/models/judge_state.js b/models/judge_state.js index af62a28..b0088de 100644 --- a/models/judge_state.js +++ b/models/judge_state.js @@ -20,13 +20,14 @@ 'use strict'; let Sequelize = require('sequelize'); -const judger = require('../modules/judge'); let db = syzoj.db; let User = syzoj.model('user'); let Problem = syzoj.model('problem'); let Contest = syzoj.model('contest'); +let Judger = syzoj.lib('judger'); + let model = db.define('judge_state', { id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, @@ -229,7 +230,7 @@ class JudgeState extends Model { await contest.newSubmission(this); } - await judger.judge(this, 1); + await Judger.judge(this, 1); }); } diff --git a/modules/api_v2.js b/modules/api_v2.js index e1f2e98..1af6ccb 100644 --- a/modules/api_v2.js +++ b/modules/api_v2.js @@ -158,7 +158,7 @@ app.apiRouter.post('/api/v2/judge/peek', async (req, res) => { app.apiRouter.post('/api/v2/judge/update2', async (req, res) => { try { if (req.get('Token') !== syzoj.config.judge_token) return res.status(403).send({ err: 'Incorrect token' }); - const data = req.body; + let data = req.body; let JudgeState = syzoj.model('judge_state'); let judge_state = await JudgeState.fromID(req.body.taskId); diff --git a/modules/problem.js b/modules/problem.js index c21b20a..2d358c9 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -28,7 +28,7 @@ let ProblemTag = syzoj.model('problem_tag'); let ProblemTagMap = syzoj.model('problem_tag_map'); let Article = syzoj.model('article'); -const judger = require('../modules/judge'); +let Judger = syzoj.lib('judger'); app.get('/problems', async (req, res) => { try { @@ -638,7 +638,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1 await judge_state.updateRelatedInfo(true); try { - await judger.judge(judge_state, contest_id ? 3 : 2); + await Judger.judge(judge_state, contest_id ? 3 : 2); } catch (err) { throw new ErrorMessage(`无法开始评测:${err.toString()}`); }