From e155ab4aa72ac9834b04226d7f97bd60052d4afa Mon Sep 17 00:00:00 2001 From: Nulo Date: Fri, 8 Dec 2023 01:02:55 -0300 Subject: [PATCH] permitir ver dumps sin comprimir --- frontend/src/lib/dump.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/dump.ts b/frontend/src/lib/dump.ts index 539a545..b2c4e34 100644 --- a/frontend/src/lib/dump.ts +++ b/frontend/src/lib/dump.ts @@ -6,21 +6,25 @@ export async function downloadFile( datasetId: string, dist: Distribution, ) { + if (!dist.downloadURL) throw new Error("no downloadURL"); const outputS = streamSaver.createWriteStream( dist.downloadURL.slice(dist.downloadURL.lastIndexOf("/") + 1), ); - const res = await fetch( + const res = await fetchGzipped( `${dataPath}/${datasetId}/${dist.identifier}/${ dist.fileName || dist.identifier }.gz`, ); - const ds = new DecompressionStream("gzip"); - const decompressedStream = res.body!.pipeThrough(ds); - await decompressedStream.pipeTo(outputS); + await res.body!.pipeTo(outputS); } async function fetchGzipped(url: string): Promise { - const res = await fetch(url); + let res = await fetch(url); + if (res.status === 404 && url.endsWith(".gz")) { + // probar cargando el archivo no comprimido + res = await fetch(url.slice(0, url.length - ".gz".length)); + return res; + } const ds = new DecompressionStream("gzip"); const decompressedStream = res.body!.pipeThrough(ds); const resD = new Response(decompressedStream);