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