refactor(server): extract the media/file-serving routes into routers/media.py (R3) (#869)

Song audio (/audio/{f}), the local-audio-path resolver (/api/audio-local-path),
and raw sloppak-member serving (/api/sloppak/{f}/file/{rel}) — plus the shared
_resolve_sloppak_local_file helper — move to lib/routers/media.py. Bodies verbatim
except @app->@router and the cache/static path seams (AUDIO_CACHE_DIR->
appstate.audio_cache_dir, STATIC_DIR->appstate.static_dir, SLOPPAK_CACHE_DIR->
appstate.sloppak_cache_dir — all already in the seam). No new slots.

The two test fixtures that redirect STATIC_DIR to a temp dir now also patch
appstate.static_dir (the moved routes read the seam, not server's global).

server.py: 2,638 -> 2,507 (-131).

Verified: pyflakes clean; route set identical (143), all unique-path (no
catch-all, no shadowing); full pytest 2395 passed (the audio-local-path +
sloppak-file-traversal cases). eslint 0. Boot smoke: /audio, /api/sloppak/{}/file
serve 404 for unknown, 0 tracebacks.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Byron Gamatos
2026-07-11 15:36:22 +02:00
committed by GitHub
co-authored by Claude Opus 4.8
parent b7624b7e65
commit 0547f55844
6 changed files with 171 additions and 137 deletions
+2
View File
@@ -25,6 +25,7 @@ def client_and_server(tmp_path, monkeypatch):
static_tmp = tmp_path / "static"
static_tmp.mkdir()
monkeypatch.setattr(server, "STATIC_DIR", static_tmp)
monkeypatch.setattr(server.appstate, "static_dir", static_tmp)
# Pass client=("127.0.0.1", 50000) so request.client.host is a loopback address
test_client = TestClient(server.app, client=("127.0.0.1", 50000))
try:
@@ -123,6 +124,7 @@ def dlc_client(tmp_path, monkeypatch):
static_tmp = tmp_path / "static"
static_tmp.mkdir()
monkeypatch.setattr(server, "STATIC_DIR", static_tmp)
monkeypatch.setattr(server.appstate, "static_dir", static_tmp)
tc = TestClient(server.app, client=("127.0.0.1", 50000))
try:
yield tc, server, dlc
+1
View File
@@ -37,6 +37,7 @@ def dlc_client(tmp_path, monkeypatch):
static_tmp = tmp_path / "static"
static_tmp.mkdir()
monkeypatch.setattr(server, "STATIC_DIR", static_tmp)
monkeypatch.setattr(server.appstate, "static_dir", static_tmp)
tc = TestClient(server.app, client=("127.0.0.1", 50000))
try:
yield tc, server, dlc