diff --git a/modules/problem.js b/modules/problem.js index fdc9712..d9a7147 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -169,6 +169,7 @@ app.get('/problem/:id/edit', async (req, res) => { problem.id = id; problem.allowedEdit = true; problem.tags = []; + problem.new = true; } else { if (!await problem.isAllowedUseBy(res.locals.user)) throw 'Permission denied.'; problem.allowedEdit = await problem.isAllowedEditBy(res.locals.user); @@ -192,7 +193,13 @@ app.post('/problem/:id/edit', async (req, res) => { let problem = await Problem.fromID(id); if (!problem) { problem = await Problem.create(); - if (id) problem.id = id; + + let customID = parseInt(req.body.id); + if (customID) { + if (await Problem.fromID(customID)) throw 'The ID has been used.'; + problem.id = customID; + } else if (id) problem.id = id; + problem.user_id = res.locals.user.id; } else { if (!await problem.isAllowedUseBy(res.locals.user)) throw 'Permission denied.'; @@ -234,6 +241,7 @@ app.get('/problem/:id/import', async (req, res) => { if (!problem) { problem = await Problem.create(); problem.id = id; + problem.new = true; problem.user_id = res.locals.user.id; } else { if (!await problem.isAllowedUseBy(res.locals.user)) throw 'Permission denied.'; @@ -257,7 +265,13 @@ app.post('/problem/:id/import', async (req, res) => { let problem = await Problem.fromID(id); if (!problem) { problem = await Problem.create(); - if (id) problem.id = id; + + let customID = parseInt(req.body.id); + if (customID) { + if (await Problem.fromID(customID)) throw 'The ID has been used.'; + problem.id = customID; + } else if (id) problem.id = id; + problem.user_id = res.locals.user.id; } else { if (!await problem.isAllowedUseBy(res.locals.user)) throw 'Permission denied.'; diff --git a/views/problem_edit.ejs b/views/problem_edit.ejs index 8180ea4..30ce9e5 100644 --- a/views/problem_edit.ejs +++ b/views/problem_edit.ejs @@ -13,7 +13,9 @@
- + + > + diff --git a/views/problem_import.ejs b/views/problem_import.ejs index 45b20a5..1570f34 100644 --- a/views/problem_import.ejs +++ b/views/problem_import.ejs @@ -1,11 +1,15 @@ <% this.title = '导入题目'; %> <% include header %>
-

导入题目

+
+

导入题目

+ 从另一个运行 SYZOJ 的网站导入题目。 +
+
- - + + >