From 5a76c4fbb455906f4bc5c52e6ad2a01c22d73abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Tonh=C3=A4user?= Date: Tue, 11 Aug 2026 14:48:01 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20bulk-download=20500=20=E2=80=94=20archiv?= =?UTF-8?q?er=20v8=20export=20is=20a=20class,=20not=20a=20callable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit archiver v8 changed its CJS export from a function to an object of class constructors ({ Archiver, ZipArchive, TarArchive, JsonArchive }). The route still called archiver('zip', opts), which throws `TypeError: archiver is not a function` — a deterministic throw in the main flow, returning 500. This was masked until the prior membership fix: before it, the empty assetToGrantedAlbum map made the route 404 at "No valid assets found" *before* reaching the archiver line. Once the map populated and downloads were authorized, execution reached archiver('zip') and threw. Fixed: `new archiver.ZipArchive({ zlib: { level: 0 } })` — same pipe/append/finalize/abort interface. Verified the full round-trip (append → finalize → Readable.toWeb → drain) produces a valid PK zip. Also surface the server error code in DownloadLightboxForm so future failures show the real code (status + {code}) in the browser console and alert instead of a generic "Download fehlgeschlagen". Co-Authored-By: Claude --- src/app/api/lightbox/bulk-download/route.ts | 6 +++++- .../leuchtkasten/DownloadLightboxForm.tsx | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/app/api/lightbox/bulk-download/route.ts b/src/app/api/lightbox/bulk-download/route.ts index 40f48ee..062500b 100644 --- a/src/app/api/lightbox/bulk-download/route.ts +++ b/src/app/api/lightbox/bulk-download/route.ts @@ -130,7 +130,11 @@ export async function POST(request: NextRequest) { } const passThrough = new PassThrough(); - const archive = archiver('zip', { zlib: { level: 0 } }); + // archiver v8 exports class constructors ({ ZipArchive, ... }), not a + // callable. The old `archiver('zip', opts)` form throws TypeError at + // runtime — which was masked until the membership fix populated the map + // and this line was actually reached (before, the route 404'd early). + const archive = new archiver.ZipArchive({ zlib: { level: 0 } }); archive.pipe(passThrough); // Start appending files asynchronously diff --git a/src/app/redaktion/leuchtkasten/DownloadLightboxForm.tsx b/src/app/redaktion/leuchtkasten/DownloadLightboxForm.tsx index 7edd505..30a5d93 100644 --- a/src/app/redaktion/leuchtkasten/DownloadLightboxForm.tsx +++ b/src/app/redaktion/leuchtkasten/DownloadLightboxForm.tsx @@ -23,7 +23,18 @@ export function DownloadLightboxForm({ assetIds }: { assetIds: string[] }) { }); if (!response.ok) { - throw new Error("Download fehlgeschlagen"); + // Surface the server's error code instead of a generic message so the + // real cause (e.g. IMMICH_UNAVAILABLE, REQUEST_FAILED) is visible in the + // browser console — the bulk handler maps UsageAccountingError to codes. + let code: string | undefined; + try { + code = (await response.clone().json()).code; + } catch { + /* non-JSON body (e.g. plain 500) — code stays undefined */ + } + const status = response.status; + console.error("[bulk-download] server error:", { status, code }); + throw new Error(`Download fehlgeschlagen (${status}${code ? ` ${code}` : ""})`); } // Download the ZIP file @@ -36,12 +47,13 @@ export function DownloadLightboxForm({ assetIds }: { assetIds: string[] }) { a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); - + dialogRef.current?.close(); setPurpose(""); router.refresh(); // Refresh to update usage history } catch (err) { - alert("Es gab einen Fehler beim Bulk-Download. Bitte versuche es später erneut."); + const message = err instanceof Error ? err.message : "Download fehlgeschlagen"; + alert(`Bulk-Download fehlgeschlagen: ${message}`); console.error(err); } finally { setLoading(false);