Updated how comments are searched for
commentID's aren't neccesarily = to the index, so instead of using it as an index, I just use a for loop to find the matching comment. I also added another form at the bottom of the timeline to trick bots Signed-off-by: deadvey <deadvey@deadvey.com>
This commit is contained in:
@@ -111,12 +111,19 @@ router.get("/tag/:tag", (req,res) => {
|
||||
|
||||
// Comments
|
||||
router.get("/comment/:postID-:commentID", (req,res) => {
|
||||
const commentID = req.params.commentID;
|
||||
const postID = req.params.postID;
|
||||
const commentID = parseInt(req.params.commentID);
|
||||
const postID = parseInt(req.params.postID);
|
||||
|
||||
let posts_comments = data.getdata('comments', postID)
|
||||
let comment = posts_comments[commentID]
|
||||
if (comment == -1) {
|
||||
let comment = 1
|
||||
// For loop to find the comment with matching ID
|
||||
posts_comments.forEach((current_comment, index) => {
|
||||
if (current_comment.id == commentID) {
|
||||
comment = posts_comments[index]
|
||||
}
|
||||
})
|
||||
// If comment doesn't exist, show error
|
||||
if (comment == 1 || posts_comments == 1) { // Comment of this ID was not found
|
||||
res.render("partials/message", {
|
||||
config,
|
||||
message: locale.comment_doesnt_exist,
|
||||
|
@@ -22,6 +22,13 @@
|
||||
<% } %>
|
||||
<% } %>
|
||||
</div>
|
||||
<form method="POST" action="/submit_nothing" style="display:none">
|
||||
<!-- Form is used to help mitigate spam as it is the last form on the front page -->
|
||||
<input type="hidden" name="post_index" value="0">
|
||||
<input placeholder="username" name="name"><br/>
|
||||
<textarea placeholder="comment" name="content"></textarea><br/>
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
<footer>
|
||||
<%- include('../partials/footer'); %>
|
||||
</footer>
|
||||
|
Reference in New Issue
Block a user