feat(api): finish Group A stubbed endpoints

Implements previously-stubbed /api/v1 endpoints (hexagonal: ports -> repos
-> services -> routers wired in deps):

- playlists: GET /{id}/cover (serves stored cover, 404 when absent)
- settings: GET/PATCH /settings + GET/PUT /settings/scrobbling — lazy
  per-user row, write-only Fernet-encrypted scrobble session key; adds
  user_settings table + migration (chains off dc126696f5a6)
- storage: GET /duplicates, /broken, /missing-metadata + admin POST
  /cleanup (arq cleanup_storage worker; reconciles local refs only,
  guarded against a storage-outage mass delete)
- admin: GET /services, /sources, /settings + POST /reindex; PATCH
  /settings and /sources/{source} return 501 (config is env-managed)

Adds NotSupportedError (-> HTTP 501). Integration tests for each surface.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Цвылев Александр Вадимович
2026-07-28 14:33:12 +03:00
parent df580578f6
commit a263272935
27 changed files with 1362 additions and 27 deletions
+34
View File
@@ -0,0 +1,34 @@
"""User settings domain entity (general preferences + scrobbling config)."""
import uuid
from dataclasses import dataclass
# Defaults for a user who has never saved settings — the row is created lazily,
# so reads return these before the first write.
DEFAULT_THEME = "system"
DEFAULT_STREAM_QUALITY = "original"
@dataclass(frozen=True, slots=True)
class UserSettings:
user_id: uuid.UUID
theme: str
stream_quality: str
scrobble_enabled: bool
scrobble_provider: str | None
scrobble_username: str | None
# Scrobbler session key / user token, encrypted at rest (never leaves the
# server in plaintext). ``None`` until the user configures scrobbling.
scrobble_session_key_enc: str | None
@classmethod
def defaults(cls, user_id: uuid.UUID) -> UserSettings:
return cls(
user_id=user_id,
theme=DEFAULT_THEME,
stream_quality=DEFAULT_STREAM_QUALITY,
scrobble_enabled=False,
scrobble_provider=None,
scrobble_username=None,
scrobble_session_key_enc=None,
)