Browse Source

Move sorting default values to config file.

pull/6/head
t123yh 7 years ago
parent
commit
7f8f48ba08
  1. 10
      config-example.json
  2. 2
      modules/index.js
  3. 4
      modules/user.js

10
config-example.json

@ -26,6 +26,16 @@
"rating": 1500 "rating": 1500
} }
}, },
"sorting": {
"ranklist": {
"field": "rating",
"order": "desc"
},
"problem": {
"field": "id",
"order": "asc"
}
},
"limit": { "limit": {
"time_limit": 10000, "time_limit": 10000,
"memory_limit": 1024, "memory_limit": 1024,

2
modules/index.js

@ -26,7 +26,7 @@ let Divine = require('syzoj-divine');
app.get('/', async (req, res) => { app.get('/', async (req, res) => {
try { 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()); await ranklist.forEachAsync(async x => x.renderInformation());
let notices = (await Article.query(null, { is_notice: true }, [['public_time', 'desc']])).map(article => ({ let notices = (await Article.query(null, { is_notice: true }, [['public_time', 'desc']])).map(article => ({

4
modules/user.js

@ -24,8 +24,8 @@ let User = syzoj.model('user');
// Ranklist // Ranklist
app.get('/ranklist', async (req, res) => { app.get('/ranklist', async (req, res) => {
try { try {
const sort = req.query.sort || "id"; const sort = req.query.sort || syzoj.config.sorting.ranklist.field;
const order = req.query.order || "desc"; const order = req.query.order || syzoj.config.sorting.ranklist.order;
console.log("SORT ===> " + sort + ", ORDER ===> " + order); console.log("SORT ===> " + sort + ", ORDER ===> " + order);
if (!['ac_num', 'rating', 'id', 'username'].includes(sort) || !['asc', 'desc'].includes(order)) { if (!['ac_num', 'rating', 'id', 'username'].includes(sort) || !['asc', 'desc'].includes(order)) {
throw new ErrorMessage('错误的排序参数。'); throw new ErrorMessage('错误的排序参数。');

Loading…
Cancel
Save