From 2ce3fee70be262a9e9daa558b70e89a23cb395f2 Mon Sep 17 00:00:00 2001 From: Maxime Date: Wed, 25 Jun 2025 14:34:27 +0200 Subject: [PATCH 1/4] added tar creation when using Download All --- bun.lock | 1 + package.json | 3 ++- public/results.js | 14 -------------- src/pages/download.tsx | 15 +++++++++------ src/pages/results.tsx | 28 +++++++++++++++++++--------- 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/bun.lock b/bun.lock index ec30c1f..4bdeb22 100644 --- a/bun.lock +++ b/bun.lock @@ -10,6 +10,7 @@ "@kitajs/html": "^4.2.9", "elysia": "^1.3.4", "sanitize-filename": "^1.6.3", + "tar": "^7.4.3", }, "devDependencies": { "@eslint/js": "^9.28.0", diff --git a/package.json b/package.json index 23a19bd..4ac248a 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "@elysiajs/static": "^1.3.0", "@kitajs/html": "^4.2.9", "elysia": "^1.3.4", - "sanitize-filename": "^1.6.3" + "sanitize-filename": "^1.6.3", + "tar": "^7.4.3" }, "module": "src/index.tsx", "type": "module", diff --git a/public/results.js b/public/results.js index 7659edb..b125e93 100644 --- a/public/results.js +++ b/public/results.js @@ -1,18 +1,4 @@ const webroot = document.querySelector("meta[name='webroot']").content; - -window.downloadAll = function () { - // Get all download links - const downloadLinks = document.querySelectorAll("a[download]"); - - // Trigger download for each link - downloadLinks.forEach((link, index) => { - // We add a delay for each download to prevent them from starting at the same time - setTimeout(() => { - const event = new MouseEvent("click"); - link.dispatchEvent(event); - }, index * 100); - }); -}; const jobId = window.location.pathname.split("/").pop(); const main = document.querySelector("main"); let progressElem = document.querySelector("progress"); diff --git a/src/pages/download.tsx b/src/pages/download.tsx index 917ee39..337fde0 100644 --- a/src/pages/download.tsx +++ b/src/pages/download.tsx @@ -4,6 +4,8 @@ import { outputDir } from ".."; import db from "../db/db"; import { WEBROOT } from "../helpers/env"; import { userService } from "./user"; +import path from "node:path"; +import * as tar from "tar"; export const download = new Elysia() .use(userService) @@ -35,8 +37,7 @@ export const download = new Elysia() return Bun.file(filePath); }, ) - .get("/zip/:userId/:jobId", async ({ params, jwt, redirect, cookie: { auth } }) => { - // TODO: Implement zip download + .get("/archive/:userId/:jobId", async ({ params, jwt, redirect, cookie: { auth } }) => { if (!auth?.value) { return redirect(`${WEBROOT}/login`, 302); } @@ -54,9 +55,11 @@ export const download = new Elysia() return redirect(`${WEBROOT}/results`, 302); } - // const userId = decodeURIComponent(params.userId); - // const jobId = decodeURIComponent(params.jobId); - // const outputPath = `${outputDir}${userId}/`{jobId}/); + const userId = decodeURIComponent(params.userId); + const jobId = decodeURIComponent(params.jobId); + const outputPath = `${outputDir}${userId}/${jobId}`; + const outputTar = path.join(outputPath, `converted_files_${jobId}.tar`) - // return Bun.zip(outputPath); + await tar.create({file: outputTar, cwd: outputPath, filter: (path) => { return path.match(".*\\.tar") ? false : true; }}, ["."]); + return Bun.file(outputTar); }); diff --git a/src/pages/results.tsx b/src/pages/results.tsx index 81e6128..edd70e7 100644 --- a/src/pages/results.tsx +++ b/src/pages/results.tsx @@ -6,12 +6,17 @@ import db from "../db/db"; import { Filename, Jobs } from "../db/types"; import { ALLOW_UNAUTHENTICATED, WEBROOT } from "../helpers/env"; import { userService } from "./user"; +import { JWTPayloadSpec } from "@elysiajs/jwt"; function ResultsArticle({ + user, job, files, outputPath, }: { + user: { + id: string; + } & JWTPayloadSpec; job: Jobs; files: Filename[]; outputPath: string; @@ -21,14 +26,19 @@ function ResultsArticle({

Results

- + +
- +