mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
bug fixes
This commit is contained in:
15 files changed
+23
-163
No files matched your search
@@ -9,7 +9,6 @@ import type { EventMap } from './service/bus';
|
||||
import type CheckService from './service/check';
|
||||
import type { } from './service/migration';
|
||||
|
||||
// TODO: this is an broken declaration
|
||||
export { EventMap as Events };
|
||||
|
||||
function addScript<K>(name: string, description: string, validate: Schema<K>, run: (args: K, report: any) => boolean | Promise<boolean>) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { load as loadOptions } from '../options';
|
||||
import { MongoService } from '../service/db';
|
||||
import { ConfigService } from '../settings';
|
||||
import {
|
||||
addon, builtinModel, model, service, setting,
|
||||
addon, builtinModel, model, service,
|
||||
} from './common';
|
||||
|
||||
const argv = cac().parse();
|
||||
@@ -125,7 +125,6 @@ export async function load(ctx: Context) {
|
||||
ctx.plugin(require('../service/worker'));
|
||||
await builtinModel(ctx);
|
||||
await model(pending, fail, ctx);
|
||||
await setting(pending, fail, require('../model/setting'));
|
||||
ctx.plugin(require('../service/server'));
|
||||
ctx = await new Promise((resolve) => {
|
||||
ctx.inject(['server', 'setting', 'worker'], (c) => {
|
||||
|
||||
@@ -79,44 +79,3 @@ export async function locale(pending: Record<string, string>, fail: string[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function setting(pending: Record<string, string>, fail: string[], modelSetting: typeof import('../model/setting')) {
|
||||
const map = {
|
||||
system: modelSetting.SystemSetting,
|
||||
account: modelSetting.AccountSetting,
|
||||
preference: modelSetting.PreferenceSetting,
|
||||
domain: modelSetting.DomainSetting,
|
||||
};
|
||||
for (const i of Object.values(pending)) {
|
||||
let p = path.resolve(i, 'setting.yaml');
|
||||
const t = i.split(path.sep);
|
||||
// TODO: change this name setting to package name
|
||||
const name = t[t.length - 1];
|
||||
if (!fs.existsSync(p)) p = path.resolve(i, 'settings.yaml');
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
try {
|
||||
const cfg: any = yaml.load(await fs.readFile(p, 'utf-8'));
|
||||
for (const key in cfg) {
|
||||
let val = cfg[key].default || cfg[key].value;
|
||||
if (typeof val === 'string') {
|
||||
val = val
|
||||
.replace(/\$TEMP/g, os.tmpdir())
|
||||
.replace(/\$HOME/g, os.homedir());
|
||||
}
|
||||
const category = cfg[key].category || 'system';
|
||||
map[category](
|
||||
modelSetting.Setting(
|
||||
cfg[key].family || name, category === 'system' ? `${name}.${key}` : key, val, cfg[key].type || 'text',
|
||||
cfg[key].name || key, cfg[key].desc || '',
|
||||
),
|
||||
);
|
||||
}
|
||||
logger.info('Config load: %s', i);
|
||||
} catch (e) {
|
||||
app.injectUI('Notification', 'Config load fail: {0}', { args: [i], type: 'warn' }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION);
|
||||
logger.error('Config Load Fail: %s', i);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import { load } from '../options';
|
||||
import { MongoService } from '../service/db';
|
||||
import { ConfigService } from '../settings';
|
||||
import {
|
||||
addon, builtinModel, locale, model, service, setting,
|
||||
addon, builtinModel, locale, model, service,
|
||||
} from './common';
|
||||
|
||||
const argv = cac().parse();
|
||||
@@ -53,11 +53,10 @@ export async function apply(ctx: Context) {
|
||||
require('../lib/index');
|
||||
|
||||
ctx.plugin(require('../service/monitor'));
|
||||
ctx.plugin(require('../service/check'));
|
||||
ctx.plugin(require('../service/check').default);
|
||||
await service(pending, fail, ctx);
|
||||
await builtinModel(ctx);
|
||||
await model(pending, fail, ctx);
|
||||
await setting(pending, fail, require('../model/setting'));
|
||||
ctx = await new Promise((resolve) => {
|
||||
ctx.inject(['worker', 'setting'], (c) => {
|
||||
resolve(c);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// TODO check more
|
||||
|
||||
import os from 'os';
|
||||
import { Dictionary } from 'lodash';
|
||||
import { DisposableList } from '@cordisjs/core';
|
||||
import { Context, Service } from '../context';
|
||||
import * as system from '../model/system';
|
||||
import db from './db';
|
||||
@@ -11,7 +11,7 @@ type ReportFunction = (message: string, ...args: any[]) => Promise<void>;
|
||||
type CheckItem = (context: any, log: ReportFunction, warn: ReportFunction, error: ReportFunction) => Promise<void>;
|
||||
|
||||
export default class CheckService extends Service {
|
||||
checkers: Dictionary<CheckItem> = {};
|
||||
checkers = new DisposableList<CheckItem>();
|
||||
c = {};
|
||||
|
||||
constructor(ctx: Context) {
|
||||
@@ -51,24 +51,19 @@ export default class CheckService extends Service {
|
||||
}
|
||||
|
||||
addChecker(type: string, checkFunc: CheckItem) {
|
||||
this.ctx.effect(() => {
|
||||
this.checkers[`check${type}`] = checkFunc;
|
||||
return () => {
|
||||
delete this.checkers[`check${type}`];
|
||||
};
|
||||
});
|
||||
this.checkers.push(checkFunc);
|
||||
}
|
||||
|
||||
async run(ctx, log, warn, error, cb: (id: string) => void) {
|
||||
const id = String.random(6);
|
||||
cb(id);
|
||||
for (const name in this.checkers) {
|
||||
for (const check of this.checkers) {
|
||||
if (this.c[id]) {
|
||||
delete this.c[id];
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await this.checkers[name](ctx, log, warn, error);
|
||||
await check(ctx, log, warn, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user