diff --git a/data/example-config.json b/data/example-config.json index 99fc2b5..8491f77 100755 --- a/data/example-config.json +++ b/data/example-config.json @@ -25,6 +25,7 @@ "user_exists": "Sorry, this user already exists, try a different username", "user_doesnt_exist": "Sorry, this user does not exist", "comment_doesnt_exist": "This comment doesn't exist, this could be because the post it was attached to was deleted", + "post_doesnt_exist": "This post doesn't exist or was deleted", "delete_account_confirmation": "Delete my account - (I agree that my account and all of my posts will be permanently deleted instantly)", "incorrect_password": "Incorrect Password", "rss_disabled": "Sorry, RSS is disabled", diff --git a/example-config.json b/example-config.json index aae04c1..5757ee0 100755 --- a/example-config.json +++ b/example-config.json @@ -9,7 +9,7 @@ "timeline_length": 20, "enable_hitcount": true, "charset": "UTF-8", - "root_path": "/path/to/blogger-webroot", + "root_path": "/path/to/webroot", "edit_account_base_url": "/edit_account", "new_post_url": "/post", "signup_url": "/signup", @@ -25,7 +25,8 @@ "user_exists": "Sorry, this user already exists, try a different username", "user_doesnt_exist": "Sorry, this user does not exist", "comment_doesnt_exist": "This comment doesn't exist, this could be because the post it was attached to was deleted", - "delete_account_confirmation": "I agree that my account and all of my posts will be permanently deleted instantly", + "post_doesnt_exist": "This post doesn't exist or was deleted", + "delete_account_confirmation": "Delete my account - (I agree that my account and all of my posts will be permanently deleted instantly)", "incorrect_password": "Incorrect Password", "rss_disabled": "Sorry, RSS is disabled", "attribution": "Powered by blogger-nodejs: Source Code, license (WTFPL)" diff --git a/src/server.js b/src/server.js index 7bbd208..6881ddb 100644 --- a/src/server.js +++ b/src/server.js @@ -186,19 +186,31 @@ app.get("/user/:username", (req, res) => { }); // /user/:username app.get("/post/:post_index", (req, res) => { const postID = req.params.post_index - res.render("pages/post", - { + if (posts[postID]["deleted"] == true) { + res.render("partials/message", { + message: config.string.post_doesnt_exist, config, - post: posts[postID], - postID: postID, - user: users[posts[postID].userID], - comments: comments.comments[postID], - fromUnixTime, - format, - getUnixTime, - func, - converter, }) + } + else if (typeof posts[postID]["deleted"] == "undefined" || posts[postID]["deleted"] == false) { + res.render("pages/post", + { + config, + post: posts[postID], + postID: postID, + user: users[posts[postID].userID], + comments: comments.comments[postID], + fromUnixTime, + format, + getUnixTime, + func, + converter, + }) + } + else { + console.log("Error loading page") + res.redirect(301,"/") + } }); // /post/:post_index app.get("/tag/:tag", (req,res) => { const tag = req.params.tag @@ -431,15 +443,15 @@ app.post("/submit_edit_user", (req,res) => { } }); // /submit_delete_account app.post("/submit_edit_post", (req,res) => { - const password = crypto.createHash('sha512').update(req.body.password).digest('hex'); - const postID = req.body.postID - const userID = req.body.userID - const title = req.body.title - const content = req.body.content - const tags = req.body.tags.split(','); - const delete_bool = req.body.delete - const unix_timestamp = getUnixTime(new Date()) - console.log(users[userID]['prettyname'], "is editting the post titled:", title); + const password = crypto.createHash('sha512').update(req.body.password).digest('hex'); + const postID = req.body.postID + const userID = req.body.userID + const title = req.body.title + const content = req.body.content + const tags = req.body.tags.split(','); + const delete_bool = req.body.delete + const unix_timestamp = getUnixTime(new Date()) + console.log(users[userID]['prettyname'], "is editting the post titled:", title); if (users[userID]['hash'] == password) { // password matches let post = posts[postID]