This commit is contained in:
undefined committed 2024-10-21 22:55:21 +08:00
1 parent 07f058ee28
commit 5d845f1471
1 file changed
+18 -3
+18 -3
View File
@@ -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 {