feat(storage): library + disk statistics endpoint (§A6)
Implement `GET /api/v1/storage`, replacing the stub. Returns aggregate library facts (track/artist/album counts, total footprint, playtime, per-format / per-source / metadata-status breakdowns, top genres) plus the real capacity of the backing volume. - domain: `LibraryStats`, `FormatBreakdown`, `DiskUsage` value objects - ports: `FileStorage.disk_usage()` (local = shutil.disk_usage walking up to the nearest existing ancestor; S3 returns None — no fixed disk) - repo: `TrackRepository.library_stats()` (single set of GROUP BYs) - tests: storage stats API (auth, empty library, upload counting) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""Storage / library statistics response schemas (§A6)."""
|
||||
|
||||
import datetime as dt
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class DiskUsageOut(BaseModel):
|
||||
total: int
|
||||
used: int
|
||||
free: int
|
||||
|
||||
|
||||
class FormatBreakdownOut(BaseModel):
|
||||
file_format: str
|
||||
track_count: int
|
||||
total_size: int
|
||||
|
||||
|
||||
class GenreCountOut(BaseModel):
|
||||
genre: str
|
||||
track_count: int
|
||||
|
||||
|
||||
class StorageStatsOut(BaseModel):
|
||||
"""Everything the Storage screen needs in a single call."""
|
||||
|
||||
# library catalogue
|
||||
total_tracks: int
|
||||
total_artists: int
|
||||
total_albums: int
|
||||
total_size: int
|
||||
total_duration_seconds: int
|
||||
largest_track_size: int
|
||||
earliest_added: dt.datetime | None
|
||||
latest_added: dt.datetime | None
|
||||
|
||||
# breakdowns
|
||||
by_format: list[FormatBreakdownOut]
|
||||
by_metadata_status: dict[str, int]
|
||||
by_source: dict[str, int]
|
||||
top_genres: list[GenreCountOut]
|
||||
|
||||
# backing volume (``None`` for object-store backends)
|
||||
disk: DiskUsageOut | None
|
||||
Reference in New Issue
Block a user