mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: 添加handler/create和handler/init事件
This commit is contained in:
1 parent
f7478ab346
commit
3040f17702
5 files changed
+14
-2
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.20.40",
|
||||
"version": "2.20.41",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -379,7 +379,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
||||
async postUploadFile(domainId: string, filename: string, type = 'testdata') {
|
||||
if (!this.request.files.file) throw new ValidationError('file');
|
||||
if (this.pdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
||||
if (filename === 'testdata.zip') {
|
||||
if (filename.endsWith('.zip')) {
|
||||
const zip = new AdmZip(this.request.files.file.path);
|
||||
const entries = zip.getEntries();
|
||||
for (const entry of entries) {
|
||||
|
||||
@@ -4,6 +4,10 @@ import 'reflect-metadata';
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable no-eval */
|
||||
|
||||
const versionNum = +process.version.replace(/v/gim, '').split('.')[0];
|
||||
if (versionNum < 14) throw new Error('NodeJS >=v14 required');
|
||||
|
||||
if (!global.Hydro) {
|
||||
global.Hydro = {
|
||||
stat: { reqCount: 0 },
|
||||
|
||||
@@ -4,6 +4,7 @@ import type {
|
||||
Db, FilterQuery, ObjectID, OnlyFieldsOfType,
|
||||
} from 'mongodb';
|
||||
import { argv } from 'yargs';
|
||||
import type { Handler } from './server';
|
||||
import { Logger } from '../logger';
|
||||
import type {
|
||||
Mdoc, Pdoc, Rdoc, TrainingDoc, User,
|
||||
@@ -60,6 +61,8 @@ export interface EventMap {
|
||||
$set: any, $unset: OnlyFieldsOfType<DocType[T], any, true | '' | 1>
|
||||
) => VoidReturn
|
||||
|
||||
'handler/create': (thisArg: Handler) => VoidReturn
|
||||
'handler/init': (thisArg: Handler) => VoidReturn
|
||||
'handler/solution/get': (thisArg: ProblemSolutionHandler) => VoidReturn
|
||||
|
||||
'discussion/before-add': (
|
||||
|
||||
@@ -18,6 +18,7 @@ import sockjs from 'sockjs';
|
||||
import type { SetOption } from 'cookies';
|
||||
import serialize, { SerializeJSOptions } from 'serialize-javascript';
|
||||
import { argv } from 'yargs';
|
||||
import * as bus from './bus';
|
||||
import { errorMessage, lrucache } from '../utils';
|
||||
import { User, DomainDoc } from '../interface';
|
||||
import { Logger } from '../logger';
|
||||
@@ -616,6 +617,8 @@ async function handle(ctx, HandlerClass, checker) {
|
||||
.replace(/_([a-z])/gm, (s) => s[1].toUpperCase());
|
||||
}
|
||||
|
||||
await bus.serial('handler/create', h);
|
||||
|
||||
await h.init(args);
|
||||
if (checker) checker.call(h);
|
||||
if (method === 'post') {
|
||||
@@ -630,6 +633,8 @@ async function handle(ctx, HandlerClass, checker) {
|
||||
throw new MethodNotAllowedError(method);
|
||||
}
|
||||
|
||||
await bus.serial('handler/init', h);
|
||||
|
||||
if (h._prepare) await h._prepare(args);
|
||||
if (h.prepare) await h.prepare(args);
|
||||
|
||||
|
||||
Reference in new issue
Block a user