diff --git a/src/components/nodes/OutputNode.tsx b/src/components/nodes/OutputNode.tsx index 9e030601..e36c392f 100644 --- a/src/components/nodes/OutputNode.tsx +++ b/src/components/nodes/OutputNode.tsx @@ -1,6 +1,6 @@ "use client"; -import { useCallback, useState } from "react"; +import { useCallback, useState, useMemo } from "react"; import { Handle, Position, NodeProps, Node } from "@xyflow/react"; import { BaseNode } from "./BaseNode"; import { useWorkflowStore } from "@/store/workflowStore"; @@ -13,16 +13,55 @@ export function OutputNode({ id, data, selected }: NodeProps) { const updateNodeData = useWorkflowStore((state) => state.updateNodeData); const [showLightbox, setShowLightbox] = useState(false); - const handleDownload = useCallback(() => { - if (!nodeData.image) return; + // Determine if content is video + const isVideo = useMemo(() => { + if (nodeData.video) return true; + if (nodeData.contentType === "video") return true; + if (nodeData.image?.startsWith("data:video/")) return true; + if (nodeData.image?.includes(".mp4") || nodeData.image?.includes(".webm")) return true; + return false; + }, [nodeData.video, nodeData.contentType, nodeData.image]); + // Get the content source (video or image) + const contentSrc = useMemo(() => { + if (nodeData.video) return nodeData.video; + return nodeData.image; + }, [nodeData.video, nodeData.image]); + + const handleDownload = useCallback(async () => { + if (!contentSrc) return; + + const timestamp = Date.now(); + const filename = isVideo ? `generated-${timestamp}.mp4` : `generated-${timestamp}.png`; + + // Handle URL-based content (needs fetch + blob conversion) + if (contentSrc.startsWith("http://") || contentSrc.startsWith("https://")) { + try { + const response = await fetch(contentSrc); + const blob = await response.blob(); + const blobUrl = URL.createObjectURL(blob); + + const link = document.createElement("a"); + link.href = blobUrl; + link.download = filename; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(blobUrl); + } catch (error) { + console.error("Failed to download:", error); + } + return; + } + + // Handle data URL content (direct download) const link = document.createElement("a"); - link.href = nodeData.image; - link.download = `generated-${Date.now()}.png`; + link.href = contentSrc; + link.download = filename; document.body.appendChild(link); link.click(); document.body.removeChild(link); - }, [nodeData.image]); + }, [contentSrc, isVideo]); return ( <> @@ -43,18 +82,31 @@ export function OutputNode({ id, data, selected }: NodeProps) { data-handletype="image" /> - {nodeData.image ? ( + {contentSrc ? (
setShowLightbox(true)} > - Output -
+ {isVideo ? ( +