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
This commit is contained in:
2025-11-30 17:04:15 +00:00
parent 54b6f018cf
commit 3d58c5b244
3 changed files with 26 additions and 13 deletions

View File

@@ -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,19 +72,28 @@ 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
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
}

View File

@@ -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,

View File

@@ -68,10 +68,10 @@ router.get("/post/:post_index", (req, res) => {
config,
})
}
else if (typeof post["deleted"] == "undefined" || post["deleted"] == false) {
if (config.enable_hitcount) {
data.increment_hitcount(postID)
}
if (typeof post["deleted"] == "undefined" || post["deleted"] == false) {
res.render("pages/post",
{
config,