Comment submission works

I fixed the comment submission to use the new way of storing comments and their counter.
I also fixed the AI-consent field in en-US because I accidently had · instead of spaces (from when I copy pasted from vim)

Signed-off-by: deadvey <deadvey@deadvey.com>
This commit is contained in:
2025-09-24 17:20:01 +01:00
parent bfaf957ae2
commit ef7178cc3f
3 changed files with 11 additions and 10 deletions

View File

@@ -1 +1 @@
{"hitcount":16,"comment_counter":1} {"hitcount":19}

View File

@@ -21,7 +21,7 @@
"incorrect_password": "Incorrect Password", "incorrect_password": "Incorrect Password",
"rss_disabled": "Sorry, RSS is disabled", "rss_disabled": "Sorry, RSS is disabled",
"atom_disabled": "Sorry, ATOM is disabled", "atom_disabled": "Sorry, ATOM is disabled",
"AI_consent": "The·content·on·this·website·may·not·be·copied,·scraped,·or·used·to·train·AI·models·or·large·language·models·(LLMs)·without·prior·written·consent.", "AI_consent": "The content on this website may not be copied, scraped, or used to train AI models or large language models (LLMs) without prior written consent.",
"rss_feed": "RSS Feed", "rss_feed": "RSS Feed",
"atom_feed": "ATOM Feed", "atom_feed": "ATOM Feed",

View File

@@ -16,23 +16,24 @@ const router = express.Router();
////////////////////// Form actions ///////////////////////// ////////////////////// Form actions /////////////////////////
router.post("/submit_comment", (req,res) => { router.post("/submit_comment", (req,res) => {
const unix_timestamp = getUnixTime(new Date()) const unix_timestamp = getUnixTime(new Date())
const postID = parseInt(req.body.post_index)
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 == "") { if (name == "") {
name = config.default_commenter_username name = config.default_commenter_username
} }
let comments = data.getdata('comments')
new_comment = { new_comment = {
"name": name, "name": name,
"content": func.escape_input(req.body.content), "content": content,
"id": data.getdata('other_data').comment_counter, "id": comments[postID].length,
"pubdate": unix_timestamp, "pubdate": unix_timestamp,
"postID": req.body.post_index, "postID": postID,
}; };
let other_data = data.getdata('other_data') comments[postID].push(new_comment);
other_data.comment_counter += 1;
let comments = data.getdata('comments')
comments[req.body.post_index].push(new_comment);
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8'); fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
fs.writeFileSync('../data/data.json', JSON.stringify(other_data), 'utf-8');
res.redirect(301,`/post/${req.body.post_index}`) res.redirect(301,`/post/${req.body.post_index}`)
}); // /submit_comment }); // /submit_comment