From 3d58c5b244f97285b7e5540e238b8ac5345458d5 Mon Sep 17 00:00:00 2001 From: deadvey Date: Sun, 30 Nov 2025 17:04:15 +0000 Subject: [PATCH] Some minor changes to data handling error messages and fixed a issue occuring in the forms routs that used the old parameters for data.getdata --- src/data.js | 25 +++++++++++++++++++------ src/routes/forms.js | 6 +++--- src/routes/standard_pages.js | 8 ++++---- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/data.js b/src/data.js index eaad5fe..937e7e9 100644 --- a/src/data.js +++ b/src/data.js @@ -15,7 +15,11 @@ export function increment_hitcount(postID = -1) { // -1 Means it will increment } else { let post = getdata('posts','id', postID); - if (typeof post.hitcount != 'undefined') { + if (post == 1) // Does not exist + { + return 1 + } + else if (typeof post.hitcount != 'undefined') { post.hitcount += 1; writedata('posts', post, postID) return 0 @@ -68,18 +72,27 @@ export function searchdata(term, type) { // Searches users and posts for any mat return search_results; }; -export function getdata(data_type, key=-1, value=-1) { +export function getdata(table_name, key=-1, value=-1) { let result = undefined switch (config["data_storage"]) { case 'json': - switch (data_type) { + switch (table_name) { case 'users': case 'posts': case 'comments': - result = func.require_module(`../data/${data_type}.json`) + result = func.require_module(`../data/${table_name}.json`) if (key != -1) { - if (key == 'id' && value < result.length) { // id is the index - return result[value] + if (key == 'id') + { // id is the index + if (value < result.length && value >= 0) + { + return result[value] + } + else + { + console.log("No object of this ID exists for the selected table") + return 1 + } } return result[func.find_key_value_pair(result, key, value)] return -1 // This index doesn't exist diff --git a/src/routes/forms.js b/src/routes/forms.js index 6d03969..568145b 100644 --- a/src/routes/forms.js +++ b/src/routes/forms.js @@ -38,14 +38,14 @@ router.get(`${config.edit_account_base_url}/:user_id`, (req,res) => { res.render("forms/edit_account", { config, locale, - user: data.getdata('users', userID), + user: data.getdata('users', 'id', userID), userID }); }); // /delete_account router.get(`${config.edit_post_base_url}/:post_id`, (req,res) => { const postID = req.params.post_id - const post = data.getdata('posts', postID) - const user = data.getdata('users', post.userID) + const post = data.getdata('posts','id', postID) + const user = data.getdata('users', 'id', post.userID) res.render("forms/edit_post", { config, locale, diff --git a/src/routes/standard_pages.js b/src/routes/standard_pages.js index 6ac781f..6133347 100644 --- a/src/routes/standard_pages.js +++ b/src/routes/standard_pages.js @@ -68,10 +68,10 @@ router.get("/post/:post_index", (req, res) => { config, }) } - if (config.enable_hitcount) { - data.increment_hitcount(postID) - } - if (typeof post["deleted"] == "undefined" || post["deleted"] == false) { + else if (typeof post["deleted"] == "undefined" || post["deleted"] == false) { + if (config.enable_hitcount) { + data.increment_hitcount(postID) + } res.render("pages/post", { config,