From 003d1d2b95511dd83e82cc1bfe399dcae62a4b87 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Wed, 10 Jun 2026 21:44:57 +0200 Subject: [PATCH] refactor(podcasts): stream public podcast audio via storage backend --- surfsense_backend/app/routes/public_chat_routes.py | 11 +++++++++++ surfsense_backend/app/services/public_chat_service.py | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/surfsense_backend/app/routes/public_chat_routes.py b/surfsense_backend/app/routes/public_chat_routes.py index 3181e117c..53f4c2651 100644 --- a/surfsense_backend/app/routes/public_chat_routes.py +++ b/surfsense_backend/app/routes/public_chat_routes.py @@ -99,6 +99,17 @@ async def stream_public_podcast( if not podcast_info: raise HTTPException(status_code=404, detail="Podcast not found") + storage_key = podcast_info.get("storage_key") + if storage_key: + from app.file_storage.factory import get_storage_backend + + return StreamingResponse( + get_storage_backend().open_stream(storage_key), + media_type="audio/mpeg", + headers={"Accept-Ranges": "bytes"}, + ) + + # Legacy fallback for snapshots taken before the storage migration. file_path = podcast_info.get("file_path") if not file_path or not os.path.isfile(file_path): diff --git a/surfsense_backend/app/services/public_chat_service.py b/surfsense_backend/app/services/public_chat_service.py index e4e0dd33a..d17f411b8 100644 --- a/surfsense_backend/app/services/public_chat_service.py +++ b/surfsense_backend/app/services/public_chat_service.py @@ -337,6 +337,9 @@ async def _get_podcast_for_snapshot( "original_id": podcast.id, "title": podcast.title, "transcript": podcast.podcast_transcript, + "storage_backend": podcast.storage_backend, + "storage_key": podcast.storage_key, + # Legacy fallback for rows rendered before the storage migration. "file_path": podcast.file_location, } @@ -717,6 +720,8 @@ async def clone_from_snapshot( new_podcast = Podcast( title=podcast_info.get("title", "Cloned Podcast"), podcast_transcript=podcast_info.get("transcript"), + storage_backend=podcast_info.get("storage_backend"), + storage_key=podcast_info.get("storage_key"), file_location=podcast_info.get("file_path"), status=PodcastStatus.READY, search_space_id=target_search_space_id,