posts are marked as deleted to preserve array structure

This commit is contained in:
2025-07-28 15:11:26 +01:00
parent 38d82f9e1a
commit 39eba8fcda
4 changed files with 11 additions and 9 deletions

View File

@@ -32,7 +32,6 @@ Read the [configuation guide](docs/CONFIG.md) for configuration help (in config.
* probably insecure as hell * probably insecure as hell
# Planned features/todo list # Planned features/todo list
* URGENT give each post and user a hard postID to prevent potential issues
* edit user (could be on instead of the delete_account page) * edit user (could be on instead of the delete_account page)
* user specific RSS feeds * user specific RSS feeds
* atom * atom

View File

@@ -306,18 +306,18 @@ app.post("/submit_delete_account", (req,res) => {
if (password == users[userID]['hash']) { // password matches if (password == users[userID]['hash']) { // password matches
console.log(username, "(userID:", userID, ") is trying deleting their account") console.log(username, "(userID:", userID, ") is trying deleting their account")
// Delete the user // Delete the user
users.splice(userID,1) users[userID] = {"deleted": true}
// Delete all their posts // Delete all their posts
for (let postid = 0; postid < posts.length; postid++) { // loop over all posts for (let postid = 0; postid < posts.length; postid++) { // loop over all posts
if (posts[postid]['userID'] == userID) { // if userID matches if (posts[postid]['userID'] == userID) { // if userID matches
posts.splice(postid,1) // delete the post posts[postid] = {"deleted": true} // delete the post
comments.comments.splice(postid,1) // the comments for this post should also be delete comments.comments[postid] = {"deleted": true} // the comments for this post should also be deleted
} }
}; };
// Write these changes // Write these changes
fs.writeFileSync(`../data/users.json`, `${JSON.stringify(users)}`, 'utf-8'); fs.writeFileSync(`../data/users.json`, `${JSON.stringify(users)}`, 'utf-8');
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8'); fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments.comments)}\nexport const counter = ${comments.counter}`, 'utf-8'); fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
res.redirect(301,"/") res.redirect(301,"/")
} }
else { // password does not match else { // password does not match
@@ -354,8 +354,8 @@ app.post("/submit_edit", (req,res) => {
post['editdate'] = unix_timestamp post['editdate'] = unix_timestamp
if (typeof delete_bool != "undefined") { if (typeof delete_bool != "undefined") {
console.log("Deleting post!") console.log("Deleting post!")
posts.splice(postID,1) posts[postID] = {"deleted": true}
comments.comments.splice(postID,1) comments.comments[postID] = {"deleted": true}
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments.comments)}\nexport const counter = ${comments.counter}`, 'utf-8'); fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments.comments)}\nexport const counter = ${comments.counter}`, 'utf-8');
} }
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8'); fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');

View File

@@ -1,4 +1,5 @@
<h1> <h1>
<%- user.prettyname %>'s posts <%= user.prettyname %>'s posts
</h1> </h1>
<p><%- converter.makeHtml(user.description) %></p>
<%- config.seperator %> <%- config.seperator %>

View File

@@ -9,7 +9,9 @@
</div> </div>
<div id="posts"> <div id="posts">
<% for (let index = posts.length - 1; index >= 0; index--) { %> <% for (let index = posts.length - 1; index >= 0; index--) { %>
<%- include('../posts/timeline', {post: posts[index], index: index, user: users[posts[index].userID]}); %> <% if (posts[index]["deleted"] != true) { %>
<%- include('../posts/timeline', {post: posts[index], index: index, user: users[posts[index].userID]}); %>
<% } %>
<% } %> <% } %>
</div> </div>
<footer> <footer>