typesave set Setting
This commit is contained in:
parent
b4a7986c8a
commit
70edd165ee
2 changed files with 19 additions and 11 deletions
|
@ -64,17 +64,19 @@ export default abstract class SettingHelper {
|
|||
* @param key The key of the setting
|
||||
* @param value The value to set
|
||||
*/
|
||||
public static async setSetting(key: SettingString, value: string): Promise<void> {
|
||||
public static async setSetting<K extends SettingString>(key: K, value: SettingValueMapping[K]): Promise<void> {
|
||||
if (value === undefined || value === null) return;
|
||||
|
||||
const stringValue = String(value);
|
||||
|
||||
const settingType = settingsType[key];
|
||||
this.validateSetting(key, value);
|
||||
this.validateSetting(key, stringValue);
|
||||
|
||||
const oldValue = this.getSetting(key);
|
||||
let finalValue = value;
|
||||
let finalValue = stringValue;
|
||||
|
||||
if (typeof settingType.type === "string" && settingType.type.includes("/crypt")) {
|
||||
finalValue = CodingHelper.encrypt(APPLICATION_SECRET, value);
|
||||
finalValue = CodingHelper.encrypt(APPLICATION_SECRET, stringValue);
|
||||
}
|
||||
|
||||
this.settings[key] = finalValue;
|
||||
|
@ -95,6 +97,8 @@ export default abstract class SettingHelper {
|
|||
* @param key The key of the setting
|
||||
*/
|
||||
public static async resetSetting(key: SettingString): Promise<void> {
|
||||
if (this.getSetting(key) == String(settingsType[key].default ?? "")) return;
|
||||
|
||||
const oldValue = this.getSetting(key);
|
||||
|
||||
const settingType = settingsType[key];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue