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:
@@ -194,6 +194,78 @@ class SqlAlchemyTrackRepository:
|
||||
by_source={source: cnt for source, cnt in source_rows},
|
||||
)
|
||||
|
||||
async def find_duplicate_groups(self) -> list[tuple[str, list[Track]]]:
|
||||
"""Tracks that share an ``acoustid_fingerprint`` (the dedup key), grouped
|
||||
by it — only fingerprints with more than one track. Empty when clean.
|
||||
Defined before ``list`` for the same name-shadowing reason as ``genres``."""
|
||||
dup_fps = (
|
||||
select(TrackModel.acoustid_fingerprint)
|
||||
.where(TrackModel.acoustid_fingerprint.is_not(None))
|
||||
.group_by(TrackModel.acoustid_fingerprint)
|
||||
.having(func.count(TrackModel.id) > 1)
|
||||
.scalar_subquery()
|
||||
)
|
||||
rows = (
|
||||
(
|
||||
await self._session.execute(
|
||||
select(TrackModel)
|
||||
.where(TrackModel.acoustid_fingerprint.in_(dup_fps))
|
||||
.order_by(TrackModel.acoustid_fingerprint, TrackModel.created_at)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
groups: dict[str, list[Track]] = {}
|
||||
for row in rows:
|
||||
fingerprint = row.acoustid_fingerprint
|
||||
assert fingerprint is not None # filtered to non-null above
|
||||
groups.setdefault(fingerprint, []).append(_to_entity(row))
|
||||
return list(groups.items())
|
||||
|
||||
async def list_by_metadata_status(
|
||||
self, status: str, *, limit: int, offset: int
|
||||
) -> list[Track]:
|
||||
"""Tracks in a given ``metadata_status`` (e.g. ``pending``/``failed``),
|
||||
newest first. Defined before ``list`` (name-shadowing)."""
|
||||
rows = (
|
||||
(
|
||||
await self._session.execute(
|
||||
select(TrackModel)
|
||||
.where(TrackModel.metadata_status == status)
|
||||
.order_by(TrackModel.created_at.desc())
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
return [_to_entity(r) for r in rows]
|
||||
|
||||
async def all_storage_refs(self) -> list[tuple[uuid.UUID, str]]:
|
||||
"""``(id, storage_uri)`` for every *local* track — for the cleanup
|
||||
worker's filesystem reconciliation. Remote placeholders have no local
|
||||
file (``availability != local``) and are skipped. No entity hydration."""
|
||||
rows = (
|
||||
await self._session.execute(
|
||||
select(TrackModel.id, TrackModel.storage_uri).where(
|
||||
TrackModel.availability == TrackAvailability.LOCAL.value,
|
||||
TrackModel.storage_uri.is_not(None),
|
||||
)
|
||||
)
|
||||
).all()
|
||||
return [(row.id, row.storage_uri) for row in rows]
|
||||
|
||||
async def count_by_metadata_status(self, status: str) -> int:
|
||||
return (
|
||||
await self._session.execute(
|
||||
select(func.count())
|
||||
.select_from(TrackModel)
|
||||
.where(TrackModel.metadata_status == status)
|
||||
)
|
||||
).scalar_one()
|
||||
|
||||
async def list(
|
||||
self,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user