Fixed a bug where comments could be submitted without any content
and where the hitcount was incremented before the program checked if the post existed
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
"new_post_url": "/post",
|
"new_post_url": "/post",
|
||||||
"signup_url": "/signup",
|
"signup_url": "/signup",
|
||||||
"edit_post_base_url": "/edit",
|
"edit_post_base_url": "/edit",
|
||||||
"default_comenter_username": "Anon",
|
"default_commenter_username": "Anon",
|
||||||
"rss": true,
|
"rss": true,
|
||||||
"atom": true,
|
"atom": true,
|
||||||
"date_format": "yyyy-MM-dd",
|
"date_format": "yyyy-MM-dd",
|
||||||
|
|||||||
@@ -19,21 +19,25 @@ router.post("/submit_comment", (req,res) => {
|
|||||||
const postID = parseInt(req.body.post_index)
|
const postID = parseInt(req.body.post_index)
|
||||||
const content = func.escape_input(req.body.content)
|
const content = func.escape_input(req.body.content)
|
||||||
let name = func.escape_input(req.body.name)
|
let name = func.escape_input(req.body.name)
|
||||||
if (name == "") {
|
// Give the user the default username if they left that bit blank
|
||||||
|
if (name == "" || typeof name == 'undefined') {
|
||||||
name = config.default_commenter_username
|
name = config.default_commenter_username
|
||||||
}
|
}
|
||||||
|
|
||||||
let comments = data.getdata('comments')
|
// Check there is actually content in the comment
|
||||||
|
if (content != '' && typeof content != 'undefined') {
|
||||||
|
let comments = data.getdata('comments')
|
||||||
|
|
||||||
new_comment = {
|
new_comment = {
|
||||||
"name": name,
|
"name": name,
|
||||||
"content": content,
|
"content": content,
|
||||||
"id": comments[postID].length,
|
"id": comments[postID].length,
|
||||||
"pubdate": unix_timestamp,
|
"pubdate": unix_timestamp,
|
||||||
"postID": postID,
|
"postID": postID,
|
||||||
};
|
};
|
||||||
comments[postID].push(new_comment);
|
comments[postID].push(new_comment);
|
||||||
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
|
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
|
||||||
|
}
|
||||||
|
|
||||||
res.redirect(301,`/post/${req.body.post_index}`)
|
res.redirect(301,`/post/${req.body.post_index}`)
|
||||||
}); // /submit_comment
|
}); // /submit_comment
|
||||||
|
|||||||
@@ -62,15 +62,15 @@ router.get("/user/:username", (req, res) => {
|
|||||||
router.get("/post/:post_index", (req, res) => {
|
router.get("/post/:post_index", (req, res) => {
|
||||||
const postID = parseInt(req.params.post_index)
|
const postID = parseInt(req.params.post_index)
|
||||||
let post = data.getdata('posts', postID)
|
let post = data.getdata('posts', postID)
|
||||||
if (config.enable_hitcount) {
|
|
||||||
data.increment_hitcount(postID)
|
|
||||||
}
|
|
||||||
if (post == 1) { // data.getdata returns error code 1 if nothing is available
|
if (post == 1) { // data.getdata returns error code 1 if nothing is available
|
||||||
res.render("partials/message", {
|
res.render("partials/message", {
|
||||||
message: locale.post_doesnt_exist,
|
message: locale.post_doesnt_exist,
|
||||||
config,
|
config,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (config.enable_hitcount) {
|
||||||
|
data.increment_hitcount(postID)
|
||||||
|
}
|
||||||
else if (typeof post["deleted"] == "undefined" || post["deleted"] == false) {
|
else if (typeof post["deleted"] == "undefined" || post["deleted"] == false) {
|
||||||
res.render("pages/post",
|
res.render("pages/post",
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ a:hover {
|
|||||||
hr {
|
hr {
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
.comment:nth-child(even) {
|
||||||
|
background: #1E1E1E;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: light) {
|
@media (prefers-color-scheme: light) {
|
||||||
@@ -46,4 +50,7 @@ a:hover {
|
|||||||
hr {
|
hr {
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
.comment:nth-child(even) {
|
||||||
|
background: #EEEEEE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user