mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: use common plugin-api interface
This commit is contained in:
1 parent
c61c875bee
commit
70a96aecac
54 files changed
+387
-566
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import * as cordis from 'cordis';
|
||||
import Schema from 'schemastery';
|
||||
import { ModuleInterfaces } from './interface';
|
||||
import { inject } from './lib/ui';
|
||||
import { Loader, ModuleInterfaces } from './loader';
|
||||
import { Loader } from './loader';
|
||||
import { EventMap } from './service/bus';
|
||||
|
||||
export interface Events<C extends Context = Context> extends cordis.Events<C>, EventMap {
|
||||
|
||||
@@ -101,7 +101,7 @@ export async function load(ctx: Context) {
|
||||
model(pending, fail, ctx),
|
||||
setting(pending, fail, require('../model/setting')),
|
||||
]);
|
||||
await require('hydrooj/src/service/server').apply(ctx);
|
||||
await require('../service/server').apply(ctx);
|
||||
await addon(pending, fail, ctx);
|
||||
const scriptDir = path.resolve(__dirname, '..', 'script');
|
||||
for (const h of await fs.readdir(scriptDir)) {
|
||||
|
||||
@@ -38,7 +38,7 @@ export async function apply(ctx: Context) {
|
||||
await modelSystem.runConfig();
|
||||
const storage = require('../service/storage');
|
||||
await storage.loadStorageService();
|
||||
await require('hydrooj/src/service/server').apply(ctx);
|
||||
await require('../service/server').apply(ctx);
|
||||
// Make sure everything is ready and then start main entry
|
||||
if (argv.options.watch) await ctx.loader.reloadPlugin(ctx, 'hydrooj/src/service/watcher', {});
|
||||
await ctx.root.start();
|
||||
|
||||
@@ -4,8 +4,8 @@ import path from 'path';
|
||||
import AdmZip from 'adm-zip';
|
||||
import fs from 'fs-extra';
|
||||
import yaml from 'js-yaml';
|
||||
import { Context } from '../context';
|
||||
import { ValidationError } from '../error';
|
||||
import { PluginContext } from '../loader';
|
||||
import { PERM, PRIV } from '../model/builtin';
|
||||
import problem, { ProblemDoc } from '../model/problem';
|
||||
import { Handler } from '../service/server';
|
||||
@@ -98,7 +98,7 @@ class ProblemImportHydroHandler extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
export async function apply(ctx: PluginContext) {
|
||||
export async function apply(ctx: Context) {
|
||||
ctx.Route('problem_import_hydro', '/problem/import/hydro', ProblemImportHydroHandler, PERM.PERM_CREATE_PROBLEM);
|
||||
ctx.inject('ProblemAdd', 'problem_import_hydro', { icon: 'copy', text: 'Import From Hydro' });
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import type fs from 'fs';
|
||||
import type { Dictionary, NumericDictionary } from 'lodash';
|
||||
import type { Cursor, ObjectID } from 'mongodb';
|
||||
import { Context } from './context';
|
||||
import type { Context } from './context';
|
||||
import type { ProblemDoc } from './model/problem';
|
||||
import type { Handler } from './service/server';
|
||||
|
||||
@@ -637,7 +637,7 @@ export interface Model {
|
||||
blog: typeof import('./model/blog'),
|
||||
builtin: typeof import('./model/builtin'),
|
||||
contest: typeof import('./model/contest'),
|
||||
discussion: typeof import('./model/discussion'),
|
||||
DiscussionModel: typeof import('./model/discussion'),
|
||||
document: typeof import('./model/document'),
|
||||
domain: typeof import('./model/domain').default,
|
||||
message: typeof import('./model/message').default,
|
||||
@@ -657,7 +657,7 @@ export interface Model {
|
||||
rp: typeof import('./script/rating').RpTypes,
|
||||
}
|
||||
|
||||
export interface Service {
|
||||
export interface HydroService {
|
||||
/** @deprecated */
|
||||
bus: Context,
|
||||
db: typeof import('./service/db'),
|
||||
@@ -683,8 +683,6 @@ export interface ProblemSearchOptions {
|
||||
|
||||
export type ProblemSearch = (domainId: string, q: string, options?: ProblemSearchOptions) => Promise<ProblemSearchResponse>;
|
||||
|
||||
export { Context as PluginContext } from './context';
|
||||
|
||||
export interface Lib extends Record<string, any> {
|
||||
difficulty: typeof import('./lib/difficulty'),
|
||||
buildContent: typeof import('./lib/content').buildContent,
|
||||
@@ -725,7 +723,7 @@ export interface HydroGlobal {
|
||||
/** @deprecated */
|
||||
handler: Record<string, Function>;
|
||||
script: Record<string, Script>;
|
||||
service: Service;
|
||||
service: HydroService;
|
||||
lib: Lib;
|
||||
module: { [K in keyof ModuleInterfaces]: Record<string, ModuleInterfaces[K]> };
|
||||
ui: UI;
|
||||
@@ -742,6 +740,7 @@ declare global {
|
||||
addons: string[],
|
||||
}
|
||||
}
|
||||
var bus: any; // eslint-disable-line
|
||||
var app: Context; // eslint-disable-line
|
||||
var Hydro: HydroGlobal; // eslint-disable-line
|
||||
var addons: string[]; // eslint-disable-line
|
||||
|
||||
@@ -16,9 +16,6 @@ import { Logger } from './logger';
|
||||
import { Context } from './context';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import { unwrapExports } from './utils';
|
||||
// This is the main entry. So let's re-export some modules.
|
||||
export * from './interface';
|
||||
export { Schema, Logger };
|
||||
|
||||
const argv = cac().parse();
|
||||
const logger = new Logger('loader');
|
||||
|
||||
@@ -302,7 +302,7 @@ bus.on('app/ready', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
global.Hydro.model.discussion = {
|
||||
global.Hydro.model.DiscussionModel = {
|
||||
typeDisplay,
|
||||
PROJECTION_LIST,
|
||||
PROJECTION_PUBLIC,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import AdmZip from 'adm-zip';
|
||||
import fs from 'fs-extra';
|
||||
import yaml from 'js-yaml';
|
||||
import Schema from 'schemastery';
|
||||
import superagent from 'superagent';
|
||||
import * as db from './service/db';
|
||||
export { ObjectID, ObjectId } from 'mongodb';
|
||||
export * from './utils';
|
||||
export * from './interface';
|
||||
export * from './pipelineUtils';
|
||||
export * from './error';
|
||||
export * from './settings';
|
||||
export * as SystemModel from './model/system';
|
||||
export * as TrainingModel from './model/training';
|
||||
export * as OpcountModel from './model/opcount';
|
||||
export * as OplogModel from './model/oplog';
|
||||
export * as BlogModel from './model/blog';
|
||||
export * as SettingModel from './model/setting';
|
||||
export * as DiscussionModel from './model/discussion';
|
||||
export * as DocumentModel from './model/document';
|
||||
export * as BuiltinModel from './model/builtin';
|
||||
export * as ContestModel from './model/contest';
|
||||
export { default as TokenModel } from './model/token';
|
||||
export { default as UserModel } from './model/user';
|
||||
export { default as ProblemModel } from './model/problem';
|
||||
export { default as RecordModel } from './model/record';
|
||||
export { default as SolutionModel } from './model/solution';
|
||||
export { default as MessageModel } from './model/message';
|
||||
export { default as OauthModel } from './model/oauth';
|
||||
export { default as BlackListModel } from './model/blacklist';
|
||||
export { default as DomainModel } from './model/domain';
|
||||
export { default as StorageModel } from './model/storage';
|
||||
export { default as TaskModel } from './model/task';
|
||||
export * from './model/builtin';
|
||||
export * as JudgeHandler from './handler/judge';
|
||||
export { postJudge } from './handler/judge';
|
||||
export { Service, Context } from './context';
|
||||
export { buildContent } from './lib/content';
|
||||
export * as validator from './lib/validator';
|
||||
export { default as rank } from './lib/rank';
|
||||
export { default as paginate } from './lib/paginate';
|
||||
export * from './service/decorators';
|
||||
export { Handler, ConnectionHandler } from './service/server';
|
||||
export { UiContextBase } from './service/layers/base';
|
||||
export { EventMap } from './service/bus';
|
||||
export {
|
||||
db, Schema, yaml, fs, AdmZip, superagent,
|
||||
};
|
||||
@@ -1,8 +1,8 @@
|
||||
import { PassThrough } from 'stream';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import * as system from 'hydrooj/src/model/system';
|
||||
import token from 'hydrooj/src/model/token';
|
||||
import type { HydroRequest, HydroResponse } from 'hydrooj/src/service/server';
|
||||
import * as system from '../../model/system';
|
||||
import token from '../../model/token';
|
||||
import type { HydroRequest, HydroResponse } from '../server';
|
||||
|
||||
export interface UiContextBase {
|
||||
cdn_prefix: string;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import BlackListModel from 'hydrooj/src/model/blacklist';
|
||||
import DomainModel from 'hydrooj/src/model/domain';
|
||||
import * as system from 'hydrooj/src/model/system';
|
||||
import token from 'hydrooj/src/model/token';
|
||||
import BlackListModel from '../../model/blacklist';
|
||||
import DomainModel from '../../model/domain';
|
||||
import * as system from '../../model/system';
|
||||
import token from '../../model/token';
|
||||
|
||||
export default async (ctx, next) => {
|
||||
const forceDomain = /^\/d\/([^/]+)\//.exec(ctx.request.path);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ObjectID } from 'mongodb';
|
||||
import avatar from 'hydrooj/src/lib/avatar';
|
||||
import { PERM } from 'hydrooj/src/model/builtin';
|
||||
import * as system from 'hydrooj/src/model/system';
|
||||
import { User } from 'hydrooj/src/model/user';
|
||||
import avatar from '../../lib/avatar';
|
||||
import { PERM } from '../../model/builtin';
|
||||
import * as system from '../../model/system';
|
||||
import { User } from '../../model/user';
|
||||
import type { KoaContext } from '../server';
|
||||
|
||||
const serializer = (showDisplayName = false) => (k: string, v: any) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { errorMessage } from '@hydrooj/utils/lib/utils';
|
||||
import { SystemError, UserFacingError } from 'hydrooj/src/error';
|
||||
import { PERM } from 'hydrooj/src/model/builtin';
|
||||
import { User } from 'hydrooj/src/model/user';
|
||||
import { SystemError, UserFacingError } from '../../error';
|
||||
import { PERM } from '../../model/builtin';
|
||||
import { User } from '../../model/user';
|
||||
import type { KoaContext } from '../server';
|
||||
|
||||
const serializer = (showDisplayName = false) => (k: string, v: any) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CsrfTokenError, NotFoundError } from 'hydrooj/src/error';
|
||||
import avatar from 'hydrooj/src/lib/avatar';
|
||||
import { PERM } from 'hydrooj/src/model/builtin';
|
||||
import UserModel from 'hydrooj/src/model/user';
|
||||
import { CsrfTokenError, NotFoundError } from '../../error';
|
||||
import avatar from '../../lib/avatar';
|
||||
import { PERM } from '../../model/builtin';
|
||||
import UserModel from '../../model/user';
|
||||
import type { KoaContext } from '../server';
|
||||
|
||||
export default async (ctx: KoaContext, next) => {
|
||||
|
||||
Reference in new issue
Block a user