mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: +hook:record/judge, +setting displayName for userImport
This commit is contained in:
1 parent
ea3a386b77
commit
4a613c47d5
7 files changed
+34
-11
No files matched your search
@@ -23,6 +23,7 @@ tsconfig.json
|
|||||||
packages/**/*.js
|
packages/**/*.js
|
||||||
!/build/build.js
|
!/build/build.js
|
||||||
!**/bin/*.js
|
!**/bin/*.js
|
||||||
|
!*.page.js
|
||||||
|
|
||||||
# Data files
|
# Data files
|
||||||
*.mmdb
|
*.mmdb
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.20.29",
|
"version": "2.20.30",
|
||||||
"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",
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ async function _postJudge(rdoc: Rdoc) {
|
|||||||
: await problem.get(rdoc.domainId, rdoc.pid);
|
: await problem.get(rdoc.domainId, rdoc.pid);
|
||||||
const difficulty = difficultyAlgorithm(pdoc.nSubmit, pdoc.nAccept);
|
const difficulty = difficultyAlgorithm(pdoc.nSubmit, pdoc.nAccept);
|
||||||
await problem.edit(pdoc.domainId, pdoc.docId, { difficulty });
|
await problem.edit(pdoc.domainId, pdoc.docId, { difficulty });
|
||||||
|
await bus.serial('record/judge', rdoc, updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function next(body: JudgeResultBody) {
|
export async function next(body: JudgeResultBody) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import * as system from '../model/system';
|
|||||||
import user from '../model/user';
|
import user from '../model/user';
|
||||||
import { STATUS, PRIV } from '../model/builtin';
|
import { STATUS, PRIV } from '../model/builtin';
|
||||||
import record from '../model/record';
|
import record from '../model/record';
|
||||||
|
import domain from '../model/domain';
|
||||||
import {
|
import {
|
||||||
Route, Connection, Handler, ConnectionHandler, param, Types,
|
Route, Connection, Handler, ConnectionHandler, param, Types,
|
||||||
} from '../service/server';
|
} from '../service/server';
|
||||||
@@ -193,14 +194,23 @@ class SystemUserImportHandler extends SystemHandler {
|
|||||||
const messages = [];
|
const messages = [];
|
||||||
for (const i in users) {
|
for (const i in users) {
|
||||||
const u = users[i];
|
const u = users[i];
|
||||||
const [email, username, password] = u.split(',').map((t) => t.trim());
|
const [email, username, password, displayName] = u.split(',').map((t) => t.trim());
|
||||||
if (email && username && password) {
|
if (email && username && password) {
|
||||||
if (!isEmail(email)) messages.push(`Line ${i + 1}: Invalid email.`);
|
if (!isEmail(email)) messages.push(`Line ${i + 1}: Invalid email.`);
|
||||||
else if (!isUname(username)) messages.push(`Line ${i + 1}: Invalid username`);
|
else if (!isUname(username)) messages.push(`Line ${i + 1}: Invalid username`);
|
||||||
else if (!isPassword(password)) messages.push(`Line ${i + 1}: Invalid password`);
|
else if (!isPassword(password)) messages.push(`Line ${i + 1}: Invalid password`);
|
||||||
else {
|
else {
|
||||||
udocs.push({ email, username, password });
|
udocs.push({
|
||||||
if (!confirm) tasks.push(user.create(email, username, password));
|
email, username, password, displayName,
|
||||||
|
});
|
||||||
|
if (!confirm) {
|
||||||
|
tasks.push(
|
||||||
|
user.create(email, username, password).then((uid) => {
|
||||||
|
if (displayName) return domain.setUserInDomain(domainId, uid, { displayName });
|
||||||
|
return Promise.resolve();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else messages.push(`Line ${i + 1}: Input invalid.`);
|
} else messages.push(`Line ${i + 1}: Input invalid.`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -447,6 +447,7 @@ export class ProblemSolutionHandler extends ProblemDetailHandler {
|
|||||||
this.response.body = {
|
this.response.body = {
|
||||||
path, psdocs, page, pcount, pscount, udict, pssdict, pdoc: this.pdoc,
|
path, psdocs, page, pcount, pscount, udict, pssdict, pdoc: this.pdoc,
|
||||||
};
|
};
|
||||||
|
await bus.serial('handler/solution/get', this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@param('content', Types.String, isContent)
|
@param('content', Types.String, isContent)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import type {
|
|||||||
} from '../interface';
|
} from '../interface';
|
||||||
import type { DomainDoc } from '../loader';
|
import type { DomainDoc } from '../loader';
|
||||||
import type { DocType } from '../model/document';
|
import type { DocType } from '../model/document';
|
||||||
|
import type { ProblemSolutionHandler } from '../handler/problem';
|
||||||
|
|
||||||
const _hooks: Record<keyof any, Array<(...args: any[]) => any>> = {};
|
const _hooks: Record<keyof any, Array<(...args: any[]) => any>> = {};
|
||||||
const logger = new Logger('bus', true);
|
const logger = new Logger('bus', true);
|
||||||
@@ -59,6 +60,8 @@ export interface EventMap {
|
|||||||
$set: any, $unset: OnlyFieldsOfType<DocType[T], any, true | '' | 1>
|
$set: any, $unset: OnlyFieldsOfType<DocType[T], any, true | '' | 1>
|
||||||
) => VoidReturn
|
) => VoidReturn
|
||||||
|
|
||||||
|
'handler/solution/get': (thisArg: ProblemSolutionHandler) => VoidReturn
|
||||||
|
|
||||||
'discussion/before-add': (
|
'discussion/before-add': (
|
||||||
domainId: string, parentType: number, parentId: ObjectID | number | string,
|
domainId: string, parentType: number, parentId: ObjectID | number | string,
|
||||||
owner: number, title: string, content: string,
|
owner: number, title: string, content: string,
|
||||||
@@ -76,6 +79,7 @@ export interface EventMap {
|
|||||||
'training/get': (tdoc: TrainingDoc, handler: any) => VoidReturn
|
'training/get': (tdoc: TrainingDoc, handler: any) => VoidReturn
|
||||||
|
|
||||||
'record/change': (rdoc: Rdoc, $set?: any, $push?: any) => void
|
'record/change': (rdoc: Rdoc, $set?: any, $push?: any) => void
|
||||||
|
'record/judge': (rdoc: Rdoc, updated: boolean) => VoidReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHooks<K extends keyof EventMap>(name: K) {
|
function getHooks<K extends keyof EventMap>(name: K) {
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import { resolve } from 'path';
|
|||||||
import os from 'os';
|
import os from 'os';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
import { isSafeInteger, Dictionary, filter } from 'lodash';
|
import {
|
||||||
|
isSafeInteger, Dictionary, filter, cloneDeep,
|
||||||
|
} from 'lodash';
|
||||||
import { ObjectID } from 'mongodb';
|
import { ObjectID } from 'mongodb';
|
||||||
import Koa, { Context } from 'koa';
|
import Koa, { Context } from 'koa';
|
||||||
import Body from 'koa-body';
|
import Body from 'koa-body';
|
||||||
@@ -245,6 +247,11 @@ export async function prepare() {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const UiContextBase = {
|
||||||
|
cdn_prefix: '/',
|
||||||
|
url_prefix: '/',
|
||||||
|
};
|
||||||
|
|
||||||
export class HandlerCommon {
|
export class HandlerCommon {
|
||||||
domainId: string;
|
domainId: string;
|
||||||
domain: DomainDoc;
|
domain: DomainDoc;
|
||||||
@@ -326,7 +333,7 @@ export class HandlerCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Handler extends HandlerCommon {
|
export class Handler extends HandlerCommon {
|
||||||
UIContext: any;
|
UiContext: any;
|
||||||
args: any;
|
args: any;
|
||||||
ctx: Koa.Context;
|
ctx: Koa.Context;
|
||||||
|
|
||||||
@@ -394,10 +401,8 @@ export class Handler extends HandlerCommon {
|
|||||||
},
|
},
|
||||||
disposition: null,
|
disposition: null,
|
||||||
};
|
};
|
||||||
this.UIContext = {
|
this.UiContext = cloneDeep(UiContextBase);
|
||||||
cdn_prefix: '/',
|
this.UiContext.cdn_prefix = system.get('server.cdn');
|
||||||
url_prefix: '/',
|
|
||||||
};
|
|
||||||
this.session = {};
|
this.session = {};
|
||||||
const xff = system.get('server.xff');
|
const xff = system.get('server.xff');
|
||||||
if (xff) this.request.ip = this.request.headers[xff.toLowerCase()] || this.request.ip;
|
if (xff) this.request.ip = this.request.headers[xff.toLowerCase()] || this.request.ip;
|
||||||
@@ -465,7 +470,7 @@ export class Handler extends HandlerCommon {
|
|||||||
}
|
}
|
||||||
if (this.user._id === 0 && this.session.viewLang) this.user.viewLang = this.session.viewLang;
|
if (this.user._id === 0 && this.session.viewLang) this.user.viewLang = this.session.viewLang;
|
||||||
this.csrfToken = this.getCsrfToken(this.session._id || String.random(32));
|
this.csrfToken = this.getCsrfToken(this.session._id || String.random(32));
|
||||||
this.UIContext.csrfToken = this.csrfToken;
|
this.UiContext.csrfToken = this.csrfToken;
|
||||||
this.loginMethods = filter(Object.keys(global.Hydro.lib), (str) => str.startsWith('oauth_'))
|
this.loginMethods = filter(Object.keys(global.Hydro.lib), (str) => str.startsWith('oauth_'))
|
||||||
.map((key) => ({
|
.map((key) => ({
|
||||||
id: key.split('_')[1],
|
id: key.split('_')[1],
|
||||||
@@ -801,6 +806,7 @@ global.Hydro.service.server = {
|
|||||||
app,
|
app,
|
||||||
server,
|
server,
|
||||||
router,
|
router,
|
||||||
|
UiContextBase,
|
||||||
get,
|
get,
|
||||||
post,
|
post,
|
||||||
route,
|
route,
|
||||||
|
|||||||
Reference in new issue
Block a user