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:
1 parent
8eadd1f408
commit
5a76c4fbb4
2 files changed
+20
-4
No files matched your search
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user