|
|
@ -27,11 +27,22 @@ let Contest = syzoj.model('contest'); |
|
|
|
let ProblemTag = syzoj.model('problem_tag'); |
|
|
|
let ProblemTag = syzoj.model('problem_tag'); |
|
|
|
let ProblemTagMap = syzoj.model('problem_tag_map'); |
|
|
|
let ProblemTagMap = syzoj.model('problem_tag_map'); |
|
|
|
let Article = syzoj.model('article'); |
|
|
|
let Article = syzoj.model('article'); |
|
|
|
|
|
|
|
const Sequelize = require('sequelize'); |
|
|
|
|
|
|
|
|
|
|
|
let Judger = syzoj.lib('judger'); |
|
|
|
let Judger = syzoj.lib('judger'); |
|
|
|
|
|
|
|
|
|
|
|
app.get('/problems', async (req, res) => { |
|
|
|
app.get('/problems', async (req, res) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
const sort = req.query.sort || syzoj.config.sorting.problem.field; |
|
|
|
|
|
|
|
const order = req.query.order || syzoj.config.sorting.problem.order; |
|
|
|
|
|
|
|
if (!['id', 'title', 'rating', 'ac_num', 'submit_num', 'ac_rate'].includes(sort) || !['asc', 'desc'].includes(order)) { |
|
|
|
|
|
|
|
throw new ErrorMessage('错误的排序参数。'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let sortVal = sort; |
|
|
|
|
|
|
|
if (sort === 'ac_rate') { |
|
|
|
|
|
|
|
sortVal = { raw: 'ac_num / submit_num' }; |
|
|
|
|
|
|
|
} |
|
|
|
let where = {}; |
|
|
|
let where = {}; |
|
|
|
if (!res.locals.user || !await res.locals.user.hasPrivilege('manage_problem')) { |
|
|
|
if (!res.locals.user || !await res.locals.user.hasPrivilege('manage_problem')) { |
|
|
|
if (res.locals.user) { |
|
|
|
if (res.locals.user) { |
|
|
@ -49,7 +60,7 @@ app.get('/problems', async (req, res) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let paginate = syzoj.utils.paginate(await Problem.count(where), req.query.page, syzoj.config.page.problem); |
|
|
|
let paginate = syzoj.utils.paginate(await Problem.count(where), req.query.page, syzoj.config.page.problem); |
|
|
|
let problems = await Problem.query(paginate, where); |
|
|
|
let problems = await Problem.query(paginate, where, [[sortVal, order]]); |
|
|
|
|
|
|
|
|
|
|
|
await problems.forEachAsync(async problem => { |
|
|
|
await problems.forEachAsync(async problem => { |
|
|
|
problem.allowedEdit = await problem.isAllowedEditBy(res.locals.user); |
|
|
|
problem.allowedEdit = await problem.isAllowedEditBy(res.locals.user); |
|
|
@ -60,7 +71,9 @@ app.get('/problems', async (req, res) => { |
|
|
|
res.render('problems', { |
|
|
|
res.render('problems', { |
|
|
|
allowedManageTag: res.locals.user && await res.locals.user.hasPrivilege('manage_problem_tag'), |
|
|
|
allowedManageTag: res.locals.user && await res.locals.user.hasPrivilege('manage_problem_tag'), |
|
|
|
problems: problems, |
|
|
|
problems: problems, |
|
|
|
paginate: paginate |
|
|
|
paginate: paginate, |
|
|
|
|
|
|
|
curSort: sort, |
|
|
|
|
|
|
|
curOrder: order === 'asc' |
|
|
|
}); |
|
|
|
}); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
syzoj.log(e); |
|
|
|
syzoj.log(e); |
|
|
@ -552,11 +565,11 @@ async function setPublic(req, res, is_public) { |
|
|
|
err: e |
|
|
|
err: e |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
app.post('/problem/:id/public', async (req, res) => { |
|
|
|
app.post('/problem/:id/public', async (req, res) => { |
|
|
|
await setPublic(req, res, true); |
|
|
|
await setPublic(req, res, true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
app.post('/problem/:id/dis_public', async (req, res) => { |
|
|
|
app.post('/problem/:id/dis_public', async (req, res) => { |
|
|
|
await setPublic(req, res, false); |
|
|
|
await setPublic(req, res, false); |
|
|
|