题目编辑,测试数据上传,评测记录

This commit is contained in:
masnn committed 2020-04-09 21:43:16 +08:00
1 parent 6e28dd868e
commit f055d79fef
9 files changed
+76 -32

No files matched your search

+5 -2
View File
@@ -2,6 +2,7 @@ const
{ requirePerm } = require('./tools'),
{ PERM_JUDGE } = require('../permission'),
record = require('../model/record'),
problem = require('../model/problem'),
bus = require('../service/bus'),
queue = require('../service/queue'),
{ GET, POST } = require('../service/server');
@@ -15,11 +16,12 @@ GET('/judge/fetch', requirePerm(PERM_JUDGE), async ctx => {
let rid = await queue.get('judge', false);
if (rid) {
let rdoc = await record.get(rid);
let pdoc = await problem.getById(rdoc.pid);
let task = {
event: 'judge',
rid, type: 0,
pid: rdoc.pid,
data: rdoc.data,
data: pdoc.data,
lang: rdoc.lang,
code: rdoc.code
};
@@ -28,6 +30,7 @@ GET('/judge/fetch', requirePerm(PERM_JUDGE), async ctx => {
else ctx.body = {};
});
POST('/judge/next', requirePerm(PERM_JUDGE), async ctx => {
console.log(ctx.request.body);
let body = ctx.request.body;
let rdoc = await record.get(body.rid);
let $set = {};
@@ -40,7 +43,7 @@ POST('/judge/next', requirePerm(PERM_JUDGE), async ctx => {
$set.judgeTexts = rdoc.judgeTexts;
}
if (body.compiler_text) {
rdoc.compilerTexts.push(body.compilerTexts);
rdoc.compilerTexts.push(body.compiler_text);
$set.compilerTexts = rdoc.compilerTexts;
}
if (body.status) $set.status = body.status;
+33 -5
View File
@@ -80,11 +80,12 @@ GET('/p/:pid/submit', requirePerm(PERM_SUBMIT_PROBLEM), async ctx => {
};
});
POST('/p/:pid/submit', requirePerm(PERM_SUBMIT_PROBLEM), async ctx => {
let pdoc = await problem.get({ pid: ctx.params.pid });
let rid = await record.add({
uid: ctx.state.user._id,
lang: ctx.request.body.lang,
code: ctx.request.body.code,
pid: ctx.params.pid
pid: pdoc._id
});
await queue.push('judge', rid);
ctx.state.user.nSubmit++;
@@ -94,7 +95,7 @@ POST('/p/:pid/submit', requirePerm(PERM_SUBMIT_PROBLEM), async ctx => {
GET('/p/:pid/settings', async ctx => {
ctx.templateName = 'problem_settings.html';
let pdoc = await problem.get({ pid: ctx.params.pid, uid: ctx.state.user._id });
if (pdoc.hidden) ctx.checkPerm(PERM_VIEW_PROBLEM_HIDDEN);
if (pdoc.owner != ctx.state.user._id) ctx.checkPerm(PERM_EDIT_PROBLEM);
ctx.body = {
path: [
['Hydro', '/'],
@@ -109,12 +110,36 @@ POST('/p/:pid/settings', async ctx => {
// TODO(masnn)
ctx.back();
});
GET('/p/:pid/edit', async ctx => {
ctx.templateName = 'problem_edit.html';
let pdoc = await problem.get({ pid: ctx.params.pid, uid: ctx.state.user._id });
if (pdoc.owner != ctx.state.user._id) ctx.checkPerm(PERM_EDIT_PROBLEM);
ctx.body = {
path: [
['Hydro', '/'],
['problem_main', '/p'],
[pdoc.title, `/p/${ctx.params.pid}`, true],
['problem_edit', null]
],
pdoc, page_name: 'problem_edit'
};
});
POST('/p/:pid/edit', async ctx => {
let title = validator.checkTitle(ctx.request.body.title);
let content = validator.checkContent(ctx.request.body.content);
let pid = validator.checkPid(ctx.request.body.pid);
let pdoc = await problem.get({ pid: ctx.params.pid });
await problem.edit(pdoc._id, {
title, content, pid
});
ctx.setRedirect = `/p/${pid}`;
});
GET('/p/:pid/upload', async ctx => {
ctx.templateName = 'problem_upload.html';
let pdoc = await problem.get({ pid: ctx.params.pid, uid: ctx.state.user._id });
if (pdoc.owner != ctx.state.user._id) ctx.checkPerm(PERM_EDIT_PROBLEM);
let md5;
if (typeof pdoc.data == 'object') {
if (pdoc.data && typeof pdoc.data == 'object') {
let files = await gridfs.find({ _id: pdoc.data }).toArray();
md5 = files[0].md5;
}
@@ -133,11 +158,14 @@ POST('/p/:pid/upload', async ctx => {
f.once('error', reject);
});
let md5;
if (typeof pdoc.data == 'object') {
if (pdoc.data && typeof pdoc.data == 'object') {
gridfs.delete(pdoc.data);
}
pdoc = await problem.edit(pdoc._id, { data: f.id });
if (pdoc.data && typeof pdoc.data == 'object') {
let files = await gridfs.find({ _id: pdoc.data }).toArray();
md5 = files[0].md5;
}
pdoc = await problem.edit(ctx.params.pid, { data: f.id });
ctx.body = { pdoc, md5 };
});
GET('/p/:pid/data', async ctx => {
+4 -1
View File
@@ -128,7 +128,10 @@ MIDDLEWARE(async (ctx, next) => {
} else {
throw new NotFoundError();
}
} catch (error) {
} catch (e) {
let error;
if (ctx.body && ctx.body.error) error = ctx.body.error;
else error = e;
if (error instanceof NotFoundError) ctx.status = 404;
if (error.toString().startsWith('NotFoundError')) console.log(error);
if (error.toString().startsWith('Template render error')) throw error;