ugghhhh new site_path config option

This commit is contained in:
2026-05-30 20:05:01 +01:00
parent 6e7d2109c8
commit f11b94527d
23 changed files with 91 additions and 89 deletions
+12 -12
View File
@@ -14,7 +14,7 @@ const crypto = require('crypto')
const router = express.Router();
////////////////////// Form actions /////////////////////////
router.post("/submit_comment", (req,res) => {
router.post(`${config.site_path}/submit_comment`, (req,res) => {
const unix_timestamp = getUnixTime(new Date())
const postID = parseInt(req.body.post_index)
const content = func.escape_input(req.body.content)
@@ -38,10 +38,10 @@ router.post("/submit_comment", (req,res) => {
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
}
res.redirect(301,`/post/${req.body.post_index}`)
res.redirect(301,`${config.site_path}/post/${req.body.post_index}`)
}); // /submit_comment
router.post("/submit_post", (req,res) => {
router.post(`${config.site_path}/submit_post`, (req,res) => {
const password = crypto.createHash('sha512').update(req.body.password).digest('hex');
const username = func.escape_input(req.body.username)
const title = func.escape_input(req.body.title)
@@ -71,7 +71,7 @@ router.post("/submit_post", (req,res) => {
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
comments.push({'id': id, 'comments': []})
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`)
res.redirect(302, "/");
res.redirect(302, config.site_path);
}
else {
res.render("partials/message", {
@@ -81,7 +81,7 @@ router.post("/submit_post", (req,res) => {
}
}); // /submit_post
router.post("/submit_signup", (req,res) => {
router.post(`${config.site_path}/submit_signup`, (req,res) => {
const password = crypto.createHash('sha512').update(req.body.password).digest('hex');
const username = func.escape_input(req.body.username)
const prettyname = func.escape_input(req.body.prettyname)
@@ -100,7 +100,7 @@ router.post("/submit_signup", (req,res) => {
"description": description,
})
fs.writeFileSync(`../data/users.json`, `${JSON.stringify(users)}`, 'utf-8');
res.redirect(301, `/user/${username}`)
res.redirect(301, `${config.site_path}/user/${username}`)
}
// if the user does exist then
else {
@@ -118,12 +118,12 @@ router.post("/submit_signup", (req,res) => {
}
// If allow_signup is undefined or not a boolean, error
else {
res.redirect(301,"/")
res.redirect(301,config.site_path)
console.log("Error, invalid value for allow_signup (bool)")
}
}); // /submit_signup
router.post("/submit_edit_user", (req,res) => {
router.post(`${config.site_path}/submit_edit_user`, (req,res) => {
// Get the form info
const password = crypto.createHash("sha512").update(req.body.password).digest("hex");
const userID = func.escape_input(req.body.userID)
@@ -152,7 +152,7 @@ router.post("/submit_edit_user", (req,res) => {
fs.writeFileSync(`../data/users.json`, `${JSON.stringify(users)}`, 'utf-8');
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
res.redirect(301,`/user/${users[userID]["username"]}`)
res.redirect(301,`${config.site_path}/user/${users[userID]["username"]}`)
}
else { // password does not match
res.render("partials/message", {
@@ -170,7 +170,7 @@ router.post("/submit_edit_user", (req,res) => {
}
}); // /submit_delete_account
router.post("/submit_edit_post", (req,res) => {
router.post(`${config.site_path}/submit_edit_post`, (req,res) => {
const password = crypto.createHash('sha512').update(req.body.password).digest('hex');
const postID = req.body.postID
const userID = req.body.userID
@@ -194,7 +194,7 @@ router.post("/submit_edit_post", (req,res) => {
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
}
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
res.redirect(302, "/");
res.redirect(302, config.site_path);
}
else {
res.render("partials/message", {
@@ -204,7 +204,7 @@ router.post("/submit_edit_post", (req,res) => {
}
}); // /submit_edit
router.get('/search', (req, res) => {
router.get(`${config.site_path}/search`, (req, res) => {
const search_term = func.escape_input(req.query.q); // 'q' is the parameter name
let search_type = req.query.type; // eg 'post', 'user'
if (typeof search_type == 'string') { // Make the search_term an array