mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +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
@@ -10,6 +10,7 @@ import type {
|
||||
} from '../interface';
|
||||
import type { DomainDoc } from '../loader';
|
||||
import type { DocType } from '../model/document';
|
||||
import type { ProblemSolutionHandler } from '../handler/problem';
|
||||
|
||||
const _hooks: Record<keyof any, Array<(...args: any[]) => any>> = {};
|
||||
const logger = new Logger('bus', true);
|
||||
@@ -59,6 +60,8 @@ export interface EventMap {
|
||||
$set: any, $unset: OnlyFieldsOfType<DocType[T], any, true | '' | 1>
|
||||
) => VoidReturn
|
||||
|
||||
'handler/solution/get': (thisArg: ProblemSolutionHandler) => VoidReturn
|
||||
|
||||
'discussion/before-add': (
|
||||
domainId: string, parentType: number, parentId: ObjectID | number | string,
|
||||
owner: number, title: string, content: string,
|
||||
@@ -76,6 +79,7 @@ export interface EventMap {
|
||||
'training/get': (tdoc: TrainingDoc, handler: any) => VoidReturn
|
||||
|
||||
'record/change': (rdoc: Rdoc, $set?: any, $push?: any) => void
|
||||
'record/judge': (rdoc: Rdoc, updated: boolean) => VoidReturn
|
||||
}
|
||||
|
||||
function getHooks<K extends keyof EventMap>(name: K) {
|
||||
|
||||
@@ -4,7 +4,9 @@ import { resolve } from 'path';
|
||||
import os from 'os';
|
||||
import http from 'http';
|
||||
import moment from 'moment-timezone';
|
||||
import { isSafeInteger, Dictionary, filter } from 'lodash';
|
||||
import {
|
||||
isSafeInteger, Dictionary, filter, cloneDeep,
|
||||
} from 'lodash';
|
||||
import { ObjectID } from 'mongodb';
|
||||
import Koa, { Context } from 'koa';
|
||||
import Body from 'koa-body';
|
||||
@@ -245,6 +247,11 @@ export async function prepare() {
|
||||
}));
|
||||
}
|
||||
|
||||
export const UiContextBase = {
|
||||
cdn_prefix: '/',
|
||||
url_prefix: '/',
|
||||
};
|
||||
|
||||
export class HandlerCommon {
|
||||
domainId: string;
|
||||
domain: DomainDoc;
|
||||
@@ -326,7 +333,7 @@ export class HandlerCommon {
|
||||
}
|
||||
|
||||
export class Handler extends HandlerCommon {
|
||||
UIContext: any;
|
||||
UiContext: any;
|
||||
args: any;
|
||||
ctx: Koa.Context;
|
||||
|
||||
@@ -394,10 +401,8 @@ export class Handler extends HandlerCommon {
|
||||
},
|
||||
disposition: null,
|
||||
};
|
||||
this.UIContext = {
|
||||
cdn_prefix: '/',
|
||||
url_prefix: '/',
|
||||
};
|
||||
this.UiContext = cloneDeep(UiContextBase);
|
||||
this.UiContext.cdn_prefix = system.get('server.cdn');
|
||||
this.session = {};
|
||||
const xff = system.get('server.xff');
|
||||
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;
|
||||
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_'))
|
||||
.map((key) => ({
|
||||
id: key.split('_')[1],
|
||||
@@ -801,6 +806,7 @@ global.Hydro.service.server = {
|
||||
app,
|
||||
server,
|
||||
router,
|
||||
UiContextBase,
|
||||
get,
|
||||
post,
|
||||
route,
|
||||
|
||||
Reference in new issue
Block a user