fix: workspace-aware media resolution + production-ready logging

- load_podcast_image_bytes now accepts user_id for workspace-aware resolution
- Video and avatar handlers pass user_id to image loading
- Strip JWT tokens from console logs (dev-only verbose logging)
- Guard debug logs behind NODE_ENV===development in SceneCard, useRenderQueue, SubscriptionContext, mediaCache
- Add devLogger utility
This commit is contained in:
ajaysi
2026-04-21 21:19:40 +05:30
parent 91b2f996fd
commit b1ca29f7f7
10 changed files with 66 additions and 30 deletions

View File

@@ -128,7 +128,7 @@ async def make_avatar_presentable(
# Load the uploaded avatar image
from ..utils import load_podcast_image_bytes
logger.info(f"[Podcast] Loading avatar image from {avatar_url}")
avatar_bytes = load_podcast_image_bytes(avatar_url)
avatar_bytes = load_podcast_image_bytes(avatar_url, user_id=user_id)
logger.info(f"[Podcast] Avatar loaded successfully - size={len(avatar_bytes)} bytes")
logger.info(f"[Podcast] Transforming avatar to podcast presenter for project {project_id}")

View File

@@ -69,7 +69,7 @@ async def generate_podcast_scene_image(
from ..utils import load_podcast_image_bytes
try:
logger.info(f"[Podcast] Attempting to load base avatar from: {request.base_avatar_url}")
base_avatar_bytes = load_podcast_image_bytes(request.base_avatar_url)
base_avatar_bytes = load_podcast_image_bytes(request.base_avatar_url, user_id=user_id)
logger.info(f"[Podcast] ✅ Successfully loaded base avatar ({len(base_avatar_bytes)} bytes) for scene {request.scene_id}")
except Exception as e:
logger.error(f"[Podcast] ❌ Failed to load base avatar from {request.base_avatar_url}: {e}", exc_info=True)

View File

@@ -321,7 +321,7 @@ async def generate_podcast_video(
# Load image bytes (scene image is required for video generation)
if body.avatar_image_url:
image_bytes = load_podcast_image_bytes(body.avatar_image_url)
image_bytes = load_podcast_image_bytes(body.avatar_image_url, user_id=user_id)
else:
# Scene-specific image should be generated before video generation
raise HTTPException(
@@ -332,7 +332,7 @@ async def generate_podcast_video(
mask_image_bytes = None
if body.mask_image_url:
try:
mask_image_bytes = load_podcast_image_bytes(body.mask_image_url)
mask_image_bytes = load_podcast_image_bytes(body.mask_image_url, user_id=user_id)
except Exception as e:
logger.error(f"[Podcast] Failed to load mask image: {e}")
raise HTTPException(

View File

@@ -67,15 +67,32 @@ def load_podcast_audio_bytes(audio_url: str, user_id: str | None = None) -> byte
raise HTTPException(status_code=500, detail=f"Failed to load audio: {str(exc)}")
def load_podcast_image_bytes(image_url: str) -> bytes:
"""Load podcast image bytes from URL. Uses centralized media loader."""
def load_podcast_image_bytes(image_url: str, user_id: str | None = None) -> bytes:
"""Load podcast image bytes from URL. Resolves from workspace first."""
if not image_url:
raise HTTPException(status_code=400, detail="Image URL is required")
logger.info(f"[Podcast] Loading image from URL: {image_url}")
try:
# REUSE: Use centralized media loader which handles cross-module lookups
# Extract filename from URL path
prefix = "/api/podcast/images/"
if prefix in image_url:
filename = image_url.split(prefix, 1)[1].split("?", 1)[0].strip()
# Handle subdirectories like avatars/
subdir = None
if "/" in filename:
subdir_part = filename.rsplit("/", 1)[0]
subdir = Path(subdir_part)
filename = filename.rsplit("/", 1)[1]
try:
image_path = _resolve_podcast_media_file(filename, "image", user_id, subdir=subdir)
return image_path.read_bytes()
except HTTPException:
pass # Fall through to centralized loader
# Fall back to centralized media loader
image_bytes = load_media_bytes(image_url)
if not image_bytes: