core: try to fix #121

This commit is contained in:
undefined committed 2021-04-27 22:40:58 +08:00
1 parent d77d7d9ade
commit 00586b5883
8 files changed
+22 -13

No files matched your search

+1 -1
View File
@@ -15,7 +15,7 @@
"lodash": "^4.17.21",
"p-queue": "^6.6.1",
"shell-quote": "^1.7.2",
"ws": "^7.4.4",
"ws": "^7.4.5",
"yargs": "^16.2.0"
},
"license": "AGPL-3.0-only",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.23.27",
"version": "2.23.28",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+1 -1
View File
@@ -123,7 +123,7 @@ class UserRegisterWithCodeHandler extends Handler {
const uid = await user.create(tdoc.mail, uname, password, undefined, this.request.ip);
await token.del(code, token.TYPE_REGISTRATION);
this.session.uid = uid;
this.session.scpoe = PERM.PERM_ALL;
this.session.scpoe = PERM.PERM_ALL.toString();
this.response.redirect = this.url('homepage');
}
}
+1 -1
View File
@@ -19,7 +19,7 @@ export async function parseConfig(config: string | ProblemConfig = {}) {
timeMax: 0,
};
let cfg: ProblemConfig = {};
if (typeof config === 'string' && config.length) {
if (typeof config === 'string') {
// TODO should validate here?
cfg = await readYamlCases(load(config) as Record<string, any>);
} else if (typeof config === 'object') cfg = await readYamlCases(config);
+7 -2
View File
@@ -10,6 +10,7 @@ import task from './task';
import problem from './problem';
import { Rdoc, ContestInfo, ProblemConfig } from '../interface';
import { ArgMethod, Time } from '../utils';
import { MaybeArray } from '../typeutils';
import * as bus from '../service/bus';
import db from '../service/db';
@@ -109,7 +110,7 @@ class RecordModel {
}
static async update(
domainId: string, _id: ObjectID,
domainId: string, _id: MaybeArray<ObjectID>,
$set?: MatchKeysAndValues<Rdoc>,
$push?: PushOperator<Rdoc>,
$unset?: OnlyFieldsOfType<Rdoc, any, true | '' | 1>,
@@ -118,6 +119,10 @@ class RecordModel {
if ($set && Object.keys($set).length) $update.$set = $set;
if ($push && Object.keys($push).length) $update.$push = $push;
if ($unset && Object.keys($unset).length) $update.$unset = $unset;
if (_id instanceof Array) {
await RecordModel.coll.updateMany({ _id: { $in: _id }, domainId }, $update);
return null;
}
if (Object.keys($update).length) {
const res = await RecordModel.coll.findOneAndUpdate(
{ _id, domainId },
@@ -143,7 +148,7 @@ class RecordModel {
return res.modifiedCount;
}
static reset(domainId: string, rid: ObjectID, isRejudge: boolean) {
static reset(domainId: string, rid: MaybeArray<ObjectID>, isRejudge: boolean) {
const upd: any = {
score: 0,
status: STATUS.STATUS_WAITING,
+6 -2
View File
@@ -115,12 +115,13 @@ class UserModel {
};
@ArgMethod
static async getById(domainId: string, _id: number, scope: bigint = PERM.PERM_ALL): Promise<User | null> {
static async getById(domainId: string, _id: number, scope: bigint | string = PERM.PERM_ALL): Promise<User | null> {
const udoc = _id === 0 || _id === 1
? BUILTIN_USERS[_id]
: await coll.findOne({ _id });
if (!udoc) return null;
const dudoc = await domain.getDomainUser(domainId, udoc);
if (typeof scope === 'string') scope = BigInt(scope);
return new User(udoc, dudoc, scope);
}
@@ -197,7 +198,10 @@ class UserModel {
uid: number = 0, regip: string = '127.0.0.1', priv: number = system.get('default.priv'),
) {
const salt = String.random();
if (!uid) uid = await system.inc('user');
if (!uid) {
const [udoc] = await coll.find({}).sort({ _id: -1 }).limit(1).toArray();
uid = Math.max((udoc._id || 0) + 1, 2);
}
try {
await coll.insertOne({
_id: uid,
+2 -2
View File
@@ -6,9 +6,9 @@
"author": "undefined <i@undefined.moe>",
"license": "MIT",
"dependencies": {
"ws": "^7.4.4"
"ws": "^7.4.5"
},
"devDependencies": {
"@types/ws": "^7.4.1"
}
}
}