There is now a reply form on the comment pages to reply to that comment Syntax: >> postID-commentID Signed-off-by: deadvey <deadvey@deadvey.com>
133 lines
4.0 KiB
JavaScript
133 lines
4.0 KiB
JavaScript
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)
|
|
let user = data.getdata('users', userID)
|
|
if (userID != -1) {
|
|
res.render("pages/user",
|
|
{
|
|
config,
|
|
locale,
|
|
posts: data.getdata('posts'),
|
|
user,
|
|
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
|
|
let post = data.getdata('posts', postID)
|
|
|
|
if (post["deleted"] == true || post == 1) { // data.getdata returns error code 1 if nothing is available
|
|
res.render("partials/message", {
|
|
message: locale.post_doesnt_exist,
|
|
config,
|
|
})
|
|
}
|
|
else if (typeof post["deleted"] == "undefined" || post["deleted"] == false) {
|
|
res.render("pages/post",
|
|
{
|
|
config,
|
|
locale,
|
|
post,
|
|
postID,
|
|
user: data.getdata('users', post.userID),
|
|
comments: data.getdata('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: data.getdata('posts'),
|
|
users: data.getdata('users'),
|
|
comments: data.getdata('comments'),
|
|
fromUnixTime,
|
|
format,
|
|
getUnixTime,
|
|
func,
|
|
})
|
|
}); // /tag/:tag
|
|
router.get("/comment/:postID-:commentID", (req,res) => {
|
|
const commentID = req.params.commentID;
|
|
const postID = req.params.postID;
|
|
|
|
let posts_comments = data.getdata('comments', postID)
|
|
let comment = posts_comments[commentID]
|
|
if (comment == -1) {
|
|
res.render("partials/message", {
|
|
config,
|
|
message: locale.comment_doesnt_exist,
|
|
})
|
|
}
|
|
else {
|
|
res.render("pages/comment",
|
|
{
|
|
config,
|
|
locale,
|
|
comment,
|
|
postID,
|
|
commentID,
|
|
fromUnixTime,
|
|
format,
|
|
getUnixTime,
|
|
func,
|
|
})
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|