From d06bf3747134248d2fb1fdcb725339909329f984 Mon Sep 17 00:00:00 2001 From: Davide Mendolia Date: Sun, 24 May 2026 11:30:06 +0200 Subject: [PATCH] fix: propagate Content-Type from fetch through loadFileAsArrayBuffer Change return type to { data, contentType } so the fetched Content-Type header is available to callers. loadSourceFile uses it to set the Blob MIME type for https:/blob: URLs instead of always falling back to application/octet-stream. useAudioPeaks destructures only { data }. Co-Authored-By: Claude Sonnet 4.6 --- src/hooks/useAudioPeaks.ts | 2 +- src/lib/exporter/streamingDecoder.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/hooks/useAudioPeaks.ts b/src/hooks/useAudioPeaks.ts index 1538bc94..3be6ac61 100644 --- a/src/hooks/useAudioPeaks.ts +++ b/src/hooks/useAudioPeaks.ts @@ -94,7 +94,7 @@ export function useAudioPeaks(videoUrl?: string): Float32Array | null { (async () => { try { - const arrayBuffer = await loadFileAsArrayBuffer(videoUrl); + const { data: arrayBuffer } = await loadFileAsArrayBuffer(videoUrl); if (cancelled) return; const audioBuffer = await getAudioCtx().decodeAudioData(arrayBuffer); if (cancelled) return; diff --git a/src/lib/exporter/streamingDecoder.ts b/src/lib/exporter/streamingDecoder.ts index 71adfa12..6f28127c 100644 --- a/src/lib/exporter/streamingDecoder.ts +++ b/src/lib/exporter/streamingDecoder.ts @@ -140,9 +140,13 @@ export function shouldFailDecodeEndedEarly({ /** * Loads a video file as an ArrayBuffer, using the Electron IPC bridge for * local paths and falling back to `fetch` for remote / blob / data URLs. + * Also returns the `contentType` from the response headers (empty string for + * local IPC reads where no Content-Type is available). * This is the single canonical place for reading raw video bytes in the renderer. */ -export async function loadFileAsArrayBuffer(videoUrl: string): Promise { +export async function loadFileAsArrayBuffer( + videoUrl: string, +): Promise<{ data: ArrayBuffer; contentType: string }> { const isRemoteUrl = /^(https?:|blob:|data:)/i.test(videoUrl); if (!isRemoteUrl && window.electronAPI?.readBinaryFile) { @@ -150,14 +154,15 @@ export async function loadFileAsArrayBuffer(videoUrl: string): Promise { - const buffer = await this.withTimeout( + const { data: buffer, contentType } = await this.withTimeout( loadFileAsArrayBuffer(videoUrl), SOURCE_LOAD_TIMEOUT_MS, "Timed out while loading the source video.", @@ -198,6 +203,7 @@ export class StreamingVideoDecoder { const ext = mime.split("/")[1]?.replace(/[^a-z0-9]/gi, "") ?? ""; filename = ext ? `video.${ext}` : "video"; } else { + mime = contentType; filename = videoUrl.split(/[\\/]/).pop() || "video"; }