Add files via upload

This commit is contained in:
Kosztyk 2025-12-04 22:07:58 +02:00 committed by GitHub
parent 4fd9862dbd
commit 1cdbd9e0f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 12 deletions

View file

@ -5,7 +5,6 @@ import { BaseHtml } from "../components/base";
import { Header } from "../components/header"; import { Header } from "../components/header";
import { getAllTargets } from "../converters/main"; import { getAllTargets } from "../converters/main";
import db from "../db/db"; import db from "../db/db";
import { User } from "../db/types";
import { import {
ACCOUNT_REGISTRATION, ACCOUNT_REGISTRATION,
ALLOW_UNAUTHENTICATED, ALLOW_UNAUTHENTICATED,
@ -76,7 +75,7 @@ export const root = new Elysia().use(userService).get(
(Number.parseInt(user.id) < 2 ** 24 || !ALLOW_UNAUTHENTICATED) (Number.parseInt(user.id) < 2 ** 24 || !ALLOW_UNAUTHENTICATED)
) { ) {
// Make sure user exists in db // Make sure user exists in db
const existingUser = db.query("SELECT * FROM users WHERE id = ?").as(User).get(user.id); const existingUser = db.query("SELECT * FROM users WHERE id = ?").get(user.id);
if (!existingUser) { if (!existingUser) {
if (auth?.value) { if (auth?.value) {
@ -115,10 +114,6 @@ export const root = new Elysia().use(userService).get(
const converters = await getAllTargets(); const converters = await getAllTargets();
const storedJobs = db.query(
"SELECT jobs.*, users.email FROM jobs INNER JOIN users ON jobs.user_id = users.id ORDER BY jobs.date_created DESC",
).all() as (User & { date_created: string; num_files: number; status: string })[];
return ( return (
<BaseHtml webroot={WEBROOT}> <BaseHtml webroot={WEBROOT}>
<> <>

View file

@ -1018,12 +1018,16 @@ export const user = new Elysia()
} }
} }
// delete this user's jobs and files (to avoid FK issues) // delete this user's jobs and files (to avoid FK issues) in a single transaction
const deleteUserTx = db.transaction((id: number) => {
db.query( db.query(
"DELETE FROM file_names WHERE job_id IN (SELECT id FROM jobs WHERE user_id = ?)", "DELETE FROM file_names WHERE job_id IN (SELECT id FROM jobs WHERE user_id = ?)",
).run(targetId); ).run(id);
db.query("DELETE FROM jobs WHERE user_id = ?").run(targetId); db.query("DELETE FROM jobs WHERE user_id = ?").run(id);
db.query("DELETE FROM users WHERE id = ?").run(targetId); db.query("DELETE FROM users WHERE id = ?").run(id);
});
deleteUserTx(targetId);
return redirect(`${WEBROOT}/account`, 302); return redirect(`${WEBROOT}/account`, 302);
}, },