config: remove all setting.yaml

This commit is contained in:
undefined committed 2025-03-24 19:42:15 +08:00
1 parent e1f4f699b8
commit 9bdf241142
16 files changed
+373 -474

No files matched your search

+40 -42
View File
@@ -7,11 +7,49 @@ import * as system from '../model/system';
import db from './db';
import storage from './storage';
type CheckItem = (context: any, log: Function, warn: Function, error: Function) => Promise<void>;
type ReportFunction = (message: string, ...args: any[]) => Promise<void>;
type CheckItem = (context: any, log: ReportFunction, warn: ReportFunction, error: ReportFunction) => Promise<void>;
export class CheckService extends Service {
export default class CheckService extends Service {
checkers: Dictionary<CheckItem> = {};
c = {};
constructor(ctx: Context) {
super(ctx, 'check');
this.addChecker('Db', async (c, log, warn, error) => {
try {
const coll = db.collection('check');
const d = await coll.findOne({ _id: 'check' });
if (!d) await coll.insertOne({ _id: 'check', value: 'check' });
await coll.createIndex('check');
await coll.deleteOne({ _id: 'check' });
await coll.drop();
} catch (e) {
error(`Mongo Error: Database read-write failed.\n${e.message}`);
}
});
this.addChecker('Storage', async (c, log, warn, error) => {
const status = await storage.status();
if (!status.status) error(`Connect to ${status.type} Storage ${status.bucket} Error: ${status.error}`);
});
this.addChecker('System', async (c, log, warn) => {
const platform = os.platform();
if (platform !== 'linux') {
warn(`Hydro is running on ${platform}, suggest to use linux4.4+.`);
}
});
this.addChecker('Mail', async (c, log, warn) => {
const from = system.get('smtp.from');
if (!from) warn('SMTP account is not provided, email verification disabled.');
});
this.addChecker('Setting', async (c, log, warn) => {
const url = system.get('server.url');
if (url === '/') warn("server.url isn't set.");
const header = system.get('server.xff');
if (header && !c.request.ip) warn('IP header seems incorrect.\nCheck dashboard>settings>server.');
});
}
addChecker(type: string, checkFunc: CheckItem) {
this.ctx.effect(() => {
this.checkers[`check${type}`] = checkFunc;
@@ -38,43 +76,3 @@ export class CheckService extends Service {
this.c[id] = true;
}
}
export const check = new CheckService(app, 'check');
check.addChecker('Db', async (ctx, log, warn, error) => {
try {
const coll = db.collection('check');
const d = await coll.findOne({ _id: 'check' });
if (!d) await coll.insertOne({ _id: 'check', value: 'check' });
await coll.createIndex('check');
await coll.deleteOne({ _id: 'check' });
await coll.drop();
} catch (e) {
error(`Mongo Error: Database read-write failed.\n${e.message}`);
}
});
check.addChecker('Storage', async (ctx, log, warn, error) => {
const status = await storage.status();
if (!status.status) error(`Connect to ${status.type} Storage ${status.bucket} Error: ${status.error}`);
});
check.addChecker('System', async (ctx, log, warn) => {
const platform = os.platform();
if (platform !== 'linux') {
warn(`Hydro is running on ${platform}, suggest to use linux4.4+.`);
}
});
check.addChecker('Mail', async (ctx, log, warn) => {
const from = system.get('smtp.from');
if (!from) warn('SMTP account is not provided, email verification disabled.');
});
check.addChecker('Setting', async (ctx, log, warn) => {
const url = system.get('server.url');
if (url === '/') warn("server.url isn't set.");
const header = system.get('server.xff');
if (header && !ctx.request.ip) warn('IP header seems incorrect.\nCheck dashboard>settings>server.');
});
export async function apply(ctx: Context) {
ctx.provide('check', CheckService, true);
ctx.check = check;
}