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:
@@ -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,
|
||||
)
|
||||
@@ -54,6 +54,13 @@ class PermissionDeniedError(DomainError):
|
||||
code = "permission_denied"
|
||||
|
||||
|
||||
class NotSupportedError(DomainError):
|
||||
"""Operation is intentionally unsupported (e.g. a config knob that is managed
|
||||
via environment, not mutable at runtime)."""
|
||||
|
||||
code = "not_supported"
|
||||
|
||||
|
||||
class DependencyUnavailableError(DomainError):
|
||||
"""An external dependency (source, ML, MusicBrainz) is unavailable.
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ from app.domain.entities import (
|
||||
SubsonicCredentials,
|
||||
User,
|
||||
)
|
||||
from app.domain.entities.settings import UserSettings
|
||||
from app.domain.entities.track import Artist, Track
|
||||
from app.domain.sources import DownloadResult, RawMetadata, SearchResult, SourceFile, SourceInfo
|
||||
from app.domain.tokens import IssuedToken, TokenClaims, TokenType
|
||||
@@ -56,6 +57,11 @@ class UserRepository(Protocol):
|
||||
async def set_subsonic_password_enc(self, user_id: uuid.UUID, password_enc: str) -> None: ...
|
||||
|
||||
|
||||
class UserSettingsRepository(Protocol):
|
||||
async def get(self, user_id: uuid.UUID) -> UserSettings | None: ...
|
||||
async def upsert(self, settings: UserSettings) -> UserSettings: ...
|
||||
|
||||
|
||||
class SubsonicCipher(Protocol):
|
||||
"""Symmetric encrypt/decrypt for the recoverable Subsonic app-password."""
|
||||
|
||||
@@ -164,6 +170,12 @@ class TrackRepository(Protocol):
|
||||
# AlbumRepository below).
|
||||
async def genres(self) -> list[tuple[str, int]]: ...
|
||||
async def library_stats(self) -> LibraryStats: ...
|
||||
async def find_duplicate_groups(self) -> list[tuple[str, list[Track]]]: ...
|
||||
async def list_by_metadata_status(
|
||||
self, status: str, *, limit: int, offset: int
|
||||
) -> list[Track]: ...
|
||||
async def all_storage_refs(self) -> list[tuple[uuid.UUID, str]]: ...
|
||||
async def count_by_metadata_status(self, status: str) -> int: ...
|
||||
async def list(
|
||||
self,
|
||||
*,
|
||||
@@ -287,6 +299,7 @@ class PlaylistRepository(Protocol):
|
||||
async def reorder_tracks(
|
||||
self, playlist_id: uuid.UUID, ordered_track_ids: list[uuid.UUID]
|
||||
) -> None: ...
|
||||
async def get_cover_path(self, playlist_id: uuid.UUID) -> str | None: ...
|
||||
# list must come after any method using list[...] in its signature (name shadowing)
|
||||
async def list(self, *, owner_id: uuid.UUID, limit: int, offset: int) -> list[Playlist]: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user