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:
2025-09-24 21:12:21 +01:00
parent 23744f4000
commit 45af80f747
2 changed files with 18 additions and 4 deletions

View File

@@ -111,12 +111,19 @@ router.get("/tag/:tag", (req,res) => {
// Comments // Comments
router.get("/comment/:postID-:commentID", (req,res) => { router.get("/comment/:postID-:commentID", (req,res) => {
const commentID = req.params.commentID; const commentID = parseInt(req.params.commentID);
const postID = req.params.postID; const postID = parseInt(req.params.postID);
let posts_comments = data.getdata('comments', postID) let posts_comments = data.getdata('comments', postID)
let comment = posts_comments[commentID] let comment = 1
if (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", { res.render("partials/message", {
config, config,
message: locale.comment_doesnt_exist, message: locale.comment_doesnt_exist,

View File

@@ -22,6 +22,13 @@
<% } %> <% } %>
<% } %> <% } %>
</div> </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> <footer>
<%- include('../partials/footer'); %> <%- include('../partials/footer'); %>
</footer> </footer>