Archived
This commit is contained in:
1 parent
aadc19341d
commit
3841e93e32
13 files changed
+73
-24
No files matched your search
+14
-6
@@ -13,9 +13,8 @@ DEFAULT_BACKUP_RETENTION = 20
|
||||
|
||||
|
||||
def get_branding() -> dict[str, Any]:
|
||||
return {"name": _get("brand_name", "WGTools-Extended"),
|
||||
"color": _get("brand_color", "#8f1f27"),
|
||||
"logo": _get("brand_logo", "")}
|
||||
values = _get_many({"brand_name": "WGTools-Extended", "brand_color": "#8f1f27", "brand_logo": ""})
|
||||
return {"name": values["brand_name"], "color": values["brand_color"], "logo": values["brand_logo"]}
|
||||
|
||||
|
||||
def update_branding(name: str, color: str, logo: str) -> dict[str, Any]:
|
||||
@@ -68,6 +67,14 @@ def _get(key: str, default: str) -> str:
|
||||
return str(row["value"]) if row else default
|
||||
|
||||
|
||||
def _get_many(defaults: dict[str, str]) -> dict[str, str]:
|
||||
init_preferences()
|
||||
with _connect() as conn:
|
||||
placeholders = ",".join("?" for _ in defaults)
|
||||
rows = conn.execute(f"SELECT key,value FROM app_settings WHERE key IN ({placeholders})", tuple(defaults)).fetchall()
|
||||
return {**defaults, **{str(row["key"]): str(row["value"]) for row in rows}}
|
||||
|
||||
|
||||
def _set(key: str, value: str) -> None:
|
||||
init_preferences()
|
||||
with _connect() as conn:
|
||||
@@ -81,9 +88,10 @@ def _set(key: str, value: str) -> None:
|
||||
|
||||
|
||||
def get_preferences() -> dict[str, Any]:
|
||||
refresh = int(_get("refresh_seconds", str(REFRESH_SECONDS)))
|
||||
threshold = int(_get("online_threshold_seconds", str(ONLINE_THRESHOLD_SECONDS)))
|
||||
retention = int(_get("backup_retention", str(DEFAULT_BACKUP_RETENTION)))
|
||||
values = _get_many({"refresh_seconds": str(REFRESH_SECONDS), "online_threshold_seconds": str(ONLINE_THRESHOLD_SECONDS), "backup_retention": str(DEFAULT_BACKUP_RETENTION)})
|
||||
refresh = int(values["refresh_seconds"])
|
||||
threshold = int(values["online_threshold_seconds"])
|
||||
retention = int(values["backup_retention"])
|
||||
return {
|
||||
"refresh_seconds": max(2, min(refresh, 60)),
|
||||
"online_threshold_seconds": max(30, min(threshold, 3600)),
|
||||
|
||||
Reference in new issue
Block a user