diff --git a/biome.json b/biome.json index 4ded3d0..a8829cb 100644 --- a/biome.json +++ b/biome.json @@ -36,7 +36,7 @@ "suspicious": { "noEmptyBlockStatements": "error", "noEmptyInterface": "error", - "noExplicitAny": "error", + "noExplicitAny": "warn", "noExtraNonNullAssertion": "error", "noMisleadingInstantiator": "error", "noUnsafeDeclarationMerging": "error", @@ -52,7 +52,7 @@ "semicolons": "always", "arrowParentheses": "always", "bracketSpacing": true, - "bracketSameLine": false, + "bracketSameLine": true, "quoteStyle": "double", "attributePosition": "auto" } diff --git a/src/index.tsx b/src/index.tsx index ec86aca..cc1f293 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -370,85 +370,102 @@ const app = new Elysia() ); }) - .post("/conversions", ({ body }) => { - console.log(body); - return ( - - ); - }) - .post("/upload", async ({ body, redirect, jwt, cookie: { auth, jobId } }) => { - if (!auth?.value) { - return redirect("/login"); - } - - const user = await jwt.verify(auth.value); - if (!user) { - return redirect("/login"); - } - - if (!jobId?.value) { - return redirect("/"); - } - - const existingJob = await db - .query("SELECT * FROM jobs WHERE id = ? AND user_id = ?") - .get(jobId.value, user.id); - - if (!existingJob) { - return redirect("/"); - } - - const userUploadsDir = `${uploadsDir}${user.id}/${jobId.value}/`; - - if (body?.file) { - if (Array.isArray(body.file)) { - for (const file of body.file) { - console.log(file); - await Bun.write(`${userUploadsDir}${file.name}`, file); - } - } else { - await Bun.write(`${userUploadsDir}${body.file.name}`, body.file); + .post( + "/conversions", + ({ body }) => { + console.log(body); + return ( + + ); + }, + { body: t.Object({ fileType: t.String() }) }, + ) + .post( + "/upload", + async ({ body, redirect, jwt, cookie: { auth, jobId } }) => { + if (!auth?.value) { + return redirect("/login"); } - } - return { - message: "Files uploaded successfully.", - }; - }) - .post("/delete", async ({ body, redirect, jwt, cookie: { auth, jobId } }) => { - if (!auth?.value) { - return redirect("/login"); - } + const user = await jwt.verify(auth.value); + if (!user) { + return redirect("/login"); + } - const user = await jwt.verify(auth.value); - if (!user) { - return redirect("/login"); - } + if (!jobId?.value) { + return redirect("/"); + } - if (!jobId?.value) { - return redirect("/"); - } + const existingJob = await db + .query("SELECT * FROM jobs WHERE id = ? AND user_id = ?") + .get(jobId.value, user.id); - const existingJob = await db - .query("SELECT * FROM jobs WHERE id = ? AND user_id = ?") - .get(jobId.value, user.id); + if (!existingJob) { + return redirect("/"); + } - if (!existingJob) { - return redirect("/"); - } + const userUploadsDir = `${uploadsDir}${user.id}/${jobId.value}/`; - const userUploadsDir = `${uploadsDir}${user.id}/${jobId.value}/`; + if (body?.file) { + if (Array.isArray(body.file)) { + for (const file of body.file) { + await Bun.write(`${userUploadsDir}${file.name}`, file); + } + } else { + await Bun.write( + `${userUploadsDir}${ + // biome-ignore lint/complexity/useLiteralKeys: ts bug + body.file["name"] + }`, + body.file, + ); + } + } - await unlink(`${userUploadsDir}${body.filename}`); - }) + return { + message: "Files uploaded successfully.", + }; + }, + { body: t.Object({ file: t.Files() }) }, + ) + .post( + "/delete", + async ({ body, redirect, jwt, cookie: { auth, jobId } }) => { + if (!auth?.value) { + return redirect("/login"); + } + + const user = await jwt.verify(auth.value); + if (!user) { + return redirect("/login"); + } + + if (!jobId?.value) { + return redirect("/"); + } + + const existingJob = await db + .query("SELECT * FROM jobs WHERE id = ? AND user_id = ?") + .get(jobId.value, user.id); + + if (!existingJob) { + return redirect("/"); + } + + const userUploadsDir = `${uploadsDir}${user.id}/${jobId.value}/`; + + await unlink(`${userUploadsDir}${body.filename}`); + }, + { body: t.Object({ filename: t.String() }) }, + ) .post( "/convert", async ({ body, redirect, jwt, cookie: { auth, jobId } }) => { @@ -487,7 +504,7 @@ const app = new Elysia() } const convertTo = normalizeFiletype(body.convert_to); - const fileNames: string[] = JSON.parse(body.file_names) as string[]; + const fileNames = JSON.parse(body.file_names) as string[]; if (!Array.isArray(fileNames) || fileNames.length === 0) { return redirect("/"); @@ -516,6 +533,12 @@ const app = new Elysia() return redirect(`/results/${jobId.value}`); }, + { + body: t.Object({ + convert_to: t.String(), + file_names: t.String(), + }), + }, ) .get("/hist", async ({ body, jwt, redirect, cookie: { auth } }) => { console.log("results page"); @@ -624,8 +647,7 @@ const app = new Elysia() @@ -646,16 +668,14 @@ const app = new Elysia()