mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
训练(题单)功能
This commit is contained in:
1 parent
e06283c0cc
commit
97b0d782b9
24 files changed
+466
-105
No files matched your search
@@ -34,6 +34,7 @@ async function run() {
|
||||
require('./handler/judge');
|
||||
require('./handler/user');
|
||||
require('./handler/contest');
|
||||
require('./handler/training');
|
||||
server.start();
|
||||
}
|
||||
process.on('restart', async () => {
|
||||
|
||||
+7
-6
@@ -118,6 +118,12 @@ class ContestScoreboardHiddenError extends ForbiddenError {
|
||||
this.params = [tid];
|
||||
}
|
||||
}
|
||||
class TrainingAlreadyEnrollError extends ForbiddenError {
|
||||
constructor(tid, uid) {
|
||||
super("You've already enrolled this training.");
|
||||
this.params = [tid, uid];
|
||||
}
|
||||
}
|
||||
class ProblemNotFoundError extends NotFoundError {
|
||||
constructor(pid) {
|
||||
super('ProblemNotFoundError');
|
||||
@@ -180,6 +186,7 @@ module.exports = {
|
||||
ContestAlreadyAttendedError,
|
||||
UserFacingError,
|
||||
SystemError,
|
||||
TrainingAlreadyEnrollError,
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -337,12 +344,6 @@ class TrainingRequirementNotSatisfiedError(ForbiddenError):
|
||||
return 'Training requirement is not satisfied.'
|
||||
|
||||
|
||||
class TrainingAlreadyEnrollError(ForbiddenError):
|
||||
@property
|
||||
def message(self):
|
||||
return "You've already enrolled this training."
|
||||
|
||||
|
||||
class UsageExceededError(ForbiddenError):
|
||||
@property
|
||||
def message(self):
|
||||
|
||||
@@ -300,7 +300,7 @@ class ProblemSolutionReplyRawHandler extends ProblemDetailHandler {
|
||||
async get({ psid }) {
|
||||
this.checkPerm(PERM_VIEW_PROBLEM_SOLUTION);
|
||||
const [psdoc, psrdoc] = await solution.getReply(psid);
|
||||
if ((!psdoc) || psdoc.pid != this.pdoc._id) throw new SolutionNotFoundError(psid);
|
||||
if ((!psdoc) || psdoc.pid !== this.pdoc._id) throw new SolutionNotFoundError(psid);
|
||||
this.response.type = 'text/markdown';
|
||||
this.response.body = psrdoc.content;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,9 @@ class RecordDetailHandler extends Handler {
|
||||
this.response.template = 'record_detail.html';
|
||||
const rdoc = await record.get(rid);
|
||||
if (rdoc.hidden) this.checkPerm(PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
|
||||
if (rdoc.uid !== this.user.uid && !this.user.hasPerm(PERM_READ_RECORD_CODE)) rdoc.code = null;
|
||||
if (rdoc.uid !== this.user.uid && !this.user.hasPerm(PERM_READ_RECORD_CODE)) {
|
||||
rdoc.code = null;
|
||||
}
|
||||
this.response.body = {
|
||||
path: [
|
||||
['Hydro', '/'],
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
const assert = require('assert');
|
||||
const { ValidationError, ProblemNotFoundError } = require('../error');
|
||||
const {
|
||||
PERM_LOGGEDIN, PERM_VIEW_TRAINING, PERM_VIEW_PROBLEM_HIDDEN,
|
||||
PERM_CREATE_TRAINING, PERM_EDIT_TRAINING,
|
||||
} = require('../permission');
|
||||
const { constants } = require('../options');
|
||||
const paginate = require('../lib/paginate');
|
||||
const problem = require('../model/problem');
|
||||
const builtin = require('../model/builtin');
|
||||
const training = require('../model/training');
|
||||
const user = require('../model/user');
|
||||
const { Route, Handler } = require('../service/server');
|
||||
|
||||
async function _parseDagJson(dag) {
|
||||
const parsed = [];
|
||||
try {
|
||||
dag = JSON.parse(dag);
|
||||
assert(dag instanceof Array, 'dag must be an array');
|
||||
const ids = new Set(dag.map((s) => s._id));
|
||||
assert(dag.length === ids.size, '_id must be unique');
|
||||
for (const node of dag) {
|
||||
assert(node._id, 'each node should have a _id');
|
||||
assert(node.title, 'each node shoule have a title');
|
||||
assert(node.requireNids instanceof Array);
|
||||
assert(node.pids instanceof Array);
|
||||
assert(node.pids.length);
|
||||
for (const nid of node.requireNids) {
|
||||
assert(ids.has(nid), `required nid ${nid} not found`);
|
||||
}
|
||||
for (const i in node.pids) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const pdoc = await problem.get(node.pids[i]); // FIXME no-await-in-loop
|
||||
assert(pdoc, `Problem not found: ${node.pids[i]}`);
|
||||
node.pids[i] = pdoc._id;
|
||||
}
|
||||
const newNode = {
|
||||
_id: parseInt(node._id),
|
||||
title: node.title,
|
||||
requireNids: Array.from(new Set(node.requireNids)),
|
||||
pids: Array.from(new Set(node.pids)),
|
||||
};
|
||||
parsed.push(newNode);
|
||||
}
|
||||
} catch (e) {
|
||||
throw new ValidationError('dag');
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
class TrainingHandler extends Handler {
|
||||
async _prepare() {
|
||||
this.checkPerm(PERM_VIEW_TRAINING);
|
||||
}
|
||||
}
|
||||
|
||||
class TrainingMainHandler extends TrainingHandler {
|
||||
async get({ sort, page }) {
|
||||
const qs = sort ? 'sort={0}'.format(sort) : '';
|
||||
const [tdocs, tpcount] = await paginate(
|
||||
training.getMulti().sort('_id', 1),
|
||||
page,
|
||||
constants.TRAINING_PER_PAGE,
|
||||
);
|
||||
const tids = new Set();
|
||||
for (const tdoc of tdocs) tids.add(tdoc._id);
|
||||
const tsdict = {};
|
||||
let tdict = {};
|
||||
if (this.user.hasPerm(PERM_LOGGEDIN)) {
|
||||
const enrolledTids = new Set();
|
||||
const tsdocs = await training.getMultiStatus({
|
||||
uid: this.user._id,
|
||||
$or: [{ _id: { $in: Array.from(tids) } }, { enroll: 1 }],
|
||||
}).toArray();
|
||||
for (const tsdoc of tsdocs) {
|
||||
tsdict[tsdoc._id] = tsdoc;
|
||||
enrolledTids.add(tsdoc._id);
|
||||
}
|
||||
for (const tid of tids) enrolledTids.delete(tid);
|
||||
if (enrolledTids.size) tdict = await training.getList(Array.from(enrolledTids));
|
||||
}
|
||||
for (const tdoc in tdocs) tdict[tdoc._id] = tdoc;
|
||||
this.response.template = 'training_main.html';
|
||||
this.response.body = {
|
||||
tdocs, page, tpcount, qs, tsdict, tdict,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class TrainingDetailHandler extends TrainingHandler {
|
||||
async get({ tid }) {
|
||||
const tdoc = await training.get(tid);
|
||||
const pids = training.getPids(tdoc);
|
||||
// TODO(twd2): check status, eg. test, hidden problem, ...
|
||||
const f = this.user.hasPerm(PERM_VIEW_PROBLEM_HIDDEN) ? {} : { hidden: false };
|
||||
const [udoc, pdict] = await Promise.all([
|
||||
user.getById(tdoc.owner),
|
||||
problem.getList(pids, f),
|
||||
]);
|
||||
const psdict = await problem.getListStatus(this.user._id, Object.keys(pdict));
|
||||
const donePids = new Set();
|
||||
const progPids = new Set();
|
||||
for (const pid in psdict) {
|
||||
const psdoc = psdict[pid];
|
||||
if (psdoc.status) {
|
||||
if (psdoc.status === builtin.status.STATUS_ACCEPTED) donePids.add(pid);
|
||||
else progPids.add(pid);
|
||||
}
|
||||
}
|
||||
const nsdict = {};
|
||||
const ndict = {};
|
||||
const doneNids = new Set();
|
||||
for (const node of tdoc.dag) {
|
||||
ndict[node._id] = node;
|
||||
const totalCount = node.pids.length;
|
||||
const doneCount = Set.union(new Set(node.pids), new Set(donePids));
|
||||
const nsdoc = {
|
||||
progress: totalCount ? parseInt(100 * (doneCount / totalCount)) : 100,
|
||||
isDone: training.isDone(node, doneNids, donePids),
|
||||
isProgress: training.isProgress(node, doneNids, donePids, progPids),
|
||||
isOpen: training.isOpen(node, doneNids, donePids, progPids),
|
||||
isInvalid: training.isInvalid(node, doneNids),
|
||||
};
|
||||
if (nsdoc.isDone) doneNids.add(node._id);
|
||||
nsdict[node._id] = nsdoc;
|
||||
}
|
||||
const tsdoc = await training.setStatus(tdoc._id, this.user._id, {
|
||||
doneNids: Array.from(doneNids),
|
||||
donePids: Array.from(donePids),
|
||||
done: doneNids.size === tdoc.dag.length,
|
||||
});
|
||||
const path = [
|
||||
['training_main', 'training_main'],
|
||||
[tdoc.title, null, true],
|
||||
];
|
||||
this.response.template = 'training_detail.html';
|
||||
this.response.body = {
|
||||
path, tdoc, tsdoc, pids, pdict, psdict, ndict, nsdict, udoc,
|
||||
};
|
||||
}
|
||||
|
||||
async postEnroll({ tid }) {
|
||||
this.checkPerm(PERM_LOGGEDIN);
|
||||
const tdoc = await training.get(tid);
|
||||
await training.enroll(tdoc._id, this.user._id);
|
||||
this.back();
|
||||
}
|
||||
}
|
||||
|
||||
class TrainingCreateHandler extends TrainingHandler {
|
||||
async prepare() {
|
||||
this.checkPerm(PERM_LOGGEDIN);
|
||||
this.checkPerm(PERM_CREATE_TRAINING);
|
||||
}
|
||||
|
||||
async get() {
|
||||
this.response.template = 'training_edit.html';
|
||||
this.response.body = { page_name: 'training_create' };
|
||||
}
|
||||
|
||||
async post({
|
||||
title, content, dag, description,
|
||||
}) {
|
||||
dag = await _parseDagJson(dag);
|
||||
const pids = training.getPids({ dag });
|
||||
console.log(pids);
|
||||
console.log(pids.length, pids.size);
|
||||
assert(pids.length, new ValidationError('dag'));
|
||||
const pdocs = await problem.getMulti({
|
||||
$or: [{ _id: { $in: pids } }, { pid: { $in: pids } }],
|
||||
}).sort('_id', 1).toArray();
|
||||
const existPids = pdocs.map((pdoc) => pdoc._id);
|
||||
const existPnames = pdocs.map((pdoc) => pdoc.pid);
|
||||
if (pids.length !== existPids.length) {
|
||||
for (const pid in pids) {
|
||||
assert(
|
||||
existPids.includes(pid) || existPnames.includes(pid),
|
||||
new ProblemNotFoundError(pid),
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const pdoc in pdocs) {
|
||||
if (pdoc.hidden) this.checkPerm(PERM_VIEW_PROBLEM_HIDDEN);
|
||||
}
|
||||
const tid = await training.add(title, content, this.user._id, dag, description);
|
||||
this.response.body = { tid };
|
||||
this.response.redirect = `/t/${tid}`;
|
||||
}
|
||||
}
|
||||
|
||||
class TrainingEditHandler extends TrainingHandler {
|
||||
async get({ tid }) {
|
||||
const tdoc = await training.get(tid);
|
||||
if (tdoc.owner !== this.user._id) this.checkPerm(PERM_EDIT_TRAINING);
|
||||
const dag = JSON.stringify(tdoc.dag, null, 2);
|
||||
const path = [
|
||||
['training_main', '/t'],
|
||||
[tdoc.title, `/t/${tdoc._id}`, true],
|
||||
['training_edit', null],
|
||||
];
|
||||
this.response.template = 'training_edit.html';
|
||||
this.response.body = {
|
||||
tdoc, dag, path, page_name: 'training_edit',
|
||||
};
|
||||
}
|
||||
|
||||
async post({
|
||||
tid, title, content, dag, description,
|
||||
}) {
|
||||
const tdoc = await training.get(tid);
|
||||
if (!this.user._id === tdoc.owner) this.checkPerm(PERM_EDIT_TRAINING);
|
||||
dag = await _parseDagJson(dag);
|
||||
const pids = training.getPids({ dag });
|
||||
assert(pids.length, new ValidationError('dag'));
|
||||
const pdocs = await problem.getMulti({
|
||||
$or: [
|
||||
{ _id: { $in: pids } },
|
||||
{ pid: { $in: pids } },
|
||||
],
|
||||
}).sort('_id', 1).toArray();
|
||||
const existPids = pdocs.map((pdoc) => pdoc._id);
|
||||
const existPnames = pdocs.map((pdoc) => pdoc.pid);
|
||||
if (pids.length !== existPids.length) {
|
||||
for (const pid in pids) {
|
||||
assert(
|
||||
existPids.includes(pid) || existPnames.includes(pid),
|
||||
new ProblemNotFoundError(pid),
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const pdoc in pdocs) { if (pdoc.hidden) this.checkPerm(PERM_VIEW_PROBLEM_HIDDEN); }
|
||||
await training.edit(tid, {
|
||||
title, content, dag, description,
|
||||
});
|
||||
this.response.body = { tid };
|
||||
this.response.redirect = `/t/${tid}`;
|
||||
}
|
||||
}
|
||||
|
||||
Route('/t', TrainingMainHandler);
|
||||
Route('/t/:tid', TrainingDetailHandler);
|
||||
Route('/t/:tid/edit', TrainingEditHandler);
|
||||
Route('/training/create', TrainingCreateHandler);
|
||||
@@ -21,6 +21,10 @@ const isName = (s) => s && s.length < 256;
|
||||
const checkName = (s) => { if (!isName(s)) throw new ValidationError('name'); else return s; };
|
||||
const isPid = (s) => RE_PID.test(s.toString());
|
||||
const checkPid = (s) => { if (!RE_PID.test(s)) throw new ValidationError('pid'); else return s; };
|
||||
const isIntro = () => true;
|
||||
const checkIntro = (s) => { if (!isIntro(s)) throw new ValidationError('intro'); else return s; };
|
||||
const isDescription = () => true;
|
||||
const checkDescription = (s) => { if (!isDescription(s)) throw new ValidationError('description'); else return s; };
|
||||
|
||||
module.exports = {
|
||||
isTitle,
|
||||
@@ -39,6 +43,10 @@ module.exports = {
|
||||
checkName,
|
||||
isPid,
|
||||
checkPid,
|
||||
isIntro,
|
||||
checkIntro,
|
||||
isDescription,
|
||||
checkDescription,
|
||||
};
|
||||
/*
|
||||
ID_RE = re.compile(r'[^\\/\s\u3000]([^\\/\n\r]*[^\\/\s\u3000])?')
|
||||
|
||||
@@ -211,7 +211,7 @@ async def recalc_status(domainId: str, doc_type: int, cid: objeccid.Objeccid):
|
||||
tdoc = await document.get(domainId, doc_type, cid)
|
||||
async with document.get_multi_status(domainId=domainId,
|
||||
doc_type=doc_type,
|
||||
doc_id=tdoc['doc_id']) as tsdocs:
|
||||
doc_id=tdoc._id) as tsdocs:
|
||||
async for tsdoc in tsdocs:
|
||||
if 'journal' not in tsdoc or not tsdoc['journal']:
|
||||
continue
|
||||
|
||||
+16
-1
@@ -56,7 +56,7 @@ async function add({
|
||||
async function get(pid, uid = null) {
|
||||
let query = {};
|
||||
if (pid.generationTime || pid.length === 24) query = { _id: new ObjectID(pid) };
|
||||
else query = { pid: parseInt(pid) || pid };
|
||||
else query = { pid };
|
||||
const pdoc = await coll.findOne(query);
|
||||
if (!pdoc) throw new ProblemNotFoundError(pid);
|
||||
if (uid) {
|
||||
@@ -91,6 +91,13 @@ function getMany(query, sort, page, limit) {
|
||||
function getMulti(query) {
|
||||
return coll.find(query);
|
||||
}
|
||||
/**
|
||||
* @param {object} query
|
||||
* @returns {Cursor}
|
||||
*/
|
||||
function getMultiStatus(query) {
|
||||
return collStatus.find(query);
|
||||
}
|
||||
/**
|
||||
* @param {ObjectID} _id
|
||||
* @param {object} query
|
||||
@@ -120,6 +127,12 @@ async function getList(pids) {
|
||||
for (const pid of pids) r[pid] = await get(pid); // eslint-disable-line no-await-in-loop
|
||||
return r;
|
||||
}
|
||||
async function getListStatus(uid, pids) {
|
||||
const psdocs = await getMultiStatus({ uid, pid: { $in: Array.from(new Set(pids)) } }).toArray();
|
||||
const r = {};
|
||||
for (const psdoc of psdocs) r[psdoc.pid] = psdoc;
|
||||
return r;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
add,
|
||||
@@ -131,4 +144,6 @@ module.exports = {
|
||||
getById,
|
||||
getMulti,
|
||||
getList,
|
||||
getListStatus,
|
||||
getMultiStatus,
|
||||
};
|
||||
+74
-41
@@ -1,67 +1,100 @@
|
||||
const assert = require('assert');
|
||||
const validator = require('../lib/validator');
|
||||
const { ValidationError, TrainingNotFoundError } = require('../error');
|
||||
const { ValidationError, TrainingNotFoundError, TrainingAlreadyEnrollError } = require('../error');
|
||||
const db = require('../service/db.js');
|
||||
|
||||
const coll = db.collection('traning');
|
||||
const collStatus = db.collection('training.status');
|
||||
|
||||
module.exports = {
|
||||
SETTING_DIFFICULTY_ALGORITHM: 0,
|
||||
SETTING_DIFFICULTY_ADMIN: 1,
|
||||
SETTING_DIFFICULTY_AVERAGE: 2,
|
||||
async function enroll(tid, uid) {
|
||||
try {
|
||||
await collStatus.insertOne({ tid, uid, enroll: 1 });
|
||||
} catch (e) {
|
||||
throw new TrainingAlreadyEnrollError(tid, uid);
|
||||
}
|
||||
await coll.findOneAndUpdate({ _id: tid }, { $inc: { enroll: 1 } });
|
||||
}
|
||||
async function setStatus(tid, uid, $set) {
|
||||
await collStatus.findOneAndUpdate({ tid, uid }, { $set });
|
||||
return await collStatus.findOne({ tid, uid });
|
||||
}
|
||||
|
||||
async add(title, content, owner, dag = [], desc = '') {
|
||||
module.exports = {
|
||||
getPids(tdoc) {
|
||||
console.log(tdoc.dag);
|
||||
const pids = new Set();
|
||||
for (const node of tdoc.dag) {
|
||||
for (const pid of node.pids) pids.add(pid);
|
||||
}
|
||||
return Array.from(pids);
|
||||
},
|
||||
isDone(node, doneNids, donePids) {
|
||||
return (Set.isSuperset(new Set(doneNids), new Set(node.requireNids))
|
||||
&& Set.isSuperset(new Set(donePids), new Set(node.pids)));
|
||||
},
|
||||
isProgress(node, doneNids, donePids, progPids) {
|
||||
return (Set.isSuperset(new Set(doneNids), new Set(node.requireNids))
|
||||
&& !Set.isSuperset(new Set(donePids), new Set(node.pids))
|
||||
&& Set.intersection(
|
||||
Set.union(new Set(donePids), new Set(progPids)),
|
||||
new Set(node.pids),
|
||||
).size);
|
||||
},
|
||||
isOpen(node, doneNids, donePids, progPids) {
|
||||
return (Set.isSuperset(new Set(doneNids), new Set(node.requireNids))
|
||||
&& !Set.isSuperset(new Set(donePids), new Set(node.pids))
|
||||
&& !Set.intersection(
|
||||
Set.union(new Set(donePids), new Set(progPids)),
|
||||
new Set(node.pids),
|
||||
).size);
|
||||
},
|
||||
isInvalid(node, doneNids) {
|
||||
return (!Set.isSuperset(new Set(doneNids), new Set(node.requireNids)));
|
||||
},
|
||||
async add(title, content, owner, dag = [], description = '') {
|
||||
validator.checkTitle(title);
|
||||
validator.checkIntro(content);
|
||||
validator.checkDescription(desc);
|
||||
for (const node of dag) { for (const nid of node.require_nids) if (nid >= node._id) throw new ValidationError('dag'); }
|
||||
return await coll.insertOne({
|
||||
validator.checkDescription(description);
|
||||
for (const node of dag) {
|
||||
for (const nid of node.requireNids) {
|
||||
if (nid >= node._id) throw new ValidationError('dag');
|
||||
}
|
||||
}
|
||||
const res = await coll.insertOne({
|
||||
content,
|
||||
owner,
|
||||
dag,
|
||||
title,
|
||||
desc,
|
||||
description,
|
||||
enroll: 0,
|
||||
});
|
||||
return res.insertedId;
|
||||
},
|
||||
count: (query) => coll.find(query).count(),
|
||||
async edit(tid, $set) {
|
||||
if ($set.title) validator.check_title($set.title);
|
||||
if ($set.content) validator.check_intro($set.content);
|
||||
if ($set.desc) validator.check_description($set.desc);
|
||||
if ($set.dag) { for (const node of $set.dag) for (const nid of node.require_nids) if (nid >= node._id) throw new ValidationError('dag'); }
|
||||
await coll.findOneAndUpdate({ tid }, { $set });
|
||||
const tdoc = await coll.findOne({ tid });
|
||||
if ($set.title) validator.checkTitle($set.title);
|
||||
if ($set.content) validator.checkIntro($set.content);
|
||||
if ($set.desc) validator.checkDescription($set.description);
|
||||
if ($set.dag) {
|
||||
for (const node of $set.dag) {
|
||||
for (const nid of node.requireNids) {
|
||||
assert(nid >= node._id, new ValidationError('dag'));
|
||||
}
|
||||
}
|
||||
}
|
||||
await coll.findOneAndUpdate({ _id: tid }, { $set });
|
||||
const tdoc = await coll.findOne({ _id: tid });
|
||||
if (!tdoc) throw new TrainingNotFoundError(tid);
|
||||
return tdoc;
|
||||
},
|
||||
async get(tid) {
|
||||
const tdoc = await coll.findOne({ tid });
|
||||
const tdoc = await coll.findOne({ _id: tid });
|
||||
if (!tdoc) throw new TrainingNotFoundError(tid);
|
||||
return tdoc;
|
||||
},
|
||||
get_multi: (query) => coll.find(query),
|
||||
get_multi_status: (query) => collStatus.find(query),
|
||||
get_status: (tid, uid) => collStatus.findOne({ tid, uid }),
|
||||
set_status: (tid, uid, $set) => collStatus.findOneAndUpdate({ tid, uid }, { $set }),
|
||||
|
||||
getMulti: (query) => coll.find(query),
|
||||
getMultiStatus: (query) => collStatus.find(query),
|
||||
getStatus: (tid, uid) => collStatus.findOne({ tid, uid }),
|
||||
enroll,
|
||||
setStatus,
|
||||
};
|
||||
|
||||
/*
|
||||
async def get_dict_status(domainId, uid, tids, *, fields=None):
|
||||
result = dict()
|
||||
async for tsdoc in get_multi_status(domainId=domainId,
|
||||
uid=uid,
|
||||
doc_id={'$in': list(set(tids))},
|
||||
fields=fields):
|
||||
result[tsdoc['doc_id']] = tsdoc
|
||||
return result
|
||||
|
||||
async def get_dict(domainId, tids, *, fields=None):
|
||||
result = dict()
|
||||
async for tdoc in get_multi(domainId=domainId,
|
||||
doc_id={'$in': list(set(tids))},
|
||||
fields=fields):
|
||||
result[tdoc['doc_id']] = tdoc
|
||||
return result
|
||||
*/
|
||||
@@ -42,6 +42,7 @@ let options = {
|
||||
RECORD_PER_PAGE: 100,
|
||||
SOLUTION_PER_PAGE: 20,
|
||||
CONTEST_PER_PAGE: 20,
|
||||
TRAINING_PER_PAGE: 10,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -259,9 +259,9 @@ function Route(route, RouteHandler) {
|
||||
if (h[method]) await h[method](args);
|
||||
|
||||
if (method === 'post' && ctx.request.body.operation) {
|
||||
if (h[`${method}_${ctx.request.body.operation}`]) {
|
||||
await h[`${method}_${ctx.request.body.operation}`](args);
|
||||
}
|
||||
const operation = `_${ctx.request.body.operation}`
|
||||
.replace(/_([a-z])/gm, (s) => s[1].toUpperCase());
|
||||
if (h[`${method}${operation}`]) await h[`${method}${operation}`](args);
|
||||
}
|
||||
|
||||
if (h.cleanup) await h.cleanup(args);
|
||||
|
||||
@@ -36,3 +36,22 @@ Date.prototype.format = function formatDate(fmt = '%Y-%m-%d %H:%M:%S') {
|
||||
.replace('%M', this.getMinutes())
|
||||
.replace('%S', this.getSeconds());
|
||||
};
|
||||
|
||||
Set.isSuperset = function isSuperset(set, subset) {
|
||||
for (const elem of subset) {
|
||||
if (!set.has(elem)) return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
Set.union = function union(setA, setB) {
|
||||
const _union = new Set(setA);
|
||||
for (const elem of setB) _union.add(elem);
|
||||
return _union;
|
||||
};
|
||||
Set.intersection = function intersection(setA, setB) {
|
||||
const _intersection = new Set();
|
||||
for (const elem of setB) {
|
||||
if (setA.has(elem)) _intersection.add(elem);
|
||||
}
|
||||
return _intersection;
|
||||
};
|
||||
Reference in new issue
Block a user