core: config: refactor (allow schemastery)

This commit is contained in:
undefined committed 2025-03-07 11:59:13 +08:00
1 parent f825fbe4f1
commit 31b4ed73f4
16 files changed
+373 -220

No files matched your search

+5 -7
View File
@@ -17,7 +17,6 @@ import { check } from '../service/check';
import {
ConnectionHandler, Handler, param, requireSudo, Types,
} from '../service/server';
import { configSource, saveConfig, SystemSettings } from '../settings';
import * as judge from './judge';
const logger = new Logger('manage');
@@ -184,27 +183,26 @@ class SystemConfigHandler extends SystemHandler {
@requireSudo
async get() {
this.response.template = 'manage_config.html';
let value = configSource;
let value = this.ctx.config.configSource;
try {
value = yaml.dump(Schema.intersect(SystemSettings)(yaml.load(configSource)));
value = yaml.dump(Schema.intersect(this.ctx.config.settings)(yaml.load(value)));
} catch (e) { }
this.response.body = {
schema: Schema.intersect(SystemSettings).toJSON(),
schema: Schema.intersect(this.ctx.config.settings).toJSON(),
value,
};
}
@requireSudo
@param('value', Types.String)
async post(domainId: string, value: string) {
async post({ }, value: string) {
let config;
try {
config = yaml.load(value);
Schema.intersect(SystemSettings)(config);
} catch (e) {
throw new ValidationError('value');
}
await saveConfig(config);
await this.ctx.config.saveConfig(config);
}
}
+1 -2
View File
@@ -15,7 +15,6 @@ import {
Handler, param, post, requireSudo, Types,
} from '../service/server';
import { encodeRFC5987ValueChars } from '../service/storage';
import { builtinConfig } from '../settings';
import { md5, sortFiles } from '../utils';
class SwitchLanguageHandler extends Handler {
@@ -110,7 +109,7 @@ export class StorageHandler extends Handler {
@param('expire', Types.UnsignedInt)
@param('secret', Types.String)
async get(domainId: string, target: string, filename = '', expire: number, secret: string) {
const expected = md5(`${target}/${expire}/${builtinConfig.file.secret}`);
const expected = md5(`${target}/${expire}/${this.ctx.config.get('file.secret')}`);
if (expire < Date.now()) throw new AccessDeniedError();
if (secret !== expected) throw new AccessDeniedError();
this.response.body = await storage.get(target);