fix: bulk-download 500 — archiver v8 export is a class, not a callable

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 <noreply@anthropic.com>
This commit is contained in:
Leon TonhäuserandClaude committed 2026-08-11 14:48:01 +02:00
1 parent 8eadd1f408
commit 5a76c4fbb4
2 files changed
+20 -4

No files matched your search

+5 -1
View File
@@ -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