From 50e9b861b0ecfcbb6e6db0bd1bad6abd584da91d Mon Sep 17 00:00:00 2001 From: C4illin Date: Sun, 26 May 2024 12:44:28 +0200 Subject: [PATCH] add safe --- prettier.config.cjs | 2 +- src/index.tsx | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/prettier.config.cjs b/prettier.config.cjs index c3ab6a8..561cb0c 100644 --- a/prettier.config.cjs +++ b/prettier.config.cjs @@ -10,4 +10,4 @@ const config = { plugins: ["@ianvs/prettier-plugin-sort-imports"], }; -export default config; \ No newline at end of file +export default config; diff --git a/src/index.tsx b/src/index.tsx index 2285e9d..d1d8664 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -32,8 +32,9 @@ const ACCOUNT_REGISTRATION = // convertedFiles : 0, // outputFiles: [], -// init db -db.exec(` +// init db if not exists +if (!db.query("SELECT * FROM sqlite_master WHERE type='table'").get()) { + db.exec(` CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT NOT NULL, @@ -54,7 +55,9 @@ CREATE TABLE IF NOT EXISTS jobs ( status TEXT DEFAULT 'not started', num_files INTEGER DEFAULT 0, FOREIGN KEY (user_id) REFERENCES users(id) -);`); +); +PRAGMA user_version = 1;`); +} const dbVersion = ( db.query("PRAGMA user_version").get() as { user_version?: number } @@ -64,6 +67,7 @@ if (dbVersion === 0) { "ALTER TABLE file_names ADD COLUMN status TEXT DEFAULT 'not started';", ); db.exec("PRAGMA user_version = 1;"); + console.log("Updated database to version 1."); } let FIRST_RUN = db.query("SELECT * FROM users").get() === null || false; @@ -454,7 +458,7 @@ const app = new Elysia() {targets.map((target) => ( // biome-ignore lint/correctness/useJsxKeyInIterable: - + ))} ))} @@ -481,7 +485,7 @@ const app = new Elysia() {targets.map((target) => ( // biome-ignore lint/correctness/useJsxKeyInIterable: - + ))} ), @@ -717,10 +721,10 @@ const app = new Elysia() {userJobs.map((job) => ( // biome-ignore lint/correctness/useJsxKeyInIterable: - {job.date_created} + {job.date_created} {job.num_files} {job.finished_files} - {job.status} + {job.status} View @@ -798,8 +802,8 @@ const app = new Elysia() {files.map((file) => ( // biome-ignore lint/correctness/useJsxKeyInIterable: - {file.output_file_name} - {file.status} + {file.output_file_name} + {file.status} @@ -886,8 +890,8 @@ const app = new Elysia() {files.map((file) => ( // biome-ignore lint/correctness/useJsxKeyInIterable: - {file.output_file_name} - {file.status} + {file.output_file_name} + {file.status} View @@ -966,13 +970,13 @@ const app = new Elysia() return ( // biome-ignore lint/correctness/useJsxKeyInIterable: - {converter} + {converter} Count: {inputs.length}
    {inputs.map((input) => ( // biome-ignore lint/correctness/useJsxKeyInIterable: -
  • {input}
  • +
  • {input}
  • ))}
@@ -981,7 +985,7 @@ const app = new Elysia()
    {targets.map((target) => ( // biome-ignore lint/correctness/useJsxKeyInIterable: -
  • {target}
  • +
  • {target}
  • ))}