mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +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);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"id": "migrate-vijos",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"description": "Migrate From Vijos"
|
||||
}
|
||||
@@ -170,7 +170,7 @@ const tasks = {
|
||||
judgeText: (c.judge_text || '') + (c.message || ''),
|
||||
});
|
||||
}
|
||||
return {
|
||||
const rdoc = {
|
||||
_id: doc._id,
|
||||
status: doc.status,
|
||||
score: doc.score,
|
||||
@@ -180,16 +180,17 @@ const tasks = {
|
||||
lang: doc.lang,
|
||||
uid: doc.uid,
|
||||
pid: pid(doc.pid),
|
||||
tid: doc.tid,
|
||||
domainId: doc.domain_id,
|
||||
judger: doc.judge_uid,
|
||||
judgeAt: doc.judge_at,
|
||||
judgeTexts: doc.judge_texts,
|
||||
compilerTexts: doc.compiler_texts,
|
||||
rejudged: doc.rejudged,
|
||||
testCases,
|
||||
hidden: doc.hidden,
|
||||
};
|
||||
if (doc.rejudged) rdoc.rejudged = true;
|
||||
if (doc.tid) rdoc.tid = doc.tid;
|
||||
return rdoc;
|
||||
},
|
||||
domain: {
|
||||
_id: '_id',
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.4.3",
|
||||
"version": "2.5.0",
|
||||
"main": "hydro/loader.js",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
"author": "masnn",
|
||||
@@ -31,7 +31,7 @@
|
||||
"nodemailer": "^6.4.10",
|
||||
"nunjucks": "^3.2.1",
|
||||
"prismjs": "^1.20.0",
|
||||
"snyk": "^1.348.1",
|
||||
"snyk": "^1.354.0",
|
||||
"sockjs": "^0.3.20",
|
||||
"superagent": "^5.2.2",
|
||||
"superagent-proxy": "^2.0.0",
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<input type="checkbox" name="rememberme">{{ _('Remember me') }}
|
||||
</label>
|
||||
</div></div>
|
||||
<input type="hidden" name="csrfToken" value="{{ handler.csrfToken }}">
|
||||
<div class="row"><div class="columns">
|
||||
<a href="{{ url('user_oauth', type='github') }}" class="expanded rounded button">{{ _('Login with Github') }}</a>
|
||||
</div></div>
|
||||
|
||||
@@ -2773,11 +2773,6 @@ ip@1.1.5, ip@^1.1.5:
|
||||
resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a"
|
||||
integrity sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo=
|
||||
|
||||
ipaddr.js@^1.9.1:
|
||||
version "1.9.1"
|
||||
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz#bff38543eeb8984825079ff3a2a8e6cbd46781b3"
|
||||
integrity sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==
|
||||
|
||||
is-accessor-descriptor@^0.1.6:
|
||||
version "0.1.6"
|
||||
resolved "https://registry.yarnpkg.com/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz#a9e12cb3ae8d876727eeef3843f8a0897b5c98d6"
|
||||
@@ -5040,10 +5035,10 @@ snyk-go-plugin@1.14.2:
|
||||
tmp "0.1.0"
|
||||
tslib "^1.10.0"
|
||||
|
||||
snyk-gradle-plugin@3.5.0:
|
||||
version "3.5.0"
|
||||
resolved "https://registry.yarnpkg.com/snyk-gradle-plugin/-/snyk-gradle-plugin-3.5.0.tgz#6e3280ef8b4965978fa7cd4664480b23234e1049"
|
||||
integrity sha512-zOHr3802bDKCcSAFfoEvt/wGSaOSGRm6yQjikdo1RTz7jTeQnSMJxCFYTOhfpu9Tka4d5q0TsdI/2VLFAvPKhA==
|
||||
snyk-gradle-plugin@3.5.1:
|
||||
version "3.5.1"
|
||||
resolved "https://registry.yarnpkg.com/snyk-gradle-plugin/-/snyk-gradle-plugin-3.5.1.tgz#a424a7b8136471296e971e7b25f4776d1a08b9ff"
|
||||
integrity sha512-8tZwQCqRbjp1azvc+bBRXSbn2AjbUpFAM6qoSpM/IZpfGl1RaOtz4/JTkGFxj+iBhTFoAkGxEunT66eO0pHZZw==
|
||||
dependencies:
|
||||
"@snyk/cli-interface" "2.8.0"
|
||||
"@snyk/dep-graph" "^1.17.0"
|
||||
@@ -5217,10 +5212,10 @@ snyk-try-require@1.3.1, snyk-try-require@^1.1.1, snyk-try-require@^1.3.1:
|
||||
lru-cache "^4.0.0"
|
||||
then-fs "^2.0.0"
|
||||
|
||||
snyk@^1.348.1:
|
||||
version "1.349.0"
|
||||
resolved "https://registry.yarnpkg.com/snyk/-/snyk-1.349.0.tgz#b29ea17037f7bc5ff29ac4a4c3227fe412fe23cb"
|
||||
integrity sha512-2gE31HJ42H2gYDci9WB+f1GOTNLQXIcO5jm7i8sw+Xpfce3FYYH3s0oCecnrDHV3qOXbr6Qa5MtL0bwWmOA3fg==
|
||||
snyk@^1.354.0:
|
||||
version "1.354.0"
|
||||
resolved "https://registry.yarnpkg.com/snyk/-/snyk-1.354.0.tgz#c23dd28177a4d57c4e02d43583ce435873e569d8"
|
||||
integrity sha512-0X3BHsdBfpJPpAVB8e7vlXCi7DfjEkVwSZLjtA5pXWpRCKyuDrVvJl+dctr11eEubbo/bJBDxWsmOnzxsdkTIw==
|
||||
dependencies:
|
||||
"@snyk/cli-interface" "2.8.0"
|
||||
"@snyk/dep-graph" "1.18.3"
|
||||
@@ -5238,7 +5233,6 @@ snyk@^1.348.1:
|
||||
debug "^4.1.1"
|
||||
diff "^4.0.1"
|
||||
glob "^7.1.3"
|
||||
ipaddr.js "^1.9.1"
|
||||
needle "^2.5.0"
|
||||
open "^7.0.3"
|
||||
os-name "^3.0.0"
|
||||
@@ -5248,7 +5242,7 @@ snyk@^1.348.1:
|
||||
snyk-config "3.1.0"
|
||||
snyk-docker-plugin "3.12.3"
|
||||
snyk-go-plugin "1.14.2"
|
||||
snyk-gradle-plugin "3.5.0"
|
||||
snyk-gradle-plugin "3.5.1"
|
||||
snyk-module "3.1.0"
|
||||
snyk-mvn-plugin "2.17.1"
|
||||
snyk-nodejs-lockfile-parser "1.22.0"
|
||||
|
||||
Reference in new issue
Block a user