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:
25
src/data.js
25
src/data.js
@@ -15,7 +15,11 @@ export function increment_hitcount(postID = -1) { // -1 Means it will increment
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let post = getdata('posts','id', postID);
|
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;
|
post.hitcount += 1;
|
||||||
writedata('posts', post, postID)
|
writedata('posts', post, postID)
|
||||||
return 0
|
return 0
|
||||||
@@ -68,18 +72,27 @@ export function searchdata(term, type) { // Searches users and posts for any mat
|
|||||||
return search_results;
|
return search_results;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getdata(data_type, key=-1, value=-1) {
|
export function getdata(table_name, key=-1, value=-1) {
|
||||||
let result = undefined
|
let result = undefined
|
||||||
switch (config["data_storage"]) {
|
switch (config["data_storage"]) {
|
||||||
case 'json':
|
case 'json':
|
||||||
switch (data_type) {
|
switch (table_name) {
|
||||||
case 'users':
|
case 'users':
|
||||||
case 'posts':
|
case 'posts':
|
||||||
case 'comments':
|
case 'comments':
|
||||||
result = func.require_module(`../data/${data_type}.json`)
|
result = func.require_module(`../data/${table_name}.json`)
|
||||||
if (key != -1) {
|
if (key != -1) {
|
||||||
if (key == 'id' && value < result.length) { // id is the index
|
if (key == 'id')
|
||||||
return result[value]
|
{ // 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 result[func.find_key_value_pair(result, key, value)]
|
||||||
return -1 // This index doesn't exist
|
return -1 // This index doesn't exist
|
||||||
|
|||||||
@@ -38,14 +38,14 @@ router.get(`${config.edit_account_base_url}/:user_id`, (req,res) => {
|
|||||||
res.render("forms/edit_account", {
|
res.render("forms/edit_account", {
|
||||||
config,
|
config,
|
||||||
locale,
|
locale,
|
||||||
user: data.getdata('users', userID),
|
user: data.getdata('users', 'id', userID),
|
||||||
userID
|
userID
|
||||||
});
|
});
|
||||||
}); // /delete_account
|
}); // /delete_account
|
||||||
router.get(`${config.edit_post_base_url}/:post_id`, (req,res) => {
|
router.get(`${config.edit_post_base_url}/:post_id`, (req,res) => {
|
||||||
const postID = req.params.post_id
|
const postID = req.params.post_id
|
||||||
const post = data.getdata('posts', postID)
|
const post = data.getdata('posts','id', postID)
|
||||||
const user = data.getdata('users', post.userID)
|
const user = data.getdata('users', 'id', post.userID)
|
||||||
res.render("forms/edit_post", {
|
res.render("forms/edit_post", {
|
||||||
config,
|
config,
|
||||||
locale,
|
locale,
|
||||||
|
|||||||
@@ -68,10 +68,10 @@ router.get("/post/:post_index", (req, res) => {
|
|||||||
config,
|
config,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (config.enable_hitcount) {
|
else if (typeof post["deleted"] == "undefined" || post["deleted"] == false) {
|
||||||
data.increment_hitcount(postID)
|
if (config.enable_hitcount) {
|
||||||
}
|
data.increment_hitcount(postID)
|
||||||
if (typeof post["deleted"] == "undefined" || post["deleted"] == false) {
|
}
|
||||||
res.render("pages/post",
|
res.render("pages/post",
|
||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
|
|||||||
Reference in New Issue
Block a user