mirror of
https://github.com/C4illin/ConvertX.git
synced 2025-11-07 07:23:23 +00:00
added tar creation when using Download All
This commit is contained in:
1
bun.lock
1
bun.lock
@@ -10,6 +10,7 @@
|
|||||||
"@kitajs/html": "^4.2.9",
|
"@kitajs/html": "^4.2.9",
|
||||||
"elysia": "^1.3.4",
|
"elysia": "^1.3.4",
|
||||||
"sanitize-filename": "^1.6.3",
|
"sanitize-filename": "^1.6.3",
|
||||||
|
"tar": "^7.4.3",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.28.0",
|
"@eslint/js": "^9.28.0",
|
||||||
|
|||||||
@@ -20,7 +20,8 @@
|
|||||||
"@elysiajs/static": "^1.3.0",
|
"@elysiajs/static": "^1.3.0",
|
||||||
"@kitajs/html": "^4.2.9",
|
"@kitajs/html": "^4.2.9",
|
||||||
"elysia": "^1.3.4",
|
"elysia": "^1.3.4",
|
||||||
"sanitize-filename": "^1.6.3"
|
"sanitize-filename": "^1.6.3",
|
||||||
|
"tar": "^7.4.3"
|
||||||
},
|
},
|
||||||
"module": "src/index.tsx",
|
"module": "src/index.tsx",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -1,18 +1,4 @@
|
|||||||
const webroot = document.querySelector("meta[name='webroot']").content;
|
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 jobId = window.location.pathname.split("/").pop();
|
||||||
const main = document.querySelector("main");
|
const main = document.querySelector("main");
|
||||||
let progressElem = document.querySelector("progress");
|
let progressElem = document.querySelector("progress");
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { outputDir } from "..";
|
|||||||
import db from "../db/db";
|
import db from "../db/db";
|
||||||
import { WEBROOT } from "../helpers/env";
|
import { WEBROOT } from "../helpers/env";
|
||||||
import { userService } from "./user";
|
import { userService } from "./user";
|
||||||
|
import path from "node:path";
|
||||||
|
import * as tar from "tar";
|
||||||
|
|
||||||
export const download = new Elysia()
|
export const download = new Elysia()
|
||||||
.use(userService)
|
.use(userService)
|
||||||
@@ -35,8 +37,7 @@ export const download = new Elysia()
|
|||||||
return Bun.file(filePath);
|
return Bun.file(filePath);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.get("/zip/:userId/:jobId", async ({ params, jwt, redirect, cookie: { auth } }) => {
|
.get("/archive/:userId/:jobId", async ({ params, jwt, redirect, cookie: { auth } }) => {
|
||||||
// TODO: Implement zip download
|
|
||||||
if (!auth?.value) {
|
if (!auth?.value) {
|
||||||
return redirect(`${WEBROOT}/login`, 302);
|
return redirect(`${WEBROOT}/login`, 302);
|
||||||
}
|
}
|
||||||
@@ -54,9 +55,11 @@ export const download = new Elysia()
|
|||||||
return redirect(`${WEBROOT}/results`, 302);
|
return redirect(`${WEBROOT}/results`, 302);
|
||||||
}
|
}
|
||||||
|
|
||||||
// const userId = decodeURIComponent(params.userId);
|
const userId = decodeURIComponent(params.userId);
|
||||||
// const jobId = decodeURIComponent(params.jobId);
|
const jobId = decodeURIComponent(params.jobId);
|
||||||
// const outputPath = `${outputDir}${userId}/`{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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,12 +6,17 @@ import db from "../db/db";
|
|||||||
import { Filename, Jobs } from "../db/types";
|
import { Filename, Jobs } from "../db/types";
|
||||||
import { ALLOW_UNAUTHENTICATED, WEBROOT } from "../helpers/env";
|
import { ALLOW_UNAUTHENTICATED, WEBROOT } from "../helpers/env";
|
||||||
import { userService } from "./user";
|
import { userService } from "./user";
|
||||||
|
import { JWTPayloadSpec } from "@elysiajs/jwt";
|
||||||
|
|
||||||
function ResultsArticle({
|
function ResultsArticle({
|
||||||
|
user,
|
||||||
job,
|
job,
|
||||||
files,
|
files,
|
||||||
outputPath,
|
outputPath,
|
||||||
}: {
|
}: {
|
||||||
|
user: {
|
||||||
|
id: string;
|
||||||
|
} & JWTPayloadSpec;
|
||||||
job: Jobs;
|
job: Jobs;
|
||||||
files: Filename[];
|
files: Filename[];
|
||||||
outputPath: string;
|
outputPath: string;
|
||||||
@@ -21,14 +26,19 @@ function ResultsArticle({
|
|||||||
<div class="mb-4 flex items-center justify-between">
|
<div class="mb-4 flex items-center justify-between">
|
||||||
<h1 class="text-xl">Results</h1>
|
<h1 class="text-xl">Results</h1>
|
||||||
<div>
|
<div>
|
||||||
<button
|
<a
|
||||||
type="button"
|
style={files.length !== job.num_files ? "pointer-events: none;" : ""}
|
||||||
class="float-right w-40 btn-primary"
|
href={`${WEBROOT}/archive/${user.id}/${job.id}`}
|
||||||
onclick="downloadAll()"
|
download={`converted_files_${job.id}.tar`}
|
||||||
{...(files.length !== job.num_files ? { disabled: true, "aria-busy": "true" } : "")}
|
|
||||||
>
|
>
|
||||||
{files.length === job.num_files ? "Download All" : "Converting..."}
|
<button
|
||||||
</button>
|
type="button"
|
||||||
|
class="float-right w-40 btn-primary"
|
||||||
|
{...(files.length !== job.num_files ? { disabled: true, "aria-busy": "true" } : "")}
|
||||||
|
>
|
||||||
|
{files.length === job.num_files ? "Download All" : "Converting..."}
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<progress
|
<progress
|
||||||
@@ -170,7 +180,7 @@ export const results = new Elysia()
|
|||||||
sm:px-4
|
sm:px-4
|
||||||
`}
|
`}
|
||||||
>
|
>
|
||||||
<ResultsArticle job={job} files={files} outputPath={outputPath} />
|
<ResultsArticle user={user} job={job} files={files} outputPath={outputPath} />
|
||||||
</main>
|
</main>
|
||||||
<script src={`${WEBROOT}/results.js`} defer />
|
<script src={`${WEBROOT}/results.js`} defer />
|
||||||
</>
|
</>
|
||||||
@@ -211,5 +221,5 @@ export const results = new Elysia()
|
|||||||
.as(Filename)
|
.as(Filename)
|
||||||
.all(params.jobId);
|
.all(params.jobId);
|
||||||
|
|
||||||
return <ResultsArticle job={job} files={files} outputPath={outputPath} />;
|
return <ResultsArticle user={user} job={job} files={files} outputPath={outputPath} />;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user