mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
将题目纳入rating计算系统
This commit is contained in:
1 parent
bf29661eaa
commit
17b38cbf4e
19 files changed
+290
-271
No files matched your search
@@ -238,7 +238,7 @@ export async function setIfNotStatus(
|
||||
{
|
||||
domainId, docType, docId, uid, key: { $not: { $eq: ifNot } },
|
||||
},
|
||||
{ $set: { [key]: value, args } },
|
||||
{ $set: { [key]: value, ...args } },
|
||||
{ upsert: true, returnOriginal: false },
|
||||
);
|
||||
return res.value;
|
||||
|
||||
@@ -10,6 +10,7 @@ import readConfig from '../lib/readConfig';
|
||||
export const pdocHidden: Pdoc = {
|
||||
_id: new ObjectID(),
|
||||
domainId: 'system',
|
||||
docType: document.TYPE_PROBLEM,
|
||||
docId: -1,
|
||||
pid: '',
|
||||
owner: 1,
|
||||
|
||||
+36
-1
@@ -57,6 +57,41 @@ export async function consume(query: any, cb: Function) {
|
||||
}, 100);
|
||||
}
|
||||
|
||||
export class Consumer {
|
||||
consuming: boolean;
|
||||
|
||||
running?: Promise<any>;
|
||||
|
||||
interval: NodeJS.Timeout;
|
||||
|
||||
filter: any;
|
||||
|
||||
func: Function;
|
||||
|
||||
constructor(filter: any, func: Function) {
|
||||
this.consuming = true;
|
||||
this.filter = filter;
|
||||
this.func = func;
|
||||
this.interval = setInterval(this.consume.bind(this), 100);
|
||||
}
|
||||
|
||||
async consume() {
|
||||
if (this.running || !this.consuming) return;
|
||||
const res = await getFirst(this.filter);
|
||||
if (res) {
|
||||
this.running = this.func(res);
|
||||
if (this.running instanceof Promise) await this.running;
|
||||
this.running = null;
|
||||
}
|
||||
}
|
||||
|
||||
async destory() {
|
||||
this.consuming = false;
|
||||
clearInterval(this.interval);
|
||||
if (this.running) await this.running;
|
||||
}
|
||||
}
|
||||
|
||||
global.Hydro.model.task = {
|
||||
add, get, del, count, getFirst, consume,
|
||||
Consumer, add, get, del, count, getFirst, consume,
|
||||
};
|
||||
@@ -156,17 +156,6 @@ export function setEmail(uid: number, mail: string) {
|
||||
return setById(uid, { mail, mailLower: mail.trim().toLowerCase() });
|
||||
}
|
||||
|
||||
export async function changePassword(uid: number, currentPassword: string, newPassword: string) {
|
||||
const udoc = await getById('system', uid);
|
||||
if (!udoc) throw new UserNotFoundError(uid);
|
||||
udoc.checkPassword(currentPassword);
|
||||
const salt = String.random();
|
||||
return await coll.findOneAndUpdate(
|
||||
{ _id: udoc._id },
|
||||
{ $set: { salt, hash: pwhash(newPassword, salt), hashType: 'hydro' } },
|
||||
);
|
||||
}
|
||||
|
||||
export async function inc(_id: number, field: string, n = 1) {
|
||||
const udoc = await coll.findOne({ _id });
|
||||
if (!udoc) throw new UserNotFoundError(_id);
|
||||
@@ -234,7 +223,6 @@ export function ensureIndexes() {
|
||||
|
||||
global.Hydro.model.user = {
|
||||
User,
|
||||
changePassword,
|
||||
create,
|
||||
getByEmail,
|
||||
getById,
|
||||
|
||||
Reference in new issue
Block a user