From c9b921becf3eb4b44d6585fd82dcd057f6cd043d Mon Sep 17 00:00:00 2001 From: Masahiko AMANO Date: Fri, 17 Feb 2023 23:51:45 +0300 Subject: [PATCH] fix(web): fix tdb response checking in js --- web/public/js/tdbms-database.js | 34 ++++++++++++++++----------------- web/public/js/tdbms-newdb.js | 6 +++--- web/public/js/tdbms-settings.js | 2 +- web/public/js/tdbms-stats.js | 2 +- web/public/js/tfm-database.js | 18 ++++++++--------- web/public/js/tfm-files.js | 2 +- web/public/js/tfm-management.js | 32 +++++++++++++++++-------------- web/public/js/tfm-settings.js | 4 ++-- web/public/js/tfm-tags.js | 2 +- 9 files changed, 53 insertions(+), 49 deletions(-) diff --git a/web/public/js/tdbms-database.js b/web/public/js/tdbms-database.js index cbf33c1..e569a23 100644 --- a/web/public/js/tdbms-database.js +++ b/web/public/js/tdbms-database.js @@ -4,11 +4,11 @@ $(document).on("click", "#btn-save", function (e) { return; } let resp = tdb_query(db_name, 4); - if (resp.status) { - alert("Successfully saved!"); - } else { + if (resp == null || !resp.status) { alert("Something went wrong!"); + return; } + alert("Successfully saved!"); }); $(document).on("click", "#btn-reload", function (e) { @@ -20,14 +20,14 @@ $(document).on("click", "#btn-reload", function (e) { return; } let resp = tdb_query(db_name, 2); - if (resp.status) { - localStorage["sasahyou_mts"] = sasahyou_mts = 0; - localStorage["sappyou_mts"] = sappyou_mts = 0; - localStorage["shoppyou_mts"] = shoppyou_mts = 0; - alert("Successfully reloaded database!"); - } else { + if (resp == null || !resp.status) { alert("Something went wrong!"); + return; } + localStorage["sasahyou_mts"] = sasahyou_mts = 0; + localStorage["sappyou_mts"] = sappyou_mts = 0; + localStorage["shoppyou_mts"] = shoppyou_mts = 0; + alert("Successfully reloaded database!"); }); $(document).on("click", "#btn-remove", function (e) { @@ -39,14 +39,14 @@ $(document).on("click", "#btn-remove", function (e) { return; } let resp = tdb_query(db_name, 1); - if (resp.status) { - localStorage.removeItem("db_name"); - db_name = null; - localStorage["sasahyou_mts"] = sasahyou_mts = 0; - localStorage["sappyou_mts"] = sappyou_mts = 0; - localStorage["shoppyou_mts"] = shoppyou_mts = 0; - alert("Successfully removed database!"); - } else { + if (resp == null || !resp.status) { alert("Something went wrong!"); + return; } + localStorage.removeItem("db_name"); + db_name = null; + localStorage["sasahyou_mts"] = sasahyou_mts = 0; + localStorage["sappyou_mts"] = sappyou_mts = 0; + localStorage["shoppyou_mts"] = shoppyou_mts = 0; + alert("Successfully removed database!"); }); diff --git a/web/public/js/tdbms-newdb.js b/web/public/js/tdbms-newdb.js index 288087f..5e2f43e 100644 --- a/web/public/js/tdbms-newdb.js +++ b/web/public/js/tdbms-newdb.js @@ -2,17 +2,17 @@ $(document).on("submit", "#newdb", function (e) { e.preventDefault(); let newdb_name = $("#newdb-name").val(), newdb_path = $("#newdb-path").val(); let resp = tdb_query(newdb_name, 3); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Failed to initialize database!"); return; } resp = tdb_query(newdb_name, 4, newdb_path); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Failed to save database!"); return; } resp = tdb_query(newdb_name, 6, "path=" + newdb_path); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Failed to finalize database!"); return; } diff --git a/web/public/js/tdbms-settings.js b/web/public/js/tdbms-settings.js index c4a99fb..7fa9ea2 100644 --- a/web/public/js/tdbms-settings.js +++ b/web/public/js/tdbms-settings.js @@ -30,7 +30,7 @@ function settings_load() { $(window).on("load", function () { let resp = tdb_query(); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Failed to fetch databases"); throw new Error("Failed to fetch databases"); } diff --git a/web/public/js/tdbms-stats.js b/web/public/js/tdbms-stats.js index e0d7ac4..ccf14c9 100644 --- a/web/public/js/tdbms-stats.js +++ b/web/public/js/tdbms-stats.js @@ -1,6 +1,6 @@ $(window).on("load", function (e) { let resp = tdb_query(db_name); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Failed to fetch database"); throw new Error("Failed to fetch database"); } diff --git a/web/public/js/tfm-database.js b/web/public/js/tfm-database.js index 48dcf2f..25a0381 100644 --- a/web/public/js/tfm-database.js +++ b/web/public/js/tfm-database.js @@ -9,11 +9,11 @@ $(document).on("click", "#btn-save", function (e) { return; } let resp = tdb_query(db_name, 4); - if (resp.status) { - alert("Successfully saved!"); - } else { + if (resp == null || !resp.status) { alert("Something went wrong!"); + return; } + alert("Successfully saved!"); }); $(document).on("click", "#btn-reload", function (e) { @@ -25,12 +25,12 @@ $(document).on("click", "#btn-reload", function (e) { return; } let resp = tdb_query(db_name, 2); - if (resp.status) { - localStorage["sasahyou_mts"] = sasahyou_mts = 0; - localStorage["sappyou_mts"] = sappyou_mts = 0; - localStorage["shoppyou_mts"] = shoppyou_mts = 0; - alert("Successfully reloaded database!"); - } else { + if (resp == null || !resp.status) { alert("Something went wrong!"); + return; } + localStorage["sasahyou_mts"] = sasahyou_mts = 0; + localStorage["sappyou_mts"] = sappyou_mts = 0; + localStorage["shoppyou_mts"] = shoppyou_mts = 0; + alert("Successfully reloaded database!"); }); diff --git a/web/public/js/tfm-files.js b/web/public/js/tfm-files.js index 8f0672a..1494988 100644 --- a/web/public/js/tfm-files.js +++ b/web/public/js/tfm-files.js @@ -21,7 +21,7 @@ $(window).on("load", function () { $(document).on("submit", "#menu-add form", function (e) { e.preventDefault(); let resp = tdb_query(db_name, 18, $("#new-name").val()); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Something went wrong!"); return; } diff --git a/web/public/js/tfm-management.js b/web/public/js/tfm-management.js index df78daf..ebe5bc9 100644 --- a/web/public/js/tfm-management.js +++ b/web/public/js/tfm-management.js @@ -26,7 +26,7 @@ function menu_view_file_open() { $("#menu-file-view .list-item").css("display", ""); $("#btn-full").attr("href", "/files/" + current_sasa.path); let resp = tdb_query(db_name, 24, '' + current_sasa.id); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Something went wrong!"); return; } @@ -59,7 +59,7 @@ function menu_view_tag_open() { $("#tag-name").val(decodeURI(current_tanzaku.name)); $("#description").val(current_tanzaku.desc); let resp = tdb_query(db_name, 40, '' + current_tanzaku.id); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Something went wrong!"); return; } @@ -262,7 +262,7 @@ $(document).on("reset", "#menu-add form", function (e) { $(document).on("submit", "#menu-file-view form", function (e) { e.preventDefault(); let resp = tdb_query(db_name, 24, '' + current_sasa.id); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Something went wrong!"); return; } @@ -280,11 +280,13 @@ $(document).on("submit", "#menu-file-view form", function (e) { } }); let status = true; - if (toadd !== "" && !tdb_query(db_name, 26, '' + current_sasa.id + toadd).status) { - status = false; + if (toadd !== "") { + resp = tdb_query(db_name, 26, '' + current_sasa.id + toadd); + status = (resp != null && resp.status); } - if (toremove !== "" && !tdb_query(db_name, 25, '' + current_sasa.id + toremove).status) { - status = false; + if (toremove !== "") { + resp = tdb_query(db_name, 25, '' + current_sasa.id + toremove); + status = (resp != null && resp.status); } if (status) { alert("Saved changes!"); @@ -300,7 +302,7 @@ $(document).on("submit", "#menu-tag-view form", function (e) { desc = $("#description").val(); if (name !== current_tanzaku.name || desc !== current_tanzaku.desc) { resp = tdb_query(db_name, 36, '' + current_tanzaku.id + ' ' + name + '\n' + desc); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Something went wrong!"); return; } @@ -309,7 +311,7 @@ $(document).on("submit", "#menu-tag-view form", function (e) { $(`.tanzaku[tid=${current_tanzaku.id}]`).text(name); } resp = tdb_query(db_name, 40, '' + current_tanzaku.id); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Something went wrong!"); return; } @@ -327,11 +329,13 @@ $(document).on("submit", "#menu-tag-view form", function (e) { } }); let status = true; - if (toadd !== "" && !tdb_query(db_name, 42, '' + current_tanzaku.id + toadd).status) { - status = false; + if (toadd !== "") { + resp = tdb_query(db_name, 42, '' + current_tanzaku.id + toadd); + status = (resp != null && resp.status); } - if (toremove !== "" && !tdb_query(db_name, 41, '' + current_tanzaku.id + toremove).status) { - status = false; + if (toremove !== "") { + resp = tdb_query(db_name, 41, '' + current_tanzaku.id + toremove); + status = (resp != null && resp.status); } if (status) { alert("Saved changes!"); @@ -346,7 +350,7 @@ $(document).on("click", "#btn-remove", function (e) { return; } let resp = tdb_query(db_name, 33, '' + current_tanzaku.id); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Something went wrong!"); return; } diff --git a/web/public/js/tfm-settings.js b/web/public/js/tfm-settings.js index af13e53..572ca03 100644 --- a/web/public/js/tfm-settings.js +++ b/web/public/js/tfm-settings.js @@ -40,7 +40,7 @@ function settings_load() { $(window).on("load", function () { let resp = tdb_query(); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Failed to fetch databases"); throw new Error("Failed to fetch databases"); } @@ -65,7 +65,7 @@ $(document).on("submit", "#settings", function (e) { let db_name_val = db_name_input.val(); if (db_name_val !== db_name) { let resp = tdb_query(); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Failed to fetch databases"); return; } diff --git a/web/public/js/tfm-tags.js b/web/public/js/tfm-tags.js index 1e7008c..f36ed6d 100644 --- a/web/public/js/tfm-tags.js +++ b/web/public/js/tfm-tags.js @@ -30,7 +30,7 @@ $(document).on("input", "#text-filter-all", function (e) { $(document).on("submit", "#menu-add form", function (e) { e.preventDefault(); let resp = tdb_query(db_name, 34, $("#new-name").val() + '\n' + $("#new-description").val()); - if (!resp.status) { + if (resp == null || !resp.status) { alert("Something went wrong!"); return; }