mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
v2.5.0
This commit is contained in:
1 parent
0de7cd7b59
commit
7d7b12392f
18 files changed
+90
-47
No files matched your search
@@ -25,7 +25,7 @@ const builtinHandler = [
|
||||
];
|
||||
|
||||
const builtinScript = [
|
||||
'install', 'uninstall', 'rating', 'recalcRating', 'register',
|
||||
'install', 'rating', 'recalcRating', 'register', 'problemStat',
|
||||
'blacklist', 'setSuperadmin', 'deleteUser',
|
||||
];
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ async function add(domainId, data, addTask = true) {
|
||||
time: 0,
|
||||
memory: 0,
|
||||
hidden: false,
|
||||
rejudged: false,
|
||||
judgeTexts: [],
|
||||
compilerTexts: [],
|
||||
testCases: [],
|
||||
|
||||
@@ -37,9 +37,9 @@ async function add(tokenType, expireSeconds, data) {
|
||||
* @param {number} tokenType type of the token.
|
||||
* @returns {Promise<object>} The token document, or null.
|
||||
*/
|
||||
async function get(tokenId, tokenType) {
|
||||
async function get(tokenId, tokenType, doThrow = true) {
|
||||
const res = await coll.findOne({ _id: tokenId, tokenType });
|
||||
if (!res) throw new ValidationError('token');
|
||||
if (!res && doThrow) throw new ValidationError('token');
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Add blacklist by ip, uid';
|
||||
|
||||
// This code format is just for fun. DO NOT DO THIS IN YOUR CODE !
|
||||
/* eslint-disable */
|
||||
const { ObjectID } = require('bson');
|
||||
@@ -61,4 +63,4 @@ async function run({address = null, discuss = null, user = null, dryrun = true},
|
||||
if (user)
|
||||
await _user(user, new Set(), new Set(), new Set(), dryrun, report) }
|
||||
|
||||
global.Hydro.script.blacklist = module.exports = { run };
|
||||
global.Hydro.script.blacklist = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Delete a user';
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
const user = require('../model/user');
|
||||
const document = require('../model/document');
|
||||
@@ -85,4 +87,4 @@ async function run({
|
||||
return uid;
|
||||
}
|
||||
|
||||
global.Hydro.script.deleteUser = module.exports = { run };
|
||||
global.Hydro.script.deleteUser = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Install';
|
||||
|
||||
const { defaults } = require('lodash');
|
||||
const db = require('../service/db');
|
||||
const { PRIV_ALL } = require('../model/builtin').PRIV;
|
||||
@@ -66,4 +68,4 @@ async function run({ username, password } = {}) {
|
||||
await Promise.all(tasks);
|
||||
}
|
||||
|
||||
global.Hydro.script.install = module.exports = { run };
|
||||
global.Hydro.script.install = module.exports = { run, description };
|
||||
@@ -0,0 +1,47 @@
|
||||
const description = 'Recalcuates nSubmit and nAccept in problem status.';
|
||||
|
||||
const db = require('../service/db');
|
||||
const { STATUS_ACCEPTED } = require('../model/builtin').STATUS;
|
||||
const document = require('../model/document');
|
||||
|
||||
async function run() {
|
||||
const pipeline = [
|
||||
{
|
||||
$match: { hidden: false, type: { $ne: 'run' } },
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
|
||||
nSubmit: { $sum: 1 },
|
||||
nAccept: {
|
||||
$sum: {
|
||||
$cond: [{ $eq: ['$status', STATUS_ACCEPTED] }, 1, 0],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: { domainId: '$_id.domainId', pid: '$_id.pid' },
|
||||
nSubmit: { $sum: '$nSubmit' },
|
||||
nAccept: { $sum: { $min: ['$nAccept', 1] } },
|
||||
},
|
||||
},
|
||||
];
|
||||
const bulk = db.collection('document').initializeUnorderedBulkOp();
|
||||
db.collection('record').aggregate(pipeline).forEach(
|
||||
(adoc) => bulk.find({
|
||||
domainId: adoc._id.domainId,
|
||||
docType: document.TYPE_PROBLEM,
|
||||
docId: adoc._id.pid,
|
||||
}).updateOne({
|
||||
$set: {
|
||||
nSubmit: adoc.nSubmit,
|
||||
nAccept: adoc.nAccept,
|
||||
},
|
||||
}),
|
||||
);
|
||||
await bulk.execute();
|
||||
}
|
||||
|
||||
global.Hydro.script.problemStat = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Calculate the rating of a contest';
|
||||
|
||||
const { ObjectID } = require('bson');
|
||||
const contest = require('../model/contest');
|
||||
const user = require('../model/user');
|
||||
@@ -18,4 +20,4 @@ async function run({ domainId, contestId }) {
|
||||
return rated;
|
||||
}
|
||||
|
||||
global.Hydro.script.rating = module.exports = { run };
|
||||
global.Hydro.script.rating = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Calculate rating of a domain, or all domains';
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
const domain = require('../model/domain');
|
||||
const contest = require('../model/contest');
|
||||
@@ -64,4 +66,4 @@ async function run({ domainId, isSub = false }, report) {
|
||||
return true;
|
||||
}
|
||||
|
||||
global.Hydro.script.recalcRating = module.exports = { run };
|
||||
global.Hydro.script.recalcRating = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Create a new user';
|
||||
|
||||
const user = require('../model/user');
|
||||
const system = require('../model/system');
|
||||
|
||||
@@ -13,4 +15,4 @@ async function run({
|
||||
return uid;
|
||||
}
|
||||
|
||||
global.Hydro.script.register = module.exports = { run };
|
||||
global.Hydro.script.register = module.exports = { run, description };
|
||||
@@ -1,3 +1,5 @@
|
||||
const description = 'Set a user as superadmin.';
|
||||
|
||||
const user = require('../model/user');
|
||||
const { PRIV_ALL } = require('../model/builtin').PRIV;
|
||||
|
||||
@@ -10,4 +12,4 @@ async function run({
|
||||
return uid;
|
||||
}
|
||||
|
||||
global.Hydro.script.setSuperadmin = module.exports = { run };
|
||||
global.Hydro.script.setSuperadmin = module.exports = { run, description };
|
||||
@@ -1,8 +0,0 @@
|
||||
const db = require('../service/db.js');
|
||||
|
||||
async function run() {
|
||||
await db.dropDatabase();
|
||||
console.log('Dropped');
|
||||
}
|
||||
|
||||
global.Hydro.script.uninstall = module.exports = { run };
|
||||
@@ -284,7 +284,7 @@ class Handler {
|
||||
}
|
||||
|
||||
async checkCsrfToken(csrfToken) {
|
||||
const sdoc = await token.get(csrfToken, token.TYPE_CSRF_TOKEN);
|
||||
const sdoc = await token.get(csrfToken, token.TYPE_CSRF_TOKEN, false);
|
||||
if (!sdoc || sdoc.uid !== this.user._id) throw new CsrfTokenError(csrfToken);
|
||||
}
|
||||
|
||||
@@ -429,12 +429,7 @@ async function handle(ctx, HandlerClass, checker) {
|
||||
if (h[`__${method}`]) await h[`__${method}`](args);
|
||||
if (h[`_${method}`]) await h[`_${method}`](args);
|
||||
if (h[method]) await h[method](args);
|
||||
|
||||
if (method === 'post' && ctx.request.body.operation) {
|
||||
const operation = `_${ctx.request.body.operation}`
|
||||
.replace(/_([a-z])/gm, (s) => s[1].toUpperCase());
|
||||
if (h[`${method}${operation}`]) await h[`${method}${operation}`](args);
|
||||
}
|
||||
if (operation) await h[`post${operation}`](args);
|
||||
|
||||
if (h.cleanup) await h.cleanup(args);
|
||||
if (h._cleanup) await h._cleanup(args);
|
||||
|
||||
Reference in new issue
Block a user