From c6fb1ad6341293c17a2e788d82d40f4a72868084 Mon Sep 17 00:00:00 2001 From: Shrimbly Date: Thu, 26 Mar 2026 10:42:44 +1300 Subject: [PATCH] fix: correct API parameter names for media save/load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Critical bug fix - the mediaStorage.ts functions were using incorrect parameter names when calling the save-generation and load-generation APIs. Fixed parameter mappings: - workflowPath → directoryPath (API expects this name) - id → imageId (API expects this name) - data + type → video/audio (API expects media in named fields) - Changed load from GET to POST with correct body structure Also increased serverActions bodySizeLimit from 50mb to 100mb to handle large video files during externalization. This fixes the save failures when externalizing workflows with videos/audio. Co-Authored-By: Claude Sonnet 4.5 --- next.config.ts | 5 ++++- src/app/api/save-generation/route.ts | 2 ++ src/utils/mediaStorage.ts | 26 +++++++++++++------------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/next.config.ts b/next.config.ts index e2916b01..a3c62094 100644 --- a/next.config.ts +++ b/next.config.ts @@ -4,9 +4,12 @@ const nextConfig: NextConfig = { reactStrictMode: true, experimental: { serverActions: { - bodySizeLimit: "50mb", + bodySizeLimit: "100mb", // Increased for large media files }, }, + // Note: For route handlers (.../route.ts files), body size is controlled by + // the underlying server. For large payloads, consider using streaming or + // increase Node.js max HTTP header size if needed. turbopack: { root: __dirname, }, diff --git a/src/app/api/save-generation/route.ts b/src/app/api/save-generation/route.ts index d4f22c18..f5bfaabc 100644 --- a/src/app/api/save-generation/route.ts +++ b/src/app/api/save-generation/route.ts @@ -4,6 +4,8 @@ import * as path from "path"; import * as crypto from "crypto"; import { logger } from "@/utils/logger"; +export const maxDuration = 300; // 5 minute timeout for large media operations + // Helper to get file extension from MIME type function getExtensionFromMime(mimeType: string): string { const mimeToExt: Record = { diff --git a/src/utils/mediaStorage.ts b/src/utils/mediaStorage.ts index 16889120..17a3614d 100644 --- a/src/utils/mediaStorage.ts +++ b/src/utils/mediaStorage.ts @@ -613,10 +613,9 @@ async function saveVideoAndGetRef( method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ - workflowPath, - id: videoId, - data: videoData, - type: "video", + directoryPath: workflowPath, + imageId: videoId, + video: videoData, }), }, 60000 // 60s timeout for larger video files @@ -680,10 +679,9 @@ async function saveAudioAndGetRef( method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ - workflowPath, - id: audioId, - data: audioData, - type: "audio", + directoryPath: workflowPath, + imageId: audioId, + audio: audioData, }), }, 60000 // 60s timeout for larger audio files @@ -1038,12 +1036,14 @@ async function loadMediaById( response = await fetch(`/api/workflow-images?${params.toString()}`); } else { // Use load-generation API for videos and audio - const params = new URLSearchParams({ - workflowPath, - id: mediaId, + response = await fetch("/api/load-generation", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + directoryPath: workflowPath, + imageId: mediaId, + }), }); - - response = await fetch(`/api/load-generation?${params.toString()}`); } const result = await response.json();