feat: add delete button in history (#440)

This commit is contained in:
Emrik Östling 2025-11-16 00:34:49 +01:00 committed by GitHub
parent 0096a6f197
commit 64264a41d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 122 additions and 104 deletions

View file

@ -7,7 +7,7 @@ import { userService } from "./user";
import { Jobs } from "../db/types";
export const deleteJob = new Elysia().use(userService).get(
"/delete/:userId/:jobId",
"/delete/:jobId",
async ({ params, redirect, user }) => {
const job = db
.query("SELECT * FROM jobs WHERE user_id = ? AND id = ?")

View file

@ -12,6 +12,7 @@ export const download = new Elysia()
.get(
"/download/:userId/:jobId/:fileName",
async ({ params, redirect, user }) => {
const userId = user.id;
const job = await db
.query("SELECT * FROM jobs WHERE user_id = ? AND id = ?")
.get(user.id, params.jobId);
@ -20,7 +21,6 @@ export const download = new Elysia()
return redirect(`${WEBROOT}/results`, 302);
}
// parse from URL encoded string
const userId = decodeURIComponent(params.userId);
const jobId = decodeURIComponent(params.jobId);
const fileName = sanitize(decodeURIComponent(params.fileName));
@ -32,8 +32,9 @@ export const download = new Elysia()
},
)
.get(
"/archive/:userId/:jobId",
"/archive/:jobId",
async ({ params, redirect, user }) => {
const userId = user.id;
const job = await db
.query("SELECT * FROM jobs WHERE user_id = ? AND id = ?")
.get(user.id, params.jobId);
@ -42,7 +43,6 @@ 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 outputTar = path.join(outputPath, `converted_files_${jobId}.tar`);

View file

@ -5,6 +5,8 @@ import db from "../db/db";
import { Filename, Jobs } from "../db/types";
import { ALLOW_UNAUTHENTICATED, HIDE_HISTORY, LANGUAGE, WEBROOT } from "../helpers/env";
import { userService } from "./user";
import { EyeIcon } from "../icons/eye";
import { DeleteIcon } from "../icons/delete";
export const history = new Elysia().use(userService).get(
"/history",
@ -102,7 +104,7 @@ export const history = new Elysia().use(userService).get(
sm:px-4
`}
>
View
Actions
</th>
</tr>
</thead>
@ -131,7 +133,7 @@ export const history = new Elysia().use(userService).get(
<td>{job.num_files}</td>
<td class="max-sm:hidden">{job.finished_files}</td>
<td safe>{job.status}</td>
<td>
<td class="flex flex-row gap-4">
<a
class={`
text-accent-500 underline
@ -139,7 +141,16 @@ export const history = new Elysia().use(userService).get(
`}
href={`${WEBROOT}/results/${job.id}`}
>
View
<EyeIcon />
</a>
<a
class={`
text-accent-500 underline
hover:text-accent-400
`}
href={`${WEBROOT}/delete/${job.id}`}
>
<DeleteIcon />
</a>
</td>
</tr>

View file

@ -1,4 +1,3 @@
import { JWTPayloadSpec } from "@elysiajs/jwt";
import { Elysia } from "elysia";
import { BaseHtml } from "../components/base";
import { Header } from "../components/header";
@ -11,14 +10,10 @@ import { EyeIcon } from "../icons/eye";
import { userService } from "./user";
function ResultsArticle({
user,
job,
files,
outputPath,
}: {
user: {
id: string;
} & JWTPayloadSpec;
job: Jobs;
files: Filename[];
outputPath: string;
@ -30,7 +25,15 @@ function ResultsArticle({
<div class="flex flex-row gap-4">
<a
style={files.length !== job.num_files ? "pointer-events: none;" : ""}
href={`${WEBROOT}/archive/${user.id}/${job.id}`}
class="flex btn-secondary flex-row gap-2 text-contrast"
href={`${WEBROOT}/delete/${job.id}`}
{...(files.length !== job.num_files ? { disabled: true, "aria-busy": "true" } : "")}
>
<DeleteIcon /> <p>Delete</p>
</a>
<a
style={files.length !== job.num_files ? "pointer-events: none;" : ""}
href={`${WEBROOT}/archive/${job.id}`}
download={`converted_files_${job.id}.tar`}
class="flex btn-primary flex-row gap-2 text-contrast"
{...(files.length !== job.num_files ? { disabled: true, "aria-busy": "true" } : "")}
@ -40,14 +43,6 @@ function ResultsArticle({
<button class="flex btn-primary flex-row gap-2 text-contrast" onclick="downloadAll()">
<DownloadIcon /> <p>All</p>
</button>
<a
style={files.length !== job.num_files ? "pointer-events: none;" : ""}
class="flex btn-primary flex-row gap-2 text-contrast"
href={`${WEBROOT}/delete/${user.id}/${job.id}`}
{...(files.length !== job.num_files ? { disabled: true, "aria-busy": "true" } : "")}
>
<DeleteIcon /> <p>Delete</p>
</a>
</div>
</div>
<progress
@ -172,7 +167,7 @@ export const results = new Elysia()
sm:px-4
`}
>
<ResultsArticle user={user} job={job} files={files} outputPath={outputPath} />
<ResultsArticle job={job} files={files} outputPath={outputPath} />
</main>
<script src={`${WEBROOT}/results.js`} defer />
</>
@ -208,7 +203,7 @@ export const results = new Elysia()
.as(Filename)
.all(params.jobId);
return <ResultsArticle user={user} job={job} files={files} outputPath={outputPath} />;
return <ResultsArticle job={job} files={files} outputPath={outputPath} />;
},
{ auth: true },
);