optimize settings helper

This commit is contained in:
Julian Krauser 2025-04-20 15:32:57 +02:00
parent 730c25a9a1
commit a8edc19f34
11 changed files with 343 additions and 119 deletions

View file

@ -1,8 +1,6 @@
import ms from "ms";
import { StringHelper } from "../helpers/stringHelper";
export type SettingTopic = "club" | "app" | "session" | "mail" | "backup" | "security";
export type SettingString =
| "club.name"
| "club.imprint"
@ -24,14 +22,38 @@ export type SettingString =
export type SettingTypeAtom = "longstring" | "string" | "ms" | "number" | "boolean" | "url";
export type SettingType = SettingTypeAtom | `${SettingTypeAtom}/crypt` | `${SettingTypeAtom}/rand`;
export const settingsType: {
[key in SettingString]: {
type: SettingType | SettingTypeAtom[];
default?: string | number | boolean | ms.StringValue;
optional?: boolean;
min?: number;
};
} = {
export type SettingValueMapping = {
"club.name": string;
"club.imprint": string;
"club.privacy": string;
"club.website": string;
"app.custom_login_message": string;
"app.show_link_to_calendar": boolean;
"session.jwt_expiration": ms.StringValue;
"session.refresh_expiration": ms.StringValue;
"session.pwa_refresh_expiration": ms.StringValue;
"mail.username": string;
"mail.password": string;
"mail.host": string;
"mail.port": number;
"mail.secure": boolean;
"backup.interval": number;
"backup.copies": number;
};
// Typsicherer Zugriff auf Settings
export type SettingDefinition<T extends SettingType | SettingTypeAtom[]> = {
type: T;
default?: string | number | boolean;
optional?: boolean;
min?: T extends "number" | `number/crypt` | `number/rand` ? number : never;
};
export type SettingsSchema = {
[key in SettingString]: SettingDefinition<SettingType | SettingTypeAtom[]>;
};
export const settingsType: SettingsSchema = {
"club.name": { type: "string", default: "FF Admin" },
"club.imprint": { type: "url", optional: true },
"club.privacy": { type: "url", optional: true },