mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: remove Hydro.service.bus, Hydro.ui.template
This commit is contained in:
8 files changed
+193
-178
No files matched your search
@@ -14,17 +14,6 @@ import { unwrapExports } from '../utils';
|
||||
|
||||
const logger = new Logger('common');
|
||||
|
||||
async function getFiles(folder: string, base = ''): Promise<string[]> {
|
||||
const files = [];
|
||||
const f = await fs.readdir(folder);
|
||||
for (const i of f) {
|
||||
if ((await fs.stat(path.join(folder, i))).isDirectory()) {
|
||||
files.push(...await getFiles(path.join(folder, i), path.join(base, i)));
|
||||
} else files.push(path.join(base, i));
|
||||
}
|
||||
return files.map((item) => item.replace(/\\/gmi, '/'));
|
||||
}
|
||||
|
||||
function locateFile(basePath: string, filenames: string[]) {
|
||||
for (const i of filenames) {
|
||||
const p = path.resolve(basePath, i);
|
||||
@@ -136,26 +125,3 @@ export async function setting(pending: string[], fail: string[], modelSetting: t
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function template(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = locateFile(i, ['template', 'templates']);
|
||||
if (p && (await fs.stat(p)).isDirectory() && !fail.includes(i)) {
|
||||
try {
|
||||
const files = await getFiles(p);
|
||||
for (const file of files) {
|
||||
const l = path.resolve(p, file);
|
||||
if (file.endsWith('.tsx')) global.Hydro.ui.template[file] = require(l);
|
||||
global.Hydro.ui.template[file] = await fs.readFile(l, 'utf-8');
|
||||
if (process.env.DEV) global.Hydro.ui.template[`${file}.source`] = l;
|
||||
}
|
||||
logger.info('Template init: %s', i);
|
||||
} catch (e) {
|
||||
fail.push(i);
|
||||
app.injectUI('Notification', 'Template load fail: {0}', { args: [i], type: 'warn' }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION);
|
||||
logger.error('Template Load Fail: %s', i);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,10 +30,7 @@ export async function apply(ctx: Context) {
|
||||
}
|
||||
const pending = global.addons;
|
||||
const fail = [];
|
||||
await Promise.all([
|
||||
locale(pending, fail),
|
||||
template(pending, fail),
|
||||
]);
|
||||
await locale(pending, fail);
|
||||
await ctx.plugin(MongoService, load() || {});
|
||||
await ctx.plugin(ConfigService);
|
||||
const modelSystem = require('../model/system');
|
||||
|
||||
@@ -9,8 +9,6 @@ if (!global.Hydro) {
|
||||
hydrooj: require('hydrooj/package.json').version,
|
||||
},
|
||||
// @ts-ignore
|
||||
service: {},
|
||||
// @ts-ignore
|
||||
model: {},
|
||||
script: {},
|
||||
// @ts-ignore
|
||||
@@ -22,9 +20,7 @@ if (!global.Hydro) {
|
||||
},
|
||||
}),
|
||||
// @ts-ignore
|
||||
ui: {
|
||||
template: {},
|
||||
},
|
||||
ui: {},
|
||||
// @ts-ignore
|
||||
error: {},
|
||||
locales: {},
|
||||
|
||||
@@ -596,11 +596,6 @@ export interface Model {
|
||||
rp: typeof import('./script/rating').RpTypes,
|
||||
}
|
||||
|
||||
export interface HydroService {
|
||||
/** @deprecated */
|
||||
bus: Context,
|
||||
}
|
||||
|
||||
export interface GeoIP {
|
||||
provider: string,
|
||||
lookup: (ip: string, locale?: string) => any,
|
||||
@@ -629,7 +624,6 @@ export interface Lib extends Record<string, any> {
|
||||
|
||||
export type UIInjectableFields = 'ProblemAdd' | 'Notification' | 'Nav' | 'UserDropdown' | 'DomainManage' | 'ControlPanel';
|
||||
export interface UI {
|
||||
template: Record<string, string>,
|
||||
nodes: Record<UIInjectableFields, any[]>,
|
||||
getNodes: typeof import('./lib/ui').getNodes,
|
||||
inject: typeof import('./lib/ui').inject,
|
||||
@@ -650,7 +644,6 @@ export interface HydroGlobal {
|
||||
version: Record<string, string>;
|
||||
model: Model;
|
||||
script: Record<string, Script>;
|
||||
service: HydroService;
|
||||
lib: Lib;
|
||||
module: { [K in keyof ModuleInterfaces]: Record<string, ModuleInterfaces[K]> };
|
||||
ui: UI;
|
||||
|
||||
@@ -115,5 +115,4 @@ export function apply(ctx: Context) {
|
||||
|
||||
export default app;
|
||||
|
||||
global.Hydro.service.bus = app as any;
|
||||
global.bus = app;
|
||||
@@ -238,12 +238,6 @@ export async function apply(ctx: Context) {
|
||||
h.translate = h.translate.bind(h);
|
||||
h.url = h.url.bind(h);
|
||||
h.ctx = h.ctx.extend({ domain: h.domain });
|
||||
h.renderHTML = ((orig) => function (name: string, args: Record<string, any>) {
|
||||
const s = name.split('.');
|
||||
let templateName = `${s[0]}.${args.domainId}.${s[1]}`;
|
||||
if (!global.Hydro.ui.template[templateName]) templateName = name;
|
||||
return orig(templateName, args);
|
||||
})(h.renderHTML).bind(h);
|
||||
});
|
||||
on('handler/create/http', async (h) => {
|
||||
if (!argv.options.benchmark && !h.notUsage) await h.limitRate('global', 5, 100);
|
||||
|
||||
Reference in new issue
Block a user