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
+3
-3
@@ -27,13 +27,13 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@shelf/jest-mongodb": "^1.2.3",
|
"@shelf/jest-mongodb": "^1.2.3",
|
||||||
"@types/cross-spawn": "^6.0.2",
|
"@types/cross-spawn": "^6.0.2",
|
||||||
"@types/jest": "^26.0.22",
|
"@types/jest": "^26.0.23",
|
||||||
"@types/node": "^14.14.41",
|
"@types/node": "^14.14.41",
|
||||||
"@types/semver": "^7.3.4",
|
"@types/semver": "^7.3.5",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.21.0",
|
"@typescript-eslint/eslint-plugin": "^4.21.0",
|
||||||
"@typescript-eslint/parser": "^4.21.0",
|
"@typescript-eslint/parser": "^4.21.0",
|
||||||
"cross-spawn": "^7.0.3",
|
"cross-spawn": "^7.0.3",
|
||||||
"eslint": "^7.23.0",
|
"eslint": "^7.25.0",
|
||||||
"eslint-config-airbnb-typescript": "^12.0.0",
|
"eslint-config-airbnb-typescript": "^12.0.0",
|
||||||
"eslint-import-resolver-typescript": "^2.4.0",
|
"eslint-import-resolver-typescript": "^2.4.0",
|
||||||
"eslint-plugin-import": "^2.22.1",
|
"eslint-plugin-import": "^2.22.1",
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"p-queue": "^6.6.1",
|
"p-queue": "^6.6.1",
|
||||||
"shell-quote": "^1.7.2",
|
"shell-quote": "^1.7.2",
|
||||||
"ws": "^7.4.4",
|
"ws": "^7.4.5",
|
||||||
"yargs": "^16.2.0"
|
"yargs": "^16.2.0"
|
||||||
},
|
},
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.23.27",
|
"version": "2.23.28",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"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);
|
const uid = await user.create(tdoc.mail, uname, password, undefined, this.request.ip);
|
||||||
await token.del(code, token.TYPE_REGISTRATION);
|
await token.del(code, token.TYPE_REGISTRATION);
|
||||||
this.session.uid = uid;
|
this.session.uid = uid;
|
||||||
this.session.scpoe = PERM.PERM_ALL;
|
this.session.scpoe = PERM.PERM_ALL.toString();
|
||||||
this.response.redirect = this.url('homepage');
|
this.response.redirect = this.url('homepage');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export async function parseConfig(config: string | ProblemConfig = {}) {
|
|||||||
timeMax: 0,
|
timeMax: 0,
|
||||||
};
|
};
|
||||||
let cfg: ProblemConfig = {};
|
let cfg: ProblemConfig = {};
|
||||||
if (typeof config === 'string' && config.length) {
|
if (typeof config === 'string') {
|
||||||
// TODO should validate here?
|
// TODO should validate here?
|
||||||
cfg = await readYamlCases(load(config) as Record<string, any>);
|
cfg = await readYamlCases(load(config) as Record<string, any>);
|
||||||
} else if (typeof config === 'object') cfg = await readYamlCases(config);
|
} else if (typeof config === 'object') cfg = await readYamlCases(config);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import task from './task';
|
|||||||
import problem from './problem';
|
import problem from './problem';
|
||||||
import { Rdoc, ContestInfo, ProblemConfig } from '../interface';
|
import { Rdoc, ContestInfo, ProblemConfig } from '../interface';
|
||||||
import { ArgMethod, Time } from '../utils';
|
import { ArgMethod, Time } from '../utils';
|
||||||
|
import { MaybeArray } from '../typeutils';
|
||||||
import * as bus from '../service/bus';
|
import * as bus from '../service/bus';
|
||||||
import db from '../service/db';
|
import db from '../service/db';
|
||||||
|
|
||||||
@@ -109,7 +110,7 @@ class RecordModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async update(
|
static async update(
|
||||||
domainId: string, _id: ObjectID,
|
domainId: string, _id: MaybeArray<ObjectID>,
|
||||||
$set?: MatchKeysAndValues<Rdoc>,
|
$set?: MatchKeysAndValues<Rdoc>,
|
||||||
$push?: PushOperator<Rdoc>,
|
$push?: PushOperator<Rdoc>,
|
||||||
$unset?: OnlyFieldsOfType<Rdoc, any, true | '' | 1>,
|
$unset?: OnlyFieldsOfType<Rdoc, any, true | '' | 1>,
|
||||||
@@ -118,6 +119,10 @@ class RecordModel {
|
|||||||
if ($set && Object.keys($set).length) $update.$set = $set;
|
if ($set && Object.keys($set).length) $update.$set = $set;
|
||||||
if ($push && Object.keys($push).length) $update.$push = $push;
|
if ($push && Object.keys($push).length) $update.$push = $push;
|
||||||
if ($unset && Object.keys($unset).length) $update.$unset = $unset;
|
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) {
|
if (Object.keys($update).length) {
|
||||||
const res = await RecordModel.coll.findOneAndUpdate(
|
const res = await RecordModel.coll.findOneAndUpdate(
|
||||||
{ _id, domainId },
|
{ _id, domainId },
|
||||||
@@ -143,7 +148,7 @@ class RecordModel {
|
|||||||
return res.modifiedCount;
|
return res.modifiedCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
static reset(domainId: string, rid: ObjectID, isRejudge: boolean) {
|
static reset(domainId: string, rid: MaybeArray<ObjectID>, isRejudge: boolean) {
|
||||||
const upd: any = {
|
const upd: any = {
|
||||||
score: 0,
|
score: 0,
|
||||||
status: STATUS.STATUS_WAITING,
|
status: STATUS.STATUS_WAITING,
|
||||||
|
|||||||
@@ -115,12 +115,13 @@ class UserModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@ArgMethod
|
@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
|
const udoc = _id === 0 || _id === 1
|
||||||
? BUILTIN_USERS[_id]
|
? BUILTIN_USERS[_id]
|
||||||
: await coll.findOne({ _id });
|
: await coll.findOne({ _id });
|
||||||
if (!udoc) return null;
|
if (!udoc) return null;
|
||||||
const dudoc = await domain.getDomainUser(domainId, udoc);
|
const dudoc = await domain.getDomainUser(domainId, udoc);
|
||||||
|
if (typeof scope === 'string') scope = BigInt(scope);
|
||||||
return new User(udoc, dudoc, 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'),
|
uid: number = 0, regip: string = '127.0.0.1', priv: number = system.get('default.priv'),
|
||||||
) {
|
) {
|
||||||
const salt = String.random();
|
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 {
|
try {
|
||||||
await coll.insertOne({
|
await coll.insertOne({
|
||||||
_id: uid,
|
_id: uid,
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ws": "^7.4.4"
|
"ws": "^7.4.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/ws": "^7.4.1"
|
"@types/ws": "^7.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user