fix all errors in index

This commit is contained in:
C4illin 2024-05-21 15:50:30 +02:00
parent 4aeeaa5060
commit 74a9252077
2 changed files with 100 additions and 80 deletions

View file

@ -36,7 +36,7 @@
"suspicious": { "suspicious": {
"noEmptyBlockStatements": "error", "noEmptyBlockStatements": "error",
"noEmptyInterface": "error", "noEmptyInterface": "error",
"noExplicitAny": "error", "noExplicitAny": "warn",
"noExtraNonNullAssertion": "error", "noExtraNonNullAssertion": "error",
"noMisleadingInstantiator": "error", "noMisleadingInstantiator": "error",
"noUnsafeDeclarationMerging": "error", "noUnsafeDeclarationMerging": "error",
@ -52,7 +52,7 @@
"semicolons": "always", "semicolons": "always",
"arrowParentheses": "always", "arrowParentheses": "always",
"bracketSpacing": true, "bracketSpacing": true,
"bracketSameLine": false, "bracketSameLine": true,
"quoteStyle": "double", "quoteStyle": "double",
"attributePosition": "auto" "attributePosition": "auto"
} }

View file

@ -370,85 +370,102 @@ const app = new Elysia()
</BaseHtml> </BaseHtml>
); );
}) })
.post("/conversions", ({ body }) => { .post(
console.log(body); "/conversions",
return ( ({ body }) => {
<select name="convert_to" aria-label="Convert to" required> console.log(body);
<option selected disabled value=""> return (
Convert to <select name="convert_to" aria-label="Convert to" required>
</option> <option selected disabled value="">
{getPossibleConversions(body.fileType).map((target) => ( Convert to
// biome-ignore lint/correctness/useJsxKeyInIterable: <explanation> </option>
<option value={target}>{target}</option> {getPossibleConversions(body.fileType).map((target) => (
))} // biome-ignore lint/correctness/useJsxKeyInIterable: <explanation>
</select> <option value={target}>{target}</option>
); ))}
}) </select>
.post("/upload", async ({ body, redirect, jwt, cookie: { auth, jobId } }) => { );
if (!auth?.value) { },
return redirect("/login"); { body: t.Object({ fileType: t.String() }) },
} )
.post(
const user = await jwt.verify(auth.value); "/upload",
if (!user) { async ({ body, redirect, jwt, cookie: { auth, jobId } }) => {
return redirect("/login"); if (!auth?.value) {
} 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);
} }
}
return { const user = await jwt.verify(auth.value);
message: "Files uploaded successfully.", if (!user) {
}; return redirect("/login");
}) }
.post("/delete", async ({ body, redirect, jwt, cookie: { auth, jobId } }) => {
if (!auth?.value) {
return redirect("/login");
}
const user = await jwt.verify(auth.value); if (!jobId?.value) {
if (!user) { return redirect("/");
return redirect("/login"); }
}
if (!jobId?.value) { const existingJob = await db
return redirect("/"); .query("SELECT * FROM jobs WHERE id = ? AND user_id = ?")
} .get(jobId.value, user.id);
const existingJob = await db if (!existingJob) {
.query("SELECT * FROM jobs WHERE id = ? AND user_id = ?") return redirect("/");
.get(jobId.value, user.id); }
if (!existingJob) { const userUploadsDir = `${uploadsDir}${user.id}/${jobId.value}/`;
return redirect("/");
}
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( .post(
"/convert", "/convert",
async ({ body, redirect, jwt, cookie: { auth, jobId } }) => { async ({ body, redirect, jwt, cookie: { auth, jobId } }) => {
@ -487,7 +504,7 @@ const app = new Elysia()
} }
const convertTo = normalizeFiletype(body.convert_to); 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) { if (!Array.isArray(fileNames) || fileNames.length === 0) {
return redirect("/"); return redirect("/");
@ -516,6 +533,12 @@ const app = new Elysia()
return redirect(`/results/${jobId.value}`); return redirect(`/results/${jobId.value}`);
}, },
{
body: t.Object({
convert_to: t.String(),
file_names: t.String(),
}),
},
) )
.get("/hist", async ({ body, jwt, redirect, cookie: { auth } }) => { .get("/hist", async ({ body, jwt, redirect, cookie: { auth } }) => {
console.log("results page"); console.log("results page");
@ -624,8 +647,7 @@ const app = new Elysia()
<button <button
type="button" type="button"
style={{ width: "10rem", float: "right" }} style={{ width: "10rem", float: "right" }}
onclick="downloadAll()" onclick="downloadAll()">
>
Download All Download All
</button> </button>
</div> </div>
@ -646,16 +668,14 @@ const app = new Elysia()
<td>{file.output_file_name}</td> <td>{file.output_file_name}</td>
<td> <td>
<a <a
href={`/download/${outputPath}${file.output_file_name}`} href={`/download/${outputPath}${file.output_file_name}`}>
>
View View
</a> </a>
</td> </td>
<td> <td>
<a <a
href={`/download/${outputPath}${file.output_file_name}`} href={`/download/${outputPath}${file.output_file_name}`}
download={file.output_file_name} download={file.output_file_name}>
>
Download Download
</a> </a>
</td> </td>