Archived
Refactor UI assets and harden quality checks
This commit is contained in:
1 parent
23ab466c52
commit
4ecc8eb874
62 files changed
+3314
-3206
No files matched your search
+42
-24
@@ -153,16 +153,14 @@ def _hostname_status(
|
||||
account: Mapping[str, object],
|
||||
history: Sequence[Mapping[str, object]] | None = None,
|
||||
) -> HostnameStatusResponse:
|
||||
account_for_url = {"update_slug": str(account["update_slug"])}
|
||||
account_for_dashboard = {"management_slug": str(account.get("management_slug", ""))}
|
||||
return HostnameStatusResponse(
|
||||
hostname=str(account["hostname"]),
|
||||
status="active" if account.get("accepted_at") else "pending",
|
||||
update_url=service.fritz_update_url(account_for_url),
|
||||
dashboard_url=service.dashboard_url(account_for_dashboard) if account_for_dashboard["management_slug"] else "",
|
||||
ipv4=str(account["ipv4"]) if account.get("ipv4") else None,
|
||||
ipv6=str(account["ipv6"]) if account.get("ipv6") else None,
|
||||
updated_at=str(account["updated_at"]) if account.get("updated_at") else None,
|
||||
status=_account_status(account, include_disabled=False),
|
||||
update_url=service.fritz_update_url({"update_slug": str(account["update_slug"])}),
|
||||
dashboard_url=_dashboard_url(service, account),
|
||||
ipv4=_row_text(account, "ipv4"),
|
||||
ipv6=_row_text(account, "ipv6"),
|
||||
updated_at=_row_text(account, "updated_at"),
|
||||
history=[_hostname_update_event(event) for event in history or []],
|
||||
)
|
||||
|
||||
@@ -181,8 +179,8 @@ def _hostname_rotate_update_response(
|
||||
def _hostname_update_event(row: Mapping[str, object]) -> HostnameUpdateEvent:
|
||||
return HostnameUpdateEvent(
|
||||
hostname=str(row["hostname"]),
|
||||
ipv4=str(row["ipv4"]) if row.get("ipv4") else None,
|
||||
ipv6=str(row["ipv6"]) if row.get("ipv6") else None,
|
||||
ipv4=_row_text(row, "ipv4"),
|
||||
ipv6=_row_text(row, "ipv6"),
|
||||
status=str(row["status"]),
|
||||
detail=str(row["detail"]),
|
||||
created_at=str(row["created_at"]),
|
||||
@@ -193,12 +191,12 @@ def _hostname_update_event(row: Mapping[str, object]) -> HostnameUpdateEvent:
|
||||
def _admin_hostname(account: Mapping[str, object]) -> AdminHostname:
|
||||
return AdminHostname(
|
||||
hostname=str(account["hostname"]),
|
||||
status="disabled" if account.get("disabled") else ("active" if account.get("accepted_at") else "pending"),
|
||||
ipv4=str(account["ipv4"]) if account.get("ipv4") else None,
|
||||
ipv6=str(account["ipv6"]) if account.get("ipv6") else None,
|
||||
updated_at=str(account["updated_at"]) if account.get("updated_at") else None,
|
||||
created_at=str(account["created_at"]) if account.get("created_at") else None,
|
||||
accepted_at=str(account["accepted_at"]) if account.get("accepted_at") else None,
|
||||
status=_account_status(account),
|
||||
ipv4=_row_text(account, "ipv4"),
|
||||
ipv6=_row_text(account, "ipv6"),
|
||||
updated_at=_row_text(account, "updated_at"),
|
||||
created_at=_row_text(account, "created_at"),
|
||||
accepted_at=_row_text(account, "accepted_at"),
|
||||
disabled=bool(account.get("disabled")),
|
||||
)
|
||||
|
||||
@@ -212,8 +210,8 @@ def _admin_metrics(metrics: dict[str, float]) -> AdminMetrics:
|
||||
def _admin_record(row: Mapping[str, object]) -> AdminRecord:
|
||||
return AdminRecord(
|
||||
hostname=str(row["hostname"]),
|
||||
ipv4=str(row["ipv4"]) if row.get("ipv4") else None,
|
||||
ipv6=str(row["ipv6"]) if row.get("ipv6") else None,
|
||||
ipv4=_row_text(row, "ipv4"),
|
||||
ipv6=_row_text(row, "ipv6"),
|
||||
updated_at=str(row["updated_at"]),
|
||||
)
|
||||
|
||||
@@ -221,8 +219,8 @@ def _admin_record(row: Mapping[str, object]) -> AdminRecord:
|
||||
def _admin_update_event(row: Mapping[str, object]) -> AdminUpdateEvent:
|
||||
return AdminUpdateEvent(
|
||||
hostname=str(row["hostname"]),
|
||||
ipv4=str(row["ipv4"]) if row.get("ipv4") else None,
|
||||
ipv6=str(row["ipv6"]) if row.get("ipv6") else None,
|
||||
ipv4=_row_text(row, "ipv4"),
|
||||
ipv6=_row_text(row, "ipv6"),
|
||||
status=str(row["status"]),
|
||||
detail=str(row["detail"]),
|
||||
source_ip=str(row["source_ip"]),
|
||||
@@ -243,16 +241,36 @@ def _admin_scheduled_task(row: Mapping[str, object]) -> AdminScheduledTask:
|
||||
name=str(row["name"]),
|
||||
interval_seconds=_int_value(row["interval_seconds"], 0),
|
||||
next_run_at=str(row["next_run_at"]),
|
||||
lease_owner=str(row["lease_owner"]) if row.get("lease_owner") else None,
|
||||
lease_expires_at=str(row["lease_expires_at"]) if row.get("lease_expires_at") else None,
|
||||
last_started_at=str(row["last_started_at"]) if row.get("last_started_at") else None,
|
||||
last_finished_at=str(row["last_finished_at"]) if row.get("last_finished_at") else None,
|
||||
lease_owner=_row_text(row, "lease_owner"),
|
||||
lease_expires_at=_row_text(row, "lease_expires_at"),
|
||||
last_started_at=_row_text(row, "last_started_at"),
|
||||
last_finished_at=_row_text(row, "last_finished_at"),
|
||||
last_status=str(row["last_status"]),
|
||||
last_error=str(row["last_error"]),
|
||||
updated_at=str(row["updated_at"]),
|
||||
)
|
||||
|
||||
|
||||
def _row_text(row: Mapping[str, object], key: str) -> str | None:
|
||||
value = row.get(key)
|
||||
return str(value) if value else None
|
||||
|
||||
|
||||
def _account_status(account: Mapping[str, object], *, include_disabled: bool = True) -> str:
|
||||
if include_disabled and account.get("disabled"):
|
||||
return "disabled"
|
||||
if account.get("accepted_at"):
|
||||
return "active"
|
||||
return "pending"
|
||||
|
||||
|
||||
def _dashboard_url(service: DdnsService, account: Mapping[str, object]) -> str:
|
||||
management_slug = _row_text(account, "management_slug")
|
||||
if management_slug is None:
|
||||
return ""
|
||||
return service.dashboard_url({"management_slug": management_slug})
|
||||
|
||||
|
||||
def _int_value(value: object, default: int) -> int:
|
||||
if value is None:
|
||||
return default
|
||||
|
||||
Reference in new issue
Block a user