Clean up changes

Seperated all routes into seperate files for neatness, and I've made the comments.json store only the comments, comments_counter is in the new data.json file which also stores the hitcount.

Signed-off-by: max <deadvey@localhost.localdomain>
This commit is contained in:
max
2025-09-24 10:02:28 +01:00
parent 0541b704db
commit 93c5f13750
11 changed files with 464 additions and 400 deletions

View File

@@ -0,0 +1,125 @@
const express = require('express');
const config = require('../../config')
const data = require('../data')
const func = require('../functions')
const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
const router = express.Router();
///////////////////// Standard Pages //////////////////////
router.get("/", (req,res) => {
// Increment the hitcount
if (config.enable_hitcount) {
func.increment_hitcount()
}
res.render("pages/timeline",
{
config,
locale,
posts: data.getdata("posts"),
users: data.getdata("users"),
comments: data.getdata("comments"),
hitcount: data.getdata("hitcount"),
fromUnixTime,
format,
getUnixTime,
func,
})
}); // /
router.get("/user/:username", (req, res) => {
const userID = func.get_userID(req.params.username)
console.log(data.getdata('users', 'id', userID)[0])
if (userID != -1) {
res.render("pages/user",
{
config,
locale,
posts: data.getdata('posts'),
user: data.getdata('users', 'id', userID),
userID: userID,
comments: data.getdata('comments'),
fromUnixTime,
format,
getUnixTime,
func,
})
}
else if (userID == -1) {
res.render("partials/message",
{
message: locale.user_doesnt_exist,
config,
})
}
}); // /user/:username
router.get("/post/:post_index", (req, res) => {
const postID = req.params.post_index
if (postID > posts.length-1 || posts[postID]["deleted"] == true) {
res.render("partials/message", {
message: locale.post_doesnt_exist,
config,
})
}
else if (typeof posts[postID]["deleted"] == "undefined" || posts[postID]["deleted"] == false) {
res.render("pages/post",
{
config,
locale,
post: posts[postID],
postID: postID,
user: users[posts[postID].userID],
comments: comments.comments[postID],
fromUnixTime,
format,
getUnixTime,
func,
})
}
else {
console.log("Error loading page")
res.redirect(301,"/")
}
}); // /post/:post_index
router.get("/tag/:tag", (req,res) => {
const tag = req.params.tag
res.render("pages/tag",
{
config,
locale,
tag,
posts,
users,
comments: comments.comments,
fromUnixTime: fromUnixTime,
format: format,
getUnixTime: getUnixTime,
func,
})
}); // /tag/:tag
router.get("/comment/:commentID", (req,res) => {
const commentID = req.params.commentID;
const comment = func.get_comment(commentID)
if (comment == -1) {
res.render("partials/message", {
config,
message: locale.comment_doesnt_exist,
})
}
else {
res.render("pages/comment",
{
config: config,
locale,
post: posts[comment["id"]],
users,
comment,
fromUnixTime: fromUnixTime,
format: format,
getUnixTime: getUnixTime,
func,
})
}
});
module.exports = router;