mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: try to fix #121
This commit is contained in:
1 parent
d77d7d9ade
commit
00586b5883
8 files changed
+22
-13
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user