mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix #894
This commit is contained in:
1 file changed
+18
-3
@@ -352,7 +352,7 @@ class HomeSecurityHandler extends Handler {
|
||||
}
|
||||
|
||||
function set(s: Setting, key: string, value: any) {
|
||||
if (s) {
|
||||
if (!s) return undefined;
|
||||
if (s.family === 'setting_storage') return undefined;
|
||||
if (s.flag & setting.FLAG_DISABLED) return undefined;
|
||||
if ((s.flag & setting.FLAG_SECRET) && !value) return undefined;
|
||||
@@ -364,6 +364,16 @@ function set(s: Setting, key: string, value: any) {
|
||||
if (!Number.isSafeInteger(+value)) throw new ValidationError(key);
|
||||
return +value;
|
||||
}
|
||||
if (s.type === 'float') {
|
||||
if (Number.isNaN(+value)) throw new ValidationError(key);
|
||||
return +value;
|
||||
}
|
||||
if (['json', 'yaml', 'markdown', 'textarea'].includes(s.type)) {
|
||||
if (!Types.Content[1](value)) throw new ValidationError(key);
|
||||
}
|
||||
if (s.type === 'text') {
|
||||
if (!Types.String[1](value)) throw new ValidationError(key);
|
||||
}
|
||||
if (s.subType === 'yaml') {
|
||||
try {
|
||||
yaml.load(value);
|
||||
@@ -371,9 +381,14 @@ function set(s: Setting, key: string, value: any) {
|
||||
throw new ValidationError(key);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
if (s.subType === 'json') {
|
||||
try {
|
||||
JSON.parse(value);
|
||||
} catch (e) {
|
||||
throw new ValidationError(key);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
class HomeSettingsHandler extends Handler {
|
||||
|
||||
Reference in new issue
Block a user