From da98d0842a1d88c12c2c39827ecf8b1ec8466b75 Mon Sep 17 00:00:00 2001 From: empty Date: Wed, 7 Jan 2026 00:34:38 +0800 Subject: [PATCH] feat: Persist regenerated image/audio paths to storyboard.json --- api/routers/editor.py | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/api/routers/editor.py b/api/routers/editor.py index 3f4bfb9..fd37203 100644 --- a/api/routers/editor.py +++ b/api/routers/editor.py @@ -514,6 +514,27 @@ async def regenerate_frame_image( target_frame["image_path"] = _path_to_url(image_path) _storyboard_cache[storyboard_id] = storyboard + # Persist changes to storyboard.json + try: + from pixelle_video.services.persistence import PersistenceService + persistence = PersistenceService() + + # Load existing storyboard model + storyboard_model = await persistence.load_storyboard(storyboard_id) + if storyboard_model: + # Update the specific frame's image_path + for frame in storyboard_model.frames: + if f"frame-{frame.index}" == frame_id: + frame.image_path = image_path + logger.debug(f"[PERSIST] Updated frame {frame_id} image_path in model") + break + + # Save back to JSON + await persistence.save_storyboard(storyboard_id, storyboard_model) + logger.info(f"[PERSIST] Saved storyboard to JSON for {storyboard_id}") + except Exception as pe: + logger.warning(f"[PERSIST] Failed to persist storyboard: {pe}") + logger.info(f"Regenerated image for frame {frame_id} via RunningHub") return RegenerateImageResponse( @@ -605,6 +626,31 @@ async def regenerate_frame_audio( storyboard["total_duration"] = sum(f.get("duration", 3.0) for f in frames) _storyboard_cache[storyboard_id] = storyboard + # Persist changes to storyboard.json + try: + from pixelle_video.services.persistence import PersistenceService + persistence = PersistenceService() + + # Load existing storyboard model + storyboard_model = await persistence.load_storyboard(storyboard_id) + if storyboard_model: + # Update the specific frame's audio_path and duration + for frame in storyboard_model.frames: + if f"frame-{frame.index}" == frame_id: + frame.audio_path = result_path + frame.duration = duration + logger.debug(f"[PERSIST] Updated frame {frame_id} audio_path in model") + break + + # Update total duration + storyboard_model.total_duration = sum(f.duration or 3.0 for f in storyboard_model.frames) + + # Save back to JSON + await persistence.save_storyboard(storyboard_id, storyboard_model) + logger.info(f"[PERSIST] Saved storyboard to JSON for {storyboard_id}") + except Exception as pe: + logger.warning(f"[PERSIST] Failed to persist storyboard: {pe}") + logger.info(f"Regenerated audio for frame {frame_id}, duration: {duration}s") return RegenerateAudioResponse(