debug: add detailed tracing logs for entire SF download→SpessaSynth flow

This commit is contained in:
2026-07-26 20:05:34 +07:00
parent 6242eba3c8
commit 5eb0c26ce4
2 changed files with 107 additions and 55 deletions
+7 -6
View File
@@ -127,22 +127,23 @@ async def delete_soundfont(sf_id: str, current_user: dict = Depends(get_current_
@router.get("/soundfonts/download/{sf_id}")
async def download_soundfont_asset(sf_id: str):
import logging as _lg
_log = _lg.getLogger("uvicorn.access")
clean_id = sf_id.replace("sf_", "") if sf_id.startswith("sf_") else sf_id
_log.info(f"[DOWNLOAD_DEBUG] sf_id={sf_id} clean_id={clean_id}")
for base_dir in [UPLOAD_SF_DIR, SYSTEM_SF_DIR]:
if not os.path.isdir(base_dir):
_log.info(f"[DOWNLOAD_DEBUG] dir NOT_FOUND: {base_dir}")
continue
for ext in [".sf2", ".sf3"]:
for fname in os.listdir(base_dir):
fbase, fext = os.path.splitext(fname)
if fext.lower() == ext and fbase.lower() == clean_id.lower():
full = os.path.join(base_dir, fname)
sz = os.path.getsize(full)
_log.info(f"[DOWNLOAD_DEBUG] SERVING: {full} ext={ext} size={sz}")
return FileResponse(full, media_type="application/octet-stream", filename=f"soundfont{ext}")
# Fallback: try exact match on sf_id
for base_dir in [UPLOAD_SF_DIR, SYSTEM_SF_DIR]:
for ext in [".sf2", ".sf3"]:
full = os.path.join(base_dir, clean_id + ext)
if os.path.exists(full):
return FileResponse(full, media_type="application/octet-stream", filename=f"soundfont{ext}")
_log.warning(f"[DOWNLOAD_DEBUG] NOT_FOUND for {sf_id}")
raise HTTPException(status_code=404, detail="SoundFont asset not found")