mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: config: refactor (allow schemastery)
This commit is contained in:
16 files changed
+373
-220
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user