From 6c65aa2eadb341519a098dade2dbde57ea970bd5 Mon Sep 17 00:00:00 2001 From: Nulo Date: Sat, 9 Dec 2023 14:05:44 -0300 Subject: [PATCH] frontend: decompressionstream polyfill --- downloader/package.json | 3 ++- frontend/package.json | 1 + frontend/src/lib/fetch.ts | 10 +++++++++- pnpm-lock.yaml | 16 ++++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/downloader/package.json b/downloader/package.json index 708e031..459e66b 100644 --- a/downloader/package.json +++ b/downloader/package.json @@ -11,9 +11,10 @@ "author": "", "license": "ISC", "dependencies": { + "common": "workspace:", "p-limit": "^5.0.0", "undici": "^5.28.0", - "common": "workspace:" + "zod": "^3.22.4" }, "devDependencies": { "@tsconfig/node20": "^20.1.2", diff --git a/frontend/package.json b/frontend/package.json index bff30b7..3c4a603 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -28,6 +28,7 @@ "vite": "^5.0.0" }, "dependencies": { + "compression-streams-polyfill": "^0.1.6", "eva-icons": "^1.1.3", "navaid": "^1.2.0", "regexparam": "^3.0.0", diff --git a/frontend/src/lib/fetch.ts b/frontend/src/lib/fetch.ts index 3a622bc..ae2f5b0 100644 --- a/frontend/src/lib/fetch.ts +++ b/frontend/src/lib/fetch.ts @@ -25,7 +25,15 @@ async function fetchGzipped(url: string): Promise { res = await fetch(url.slice(0, url.length - ".gz".length)); return res; } - const ds = new DecompressionStream("gzip"); + let DecStream; + if ("DecompressionStream" in window) DecStream = window.DecompressionStream; + else { + const { makeDecompressionStream } = await import( + "compression-streams-polyfill/ponyfill" + ); + DecStream = makeDecompressionStream(TransformStream); + } + const ds = new DecStream("gzip"); const decompressedStream = res.body!.pipeThrough(ds); const resD = new Response(decompressedStream); return resD; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0197cb6..24afbc6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,9 @@ importers: undici: specifier: ^5.28.0 version: 5.28.2 + zod: + specifier: ^3.22.4 + version: 3.22.4 devDependencies: '@tsconfig/node20': specifier: ^20.1.2 @@ -33,6 +36,9 @@ importers: frontend: dependencies: + compression-streams-polyfill: + specifier: ^0.1.6 + version: 0.1.6 eva-icons: specifier: ^1.1.3 version: 1.1.3 @@ -703,6 +709,12 @@ packages: engines: {node: '>= 10'} dev: true + /compression-streams-polyfill@0.1.6: + resolution: {integrity: sha512-vYXHeCzZPfKqz/ppInffY2HkevGbV6zm5wlSgtrW0+6neApbA5qZdG48KaDEhRmbIFhLgmVUlUc+szH9NrcaBA==} + dependencies: + fflate: 0.8.1 + dev: false + /concat-map@0.0.1: resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} dev: true @@ -888,6 +900,10 @@ packages: reusify: 1.0.4 dev: true + /fflate@0.8.1: + resolution: {integrity: sha512-/exOvEuc+/iaUm105QIiOt4LpBdMTWsXxqR0HDF35vx3fmaKzw7354gTilCh5rkzEt8WYyG//ku3h3nRmd7CHQ==} + dev: false + /fill-range@7.0.1: resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==} engines: {node: '>=8'}