From 7f8f48ba0810ff0fe572a24a13970a50377a8302 Mon Sep 17 00:00:00 2001 From: t123yh Date: Mon, 28 Aug 2017 17:25:54 +0800 Subject: [PATCH] Move sorting default values to config file. --- config-example.json | 10 ++++++++++ modules/index.js | 2 +- modules/user.js | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config-example.json b/config-example.json index b837917..84dd2fb 100644 --- a/config-example.json +++ b/config-example.json @@ -26,6 +26,16 @@ "rating": 1500 } }, + "sorting": { + "ranklist": { + "field": "rating", + "order": "desc" + }, + "problem": { + "field": "id", + "order": "asc" + } + }, "limit": { "time_limit": 10000, "memory_limit": 1024, diff --git a/modules/index.js b/modules/index.js index 4354eba..7d1fb37 100644 --- a/modules/index.js +++ b/modules/index.js @@ -26,7 +26,7 @@ let Divine = require('syzoj-divine'); app.get('/', async (req, res) => { try { - let ranklist = await User.query([1, 10], { is_show: true }, [['ac_num', 'desc']]); + let ranklist = await User.query([1, 10], { is_show: true }, [[syzoj.config.sorting.ranklist.field, syzoj.config.sorting.ranklist.order]]); await ranklist.forEachAsync(async x => x.renderInformation()); let notices = (await Article.query(null, { is_notice: true }, [['public_time', 'desc']])).map(article => ({ diff --git a/modules/user.js b/modules/user.js index fa0fd1a..acbe69f 100644 --- a/modules/user.js +++ b/modules/user.js @@ -24,8 +24,8 @@ let User = syzoj.model('user'); // Ranklist app.get('/ranklist', async (req, res) => { try { - const sort = req.query.sort || "id"; - const order = req.query.order || "desc"; + const sort = req.query.sort || syzoj.config.sorting.ranklist.field; + const order = req.query.order || syzoj.config.sorting.ranklist.order; console.log("SORT ===> " + sort + ", ORDER ===> " + order); if (!['ac_num', 'rating', 'id', 'username'].includes(sort) || !['asc', 'desc'].includes(order)) { throw new ErrorMessage('错误的排序参数。');