mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add definePlugin syntax support
This commit is contained in:
1 parent
9971967fd1
commit
bb288cb960
2 files changed
+13
-4
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import {
|
import {
|
||||||
Context, db, ForbiddenError, Handler, post, Types, yaml,
|
db, definePlugin, ForbiddenError, Handler, post, Types, yaml,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
|
|
||||||
function decrypt(encrypted: string) {
|
function decrypt(encrypted: string) {
|
||||||
@@ -67,6 +67,8 @@ class DataReportHandler extends Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function apply(ctx: Context) {
|
export default definePlugin({
|
||||||
ctx.Route('data_report', '/center/report', DataReportHandler);
|
apply(ctx) {
|
||||||
}
|
ctx.Route('data_report', '/center/report', DataReportHandler);
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -5,6 +5,7 @@ import _ from 'lodash';
|
|||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
import Schema from 'schemastery';
|
import Schema from 'schemastery';
|
||||||
import superagent from 'superagent';
|
import superagent from 'superagent';
|
||||||
|
import { Context } from './context';
|
||||||
import db from './service/db';
|
import db from './service/db';
|
||||||
export { ObjectID, ObjectId, FilterQuery } from 'mongodb';
|
export { ObjectID, ObjectId, FilterQuery } from 'mongodb';
|
||||||
export * from './utils';
|
export * from './utils';
|
||||||
@@ -55,3 +56,9 @@ export { EventMap } from './service/bus';
|
|||||||
export {
|
export {
|
||||||
db, Schema, yaml, fs, AdmZip, superagent, _, moment,
|
db, Schema, yaml, fs, AdmZip, superagent, _, moment,
|
||||||
};
|
};
|
||||||
|
export const definePlugin = <T = never>(args: {
|
||||||
|
using?: keyof Context[];
|
||||||
|
apply: (ctx: Context, config: T) => Promise<void> | void;
|
||||||
|
schema?: Schema<T>;
|
||||||
|
name?: string;
|
||||||
|
}) => args;
|
||||||
Reference in new issue
Block a user