diff --git a/src/functions.js b/src/functions.js
index 405026a..af3b94f 100644
--- a/src/functions.js
+++ b/src/functions.js
@@ -9,15 +9,15 @@ const locale = require(`../locales/${config.locale}.json`)
// https://stackoverflow.com/a/16060619
export function require_module(module)
{
- if (config.cache_data == false)
- {
- delete require.cache[require.resolve(module)];
- return require(module);
- }
- else
- {
- return require(module);
- }
+ if (config.cache_data == false)
+ {
+ delete require.cache[require.resolve(module)];
+ return require(module);
+ }
+ else
+ {
+ return require(module);
+ }
}
// The configuration defines a date format using the date-fns (a datetime library) syntax
@@ -27,7 +27,7 @@ export function require_module(module)
// returns the formatted date (string)
export function unix_time_to_date_format(unix_time)
{
- const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
+ const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
let date = fromUnixTime(unix_time)
let formatted_date = format(date, config.date_format)
return formatted_date
@@ -39,7 +39,7 @@ export function unix_time_to_date_format(unix_time)
// returns the formatted date (string)
export function unix_time_to_rss_date(unix_time)
{
- const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
+ const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
let date = fromUnixTime(unix_time)
let formatted_date = format(date, "EEE, dd MMM yyyy HH:mm:ss")
return `${formatted_date} ${config.time_zone}`
@@ -47,7 +47,7 @@ export function unix_time_to_rss_date(unix_time)
// And again with atom's date format
export function unix_time_to_atom_date(unix_time)
{
- const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
+ const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
let date = fromUnixTime(unix_time)
let formatted_date = format(date, "yyyy-MM-dd'T'HH:mm:ss'Z'")
return `${formatted_date}`
@@ -61,17 +61,17 @@ export function render_tags(tags)
{
tags = tags.filter((item, index) => tags.indexOf(item) === index) // Remove duplicate tags
let string = "" // Initialises the string
- if (tags.length == 1 && tags[0] == "")
- {
- string = ''; // If there are no tags, output nothing
- }
- else
- {
- for (let tag_index = 0; tag_index < tags.length; tag_index++)
- { // Loop over each tag
- string += `#${tags[tag_index].trim()} ` // Adds the tag to the string as a HTML href
- }
- }
+ if (tags.length == 1 && tags[0] == "")
+ {
+ string = ''; // If there are no tags, output nothing
+ }
+ else
+ {
+ for (let tag_index = 0; tag_index < tags.length; tag_index++)
+ { // Loop over each tag
+ string += `#${tags[tag_index].trim()} ` // Adds the tag to the string as a HTML href
+ }
+ }
return string
}
// The users are stored as a list of objects [ user_object, user_object, user_object ]
@@ -81,11 +81,11 @@ export function render_tags(tags)
// if the user is not present it returns -1
export function get_userID(username)
{
- const users = require_module("../data/users.json")
+ const users = require_module("../data/users.json")
for (let i = 0; i < users.length; i++)
- { // Loop over every user
+ { // Loop over every user
if (users[i]['username'] == username)
- {
+ {
return i // If the username matches then return the index of that user
}
}
@@ -98,46 +98,46 @@ export function get_userID(username)
// returns a string with some character replaced by their entities
export function escape_input(input)
{
- let output = input
- .replaceAll("&", "&") // This must be first
- .replaceAll("<", "<")
- .replaceAll(">", ">")
- .replaceAll("\\", "\")
- .replaceAll('"', """)
- .replaceAll("'", "'")
- .replaceAll("/", "/")
- .replaceAll("%", "%")
- return output
+ let output = input
+ .replaceAll("&", "&") // This must be first
+ .replaceAll("<", "<")
+ .replaceAll(">", ">")
+ .replaceAll("\\", "\")
+ .replaceAll('"', """)
+ .replaceAll("'", "'")
+ .replaceAll("/", "/")
+ .replaceAll("%", "%")
+ return output
}
// Render comment content by replacing the >> int with a url link to that comment
// Syntax: ">> postID-commentID"
export function render_comment(comment_content)
{
- return comment_content
- .replaceAll(/>> ([0-9]*)-([0-9]*)/g, ">> $1-$2")
- .replaceAll(/>>([0-9]*)-([0-9]*)/g, ">>$1-$2")
- .replaceAll(/>> ([0-9]*)-([0-9]*)/g, ">> $1-$2")
- .replaceAll(/>>([0-9]*)-([0-9]*)/g, ">>$1-$2")
- .replaceAll("\n", "
")
+ return comment_content
+ .replaceAll(/>> ([0-9]*)-([0-9]*)/g, ">> $1-$2")
+ .replaceAll(/>>([0-9]*)-([0-9]*)/g, ">>$1-$2")
+ .replaceAll(/>> ([0-9]*)-([0-9]*)/g, ">> $1-$2")
+ .replaceAll(/>>([0-9]*)-([0-9]*)/g, ">>$1-$2")
+ .replaceAll("\n", "
")
};
// Renders a string into markdown using markdown-it library
export function render_md(content)
{
- const markdownit = require("markdown-it")
- const md = markdownit
- ({ // this is just defining some options for markdown-it, should I add this to config.json?
- html: false,
- xhtmlOut: false,
- breaks: true,
- linkify: false,
- typographer: true,
- quotes: locale.quotes,
- })
+ const markdownit = require("markdown-it")
+ const md = markdownit
+ ({ // this is just defining some options for markdown-it, should I add this to config.json?
+ html: false,
+ xhtmlOut: false,
+ breaks: true,
+ linkify: false,
+ typographer: true,
+ quotes: locale.quotes,
+ })
.disable('image');
- return md.render(content)
+ return md.render(content)
};
export function find_key_value_pair(data_array, key, value) {
diff --git a/src/routes/form_actions.js b/src/routes/form_actions.js
index 5e97d4d..d52b7a8 100644
--- a/src/routes/form_actions.js
+++ b/src/routes/form_actions.js
@@ -15,193 +15,193 @@ const router = express.Router();
////////////////////// Form actions /////////////////////////
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)
- let name = func.escape_input(req.body.name)
- // Give the user the default username if they left that bit blank
- if (name == "" || typeof name == 'undefined') {
- name = config.default_commenter_username
- }
+ 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)
+ // Give the user the default username if they left that bit blank
+ if (name == "" || typeof name == 'undefined') {
+ name = config.default_commenter_username
+ }
- // Check there is actually content in the comment
- if (content != '' && typeof content != 'undefined') {
- let comments = data.getdata('comments')
+ // Check there is actually content in the comment
+ if (content != '' && typeof content != 'undefined') {
+ let comments = data.getdata('comments')
- new_comment = {
+ new_comment = {
"name": name,
"content": content,
"id": comments[postID]['comments'].length,
"pubdate": unix_timestamp,
- };
- comments[postID]['comments'].push(new_comment);
- fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
- }
+ };
+ comments[postID]['comments'].push(new_comment);
+ fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
+ }
- res.redirect(301,`${config.site_path}/post/${req.body.post_index}`)
+ res.redirect(301,`${config.site_path}/post/${req.body.post_index}`)
}); // /submit_comment
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)
- const content = req.body.content
- const tags = func.escape_input(req.body.tags).split(',').map(str => str.trim());
- const unix_timestamp = getUnixTime(new Date())
+ 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)
+ const content = req.body.content
+ const tags = func.escape_input(req.body.tags).split(',').map(str => str.trim());
+ const unix_timestamp = getUnixTime(new Date())
- if (func.get_userID(username) == -1) {
- res.render("partials/message", {
- message: locale.user_doesnt_exit,
- config,
- })
- }
+ if (func.get_userID(username) == -1) {
+ res.render("partials/message", {
+ message: locale.user_doesnt_exit,
+ config,
+ })
+ }
- else if (users[func.get_userID(username)]['hash'] == password) { // Password matches
- console.log(username, "is submitting a post titled:", title);
- id = posts.length
- posts.push({
- "id": id,
- "userID": func.get_userID(username),
- "title": title,
- "content": content,
- "pubdate": unix_timestamp,
- "editdate": unix_timestamp,
- "tags": tags,
- })
- 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, config.site_path);
- }
- else {
- res.render("partials/message", {
- message: locale.incorrect_password,
- config,
- })
- }
+ else if (users[func.get_userID(username)]['hash'] == password) { // Password matches
+ console.log(username, "is submitting a post titled:", title);
+ id = posts.length
+ posts.push({
+ "id": id,
+ "userID": func.get_userID(username),
+ "title": title,
+ "content": content,
+ "pubdate": unix_timestamp,
+ "editdate": unix_timestamp,
+ "tags": tags,
+ })
+ 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, config.site_path);
+ }
+ else {
+ res.render("partials/message", {
+ message: locale.incorrect_password,
+ config,
+ })
+ }
}); // /submit_post
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)
- const description = req.body.description
+ 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)
+ const description = req.body.description
- // Check that signups are allowed
- if (config.allow_signup == true) {
- // func.get_userID will return -1 if the user does not exist
- // so this checks that the user does not exist
- if (func.get_userID(username) == -1) {
- users.push({
- "id": users.length,
- "username": username,
- "prettyname": prettyname,
- "hash": password,
- "description": description,
- })
- fs.writeFileSync(`../data/users.json`, `${JSON.stringify(users)}`, 'utf-8');
- res.redirect(301, `${config.site_path}/user/${username}`)
- }
- // if the user does exist then
- else {
- res.render("partials/message", {
- message: locale.user_exists,
- config,
- })
- }
- }
- else if (config.allow_signup == false) {
- res.render("partials/message", {
- message: locale.signups_unavailable,
- config,
- })
- }
- // If allow_signup is undefined or not a boolean, error
- else {
- res.redirect(301,config.site_path)
- console.log("Error, invalid value for allow_signup (bool)")
- }
+ // Check that signups are allowed
+ if (config.allow_signup == true) {
+ // func.get_userID will return -1 if the user does not exist
+ // so this checks that the user does not exist
+ if (func.get_userID(username) == -1) {
+ users.push({
+ "id": users.length,
+ "username": username,
+ "prettyname": prettyname,
+ "hash": password,
+ "description": description,
+ })
+ fs.writeFileSync(`../data/users.json`, `${JSON.stringify(users)}`, 'utf-8');
+ res.redirect(301, `${config.site_path}/user/${username}`)
+ }
+ // if the user does exist then
+ else {
+ res.render("partials/message", {
+ message: locale.user_exists,
+ config,
+ })
+ }
+ }
+ else if (config.allow_signup == false) {
+ res.render("partials/message", {
+ message: locale.signups_unavailable,
+ config,
+ })
+ }
+ // If allow_signup is undefined or not a boolean, error
+ else {
+ res.redirect(301,config.site_path)
+ console.log("Error, invalid value for allow_signup (bool)")
+ }
}); // /submit_signup
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)
- const description = req.body.description
- const prettyname = func.escape_input(req.body.prettyname)
- const delete_bool = req.body.delete
+ // Get the form info
+ const password = crypto.createHash("sha512").update(req.body.password).digest("hex");
+ const userID = func.escape_input(req.body.userID)
+ const description = req.body.description
+ const prettyname = func.escape_input(req.body.prettyname)
+ const delete_bool = req.body.delete
- if (userID >= 0) { // The user exists
- if (password == users[userID]['hash']) { // password matches
- console.log(userID, " (userID) is modifying their account")
- users[userID]["prettyname"] = prettyname;
- users[userID]["description"] = description;
+ if (userID >= 0) { // The user exists
+ if (password == users[userID]['hash']) { // password matches
+ console.log(userID, " (userID) is modifying their account")
+ users[userID]["prettyname"] = prettyname;
+ users[userID]["description"] = description;
- if (delete_bool == true) {
- // Delete the user
- users[userID] = {"id": userID,"deleted": true}
- // Delete all their posts
- for (let postid = 0; postid < posts.length; postid++) { // loop over all posts
- if (posts[postid]['userID'] == userID) { // if userID matches
- posts[postid] = {"id": postid, "deleted": true} // delete the post
- comments[postid] = [] // the comments for this post should also be deleted
- }
- };
- }
- // Write these changes
- 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,`${config.site_path}/user/${users[userID]["username"]}`)
- }
- else { // password does not match
- res.render("partials/message", {
- message: locale.incorrect_password,
- config
- }
- )
- };
- }
- else {
- res.render("partials/message", {
- message: locale.user_doesnt_exist,
- config,
- })
- }
+ if (delete_bool == true) {
+ // Delete the user
+ users[userID] = {"id": userID,"deleted": true}
+ // Delete all their posts
+ for (let postid = 0; postid < posts.length; postid++) { // loop over all posts
+ if (posts[postid]['userID'] == userID) { // if userID matches
+ posts[postid] = {"id": postid, "deleted": true} // delete the post
+ comments[postid] = [] // the comments for this post should also be deleted
+ }
+ };
+ }
+ // Write these changes
+ 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,`${config.site_path}/user/${users[userID]["username"]}`)
+ }
+ else { // password does not match
+ res.render("partials/message", {
+ message: locale.incorrect_password,
+ config
+ }
+ )
+ };
+ }
+ else {
+ res.render("partials/message", {
+ message: locale.user_doesnt_exist,
+ config,
+ })
+ }
}); // /submit_delete_account
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
- const title = func.escape_input(req.body.title)
- const content = req.body.content
- const tags = func.escape_input(req.body.tags).split(",").map(str => str.trim());
- const delete_bool = req.body.delete
- const unix_timestamp = getUnixTime(new Date())
- console.log(users[userID]['prettyname'], "is editting the post titled:", title);
+ const password = crypto.createHash('sha512').update(req.body.password).digest('hex');
+ const postID = req.body.postID
+ const userID = req.body.userID
+ const title = func.escape_input(req.body.title)
+ const content = req.body.content
+ const tags = func.escape_input(req.body.tags).split(",").map(str => str.trim());
+ const delete_bool = req.body.delete
+ const unix_timestamp = getUnixTime(new Date())
+ console.log(users[userID]['prettyname'], "is editting the post titled:", title);
- if (users[userID]['hash'] == password) { // password matches
- let post = posts[postID]
- post['title'] = title
- post['content'] = content
- post['tags'] = tags
- post['editdate'] = unix_timestamp
- if (typeof delete_bool != "undefined") {
- console.log("Deleting post!")
- posts[postID] = {"id": post["id"], "deleted": true}
- comments[postID] = [];
- fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
- }
- fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
- res.redirect(302, config.site_path);
- }
- else {
- res.render("partials/message", {
- message: locale.incorrect_password,
- config,
- })
- }
+ if (users[userID]['hash'] == password) { // password matches
+ let post = posts[postID]
+ post['title'] = title
+ post['content'] = content
+ post['tags'] = tags
+ post['editdate'] = unix_timestamp
+ if (typeof delete_bool != "undefined") {
+ console.log("Deleting post!")
+ posts[postID] = {"id": post["id"], "deleted": true}
+ comments[postID] = [];
+ fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
+ }
+ fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
+ res.redirect(302, config.site_path);
+ }
+ else {
+ res.render("partials/message", {
+ message: locale.incorrect_password,
+ config,
+ })
+ }
}); // /submit_edit
router.get(`${config.site_path}/search`, (req, res) => {
@@ -216,7 +216,8 @@ router.get(`${config.site_path}/search`, (req, res) => {
console.log('searching for: ', search_term);
const search_results = data.searchdata(search_term, search_type); // data.searchdata returns an array of search results
- res.render('pages/search', {
+ res.render('pages/search',
+ {
config,
locale,
search_results,
diff --git a/src/routes/forms.js b/src/routes/forms.js
index de5cd3e..abc654c 100644
--- a/src/routes/forms.js
+++ b/src/routes/forms.js
@@ -6,53 +6,55 @@ const router = express.Router();
///////////////////// Form pages ////////////////////////////
router.get(`${config.site_path}/${config.new_post_url}`, (req,res) => {
- res.render("forms/new_post", {
- config,
- locale,
- });
+ res.render("forms/new_post", {
+ config,
+ locale,
+ });
}); // /post
router.get(`${config.site_path}/${config.signup_url}`, (req,res) => {
- // if the server does allow signup
- if (config.allow_signup == true) {
- // Send the page for signing up to the server
- res.render("forms/signup", {
- config,
- locale,
- });
- }
- // if the server does not allow signup
- else if (config.allow_signup == false) {
- res.render("partials/message", {
- message: locale.signups_unavailable,
- config,
- })
- }
- // If allow_signup is undefined or not a boolean, error
- else {
- res.redirect(301,"/")
- console.log("Error, invalid value for allow_signup (bool)")
- }
+ // if the server does allow signup
+ if (config.allow_signup == true) {
+ // Send the page for signing up to the server
+ res.render("forms/signup", {
+ config,
+ locale,
+ });
+ }
+ // if the server does not allow signup
+ else if (config.allow_signup == false) {
+ res.render("partials/message", {
+ message: locale.signups_unavailable,
+ config,
+ })
+ }
+ // If allow_signup is undefined or not a boolean, error
+ else {
+ res.redirect(301,"/")
+ console.log("Error, invalid value for allow_signup (bool)")
+ }
}); // /signup
router.get(`${config.site_path}/${config.edit_account_base_url}/:user_id`, (req,res) => {
- const userID = parseInt(req.params.user_id);
- res.render("forms/edit_account", {
- config,
- locale,
- user: data.getdata('users', 'id', userID),
- userID
- });
+ const userID = parseInt(req.params.user_id);
+ res.render("forms/edit_account",
+ {
+ config,
+ locale,
+ user: data.getdata('users', 'id', userID),
+ userID
+ });
}); // /delete_account
router.get(`${config.site_path}/${config.edit_post_base_url}/:post_id`, (req,res) => {
- const postID = req.params.post_id
- const post = data.getdata('posts','id', postID)
- const user = data.getdata('users', 'id', post.userID)
- res.render("forms/edit_post", {
- config,
- locale,
- post,
- postID,
- user,
- });
+ const postID = req.params.post_id
+ const post = data.getdata('posts','id', postID)
+ const user = data.getdata('users', 'id', post.userID)
+ res.render("forms/edit_post",
+ {
+ config,
+ locale,
+ post,
+ postID,
+ user,
+ });
}); // /edit/:post_id
module.exports = router;
diff --git a/src/routes/indexes.js b/src/routes/indexes.js
index 4fb6e2d..b726f2d 100644
--- a/src/routes/indexes.js
+++ b/src/routes/indexes.js
@@ -7,30 +7,30 @@ const router = express.Router();
///////////////////// Page index's ///////////////////////
router.get(`${config.site_path}/index/pages`, (req,res) => {
- res.render("indexes/all_pages", {
- config,
- posts: data.getdata('posts'),
- users: data.getdata('users'),
- comments: data.getdata('comments'),
- });
+ res.render("indexes/all_pages", {
+ config,
+ posts: data.getdata('posts'),
+ users: data.getdata('users'),
+ comments: data.getdata('comments'),
+ });
}); // /index/pages
router.get(`${config.site_path}/index/posts`, (req,res) => {
- res.render("indexes/posts", {
- config,
- posts: data.getdata('posts'),
- });
+ res.render("indexes/posts", {
+ config,
+ posts: data.getdata('posts'),
+ });
}); // /index/posts
router.get(`${config.site_path}/index/users`, (req,res) => {
- res.render("indexes/users", {
- config,
- users: data.getdata('users'),
- });
+ res.render("indexes/users", {
+ config,
+ users: data.getdata('users'),
+ });
}); // /index/users
router.get(`${config.site_path}/index/comments`, (req,res) => {
- res.render("indexes/comments", {
- config,
- comments: data.getdata('comments'),
- });
+ res.render("indexes/comments", {
+ config,
+ comments: data.getdata('comments'),
+ });
}); // /index/comments
diff --git a/src/routes/standard_pages.js b/src/routes/standard_pages.js
index ff0fcad..4d981be 100644
--- a/src/routes/standard_pages.js
+++ b/src/routes/standard_pages.js
@@ -10,142 +10,142 @@ const router = express.Router();
// Timeline
router.get(config.site_path, (req,res) => {
- // Increment the hitcount
- if (config.enable_hitcount) {
- data.increment_hitcount()
- }
+ // Increment the hitcount
+ if (config.enable_hitcount) {
+ data.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,
- })
+ 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,
+ })
}); // /
// Users
router.get(`${config.site_path}/user/:username`, (req, res) => {
- const userID = func.get_userID(req.params.username)
- let user = data.getdata('users', 'id', 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,
- })
- }
+ const userID = func.get_userID(req.params.username)
+ let user = data.getdata('users', 'id', 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
// Posts
router.get(`${config.site_path}/post/:post_index`, (req, res) => {
- const postID = parseInt(req.params.post_index)
- let post = data.getdata('posts','id', postID)
- if (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) {
+ const postID = parseInt(req.params.post_index)
+ let post = data.getdata('posts','id', postID)
+ if (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) {
if (config.enable_hitcount) {
data.increment_hitcount(postID)
}
- res.render("pages/post",
- {
- config,
- locale,
- post,
- postID,
- user: data.getdata('users','id', post.userID),
- comments: data.getdata('comments','id', postID),
- fromUnixTime,
- format,
- getUnixTime,
- func,
- })
- }
- else {
- console.log("Error loading page")
- res.redirect(301,"/")
- }
+ res.render("pages/post",
+ {
+ config,
+ locale,
+ post,
+ postID,
+ user: data.getdata('users','id', post.userID),
+ comments: data.getdata('comments','id', postID),
+ fromUnixTime,
+ format,
+ getUnixTime,
+ func,
+ })
+ }
+ else {
+ console.log("Error loading page")
+ res.redirect(301,"/")
+ }
}); // /post/:post_index
// Tags
router.get(`${config.site_path}/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,
- })
+ 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
// Comments
router.get(`${config.site_path}/comment/:postID-:commentID`, (req,res) => {
- const commentID = parseInt(req.params.commentID);
- const postID = parseInt(req.params.postID);
+ const commentID = parseInt(req.params.commentID);
+ const postID = parseInt(req.params.postID);
- let posts_comments = data.getdata('comments', 'id', postID)["comments"]
- let comment = 1
- // For loop to find the comment with matching ID
- posts_comments.forEach((current_comment, index) => {
- if (current_comment.id == commentID) {
- comment = posts_comments[index]
- }
- })
- // If comment doesn't exist, show error
- if (comment == 1 || posts_comments == 1) { // Comment of this ID was not found
- res.render("partials/message", {
- config,
- message: locale.comment_doesnt_exist,
- })
- }
- else {
- res.render("pages/comment",
- {
- config,
- locale,
- comment,
- postID,
- commentID,
- fromUnixTime,
- format,
- getUnixTime,
- func,
- })
- }
+ let posts_comments = data.getdata('comments', 'id', postID)["comments"]
+ let comment = 1
+ // For loop to find the comment with matching ID
+ posts_comments.forEach((current_comment, index) => {
+ if (current_comment.id == commentID) {
+ comment = posts_comments[index]
+ }
+ })
+ // If comment doesn't exist, show error
+ if (comment == 1 || posts_comments == 1) { // Comment of this ID was not found
+ 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;
diff --git a/src/routes/syndication.js b/src/routes/syndication.js
index 15ce3e5..94c2861 100644
--- a/src/routes/syndication.js
+++ b/src/routes/syndication.js
@@ -10,79 +10,79 @@ const router = express.Router();
////////////////////// SYNDICATION ////////////////////////
// global RSS protocol gets
router.get(`${config.site_path}/rss`, (req,res) => {
- if (config.rss == false) {
- res.render("partials/message", {
- message: locale.rss_disabled,
- config,
- })
- }
- else {
- res.setHeader('content-type', 'application/rss+xml');
- res.render("syndication/global_rss", {
- config,
- posts: data.getdata('posts'),
- func,
- })
- };
+ if (config.rss == false) {
+ res.render("partials/message", {
+ message: locale.rss_disabled,
+ config,
+ })
+ }
+ else {
+ res.setHeader('content-type', 'application/rss+xml');
+ res.render("syndication/global_rss", {
+ config,
+ posts: data.getdata('posts'),
+ func,
+ })
+ };
});
// user RSS protocol gets
router.get(`${config.site_path}/user/:username/rss`, (req,res) => {
- const username = req.params.username;
- const userID = func.get_userID(username);
- if (config.rss == false) {
- res.render("partials/message", {
- message: locale.rss_disabled,
- config: config,
- })
- }
- else {
- res.setHeader('content-type', 'application/rss+xml');
- res.render("syndication/user_rss", {
- config,
- posts: data.getdata('posts'),
- func,
- userID,
- })
- };
+ const username = req.params.username;
+ const userID = func.get_userID(username);
+ if (config.rss == false) {
+ res.render("partials/message", {
+ message: locale.rss_disabled,
+ config: config,
+ })
+ }
+ else {
+ res.setHeader('content-type', 'application/rss+xml');
+ res.render("syndication/user_rss", {
+ config,
+ posts: data.getdata('posts'),
+ func,
+ userID,
+ })
+ };
});
// global ATOM protocol gets
router.get(`${config.site_path}/atom`, (req,res) => {
- if (config.atom == false) {
- res.render("partials/message", {
- message: locale.atom_disabled,
- config: config,
- })
- }
- else {
- res.setHeader('content-type', 'application/rss+xml');
- res.render("syndication/global_atom", {
- config,
- posts: data.getdata('posts'),
- func,
- getUnixTime,
- })
- };
+ if (config.atom == false) {
+ res.render("partials/message", {
+ message: locale.atom_disabled,
+ config: config,
+ })
+ }
+ else {
+ res.setHeader('content-type', 'application/rss+xml');
+ res.render("syndication/global_atom", {
+ config,
+ posts: data.getdata('posts'),
+ func,
+ getUnixTime,
+ })
+ };
});
// user ATOM protocol gets
router.get(`${config.site_path}/user/:username/atom`, (req,res) => {
- const username = req.params.username;
- const userID = func.get_userID(username);
- if (config.atom == false) {
- res.render("partials/message", {
- message: locale.atom_disabled,
- config: config,
- })
- }
- else {
- res.setHeader('content-type', 'application/rss+xml');
- res.render("syndication/user_atom", {
- config,
- posts: data.getdata('posts'),
- func,
- userID,
- getUnixTime,
- })
- };
+ const username = req.params.username;
+ const userID = func.get_userID(username);
+ if (config.atom == false) {
+ res.render("partials/message", {
+ message: locale.atom_disabled,
+ config: config,
+ })
+ }
+ else {
+ res.setHeader('content-type', 'application/rss+xml');
+ res.render("syndication/user_atom", {
+ config,
+ posts: data.getdata('posts'),
+ func,
+ userID,
+ getUnixTime,
+ })
+ };
});
module.exports = router;
diff --git a/src/server.js b/src/server.js
index 62651c7..7bf6280 100644
--- a/src/server.js
+++ b/src/server.js
@@ -15,11 +15,11 @@ config = require('../config.json');
// Import the locale
try {
- locale = require(`../locales/${config.locale}.json`);
+ locale = require(`../locales/${config.locale}.json`);
}
catch (error) {
- console.log("This locale doesn't exist, if you want to create it then you can create a PR")
- console.log("Locale selected: ", config.locale)
+ console.log("This locale doesn't exist, if you want to create it then you can create a PR")
+ console.log("Locale selected: ", config.locale)
}
// Define stuff to do with express (nodejs webserver)
@@ -46,44 +46,43 @@ app.use('/', form_actions_routes);
function perform_checks()
{
- console.log("Performing startup checks...")
- exit_flag = false
- required_values = ['site_admin','seperator','site_name','site_url','locale','port','cache_data','allow_signup','site_description','request_data_limit','enable_hitcount','charset','root_path','edit_account_base_url','new_post_url','signup_url','default_commenter_username','rss','atom','date_format','time_zone','css']
- // Perform some standard checks:
+ console.log("Performing startup checks...")
+ exit_flag = false
+ required_values = ['site_admin','seperator','site_name','site_url','locale','port','cache_data','allow_signup','site_description','request_data_limit','enable_hitcount','charset','root_path','edit_account_base_url','new_post_url','signup_url','default_commenter_username','rss','atom','date_format','time_zone','css']
+ // Perform some standard checks:
- // data_storage
- switch (config.data_storage)
- {
- case 'mysql':
- case 'json':
- break
- default:
- console.log("[ ERROR ] invalid value in `data_storage`\nPlease modify config.json. Value should be 'mysql' or 'json'.")
- exit_flag = true
- }
- // auto_generated
- if (config.auto_generated)
- {
- console.log("[ ERROR ] `autogenerated` option set to true\nplease edit the config.json file to include your relevant information, then set to false or remove the autogenerated option.")
- exit_flag = true
- }
- // Check required values are present
- required_values.forEach((value) => { // Use a loop to check each required value is present
- if (typeof config[value] == 'undefined') {
- exit_flag = true
- console.log(`[ ERROR ] \`${value}\` is undefined\nPlease set it to something, read the documentation for help.`)
- }
- });
- if (exit_flag)
- {
- console.log("Exiting due to errors.")
- process.exit(1)
- }
+ // data_storage
+ switch (config.data_storage)
+ {
+ case 'mysql':
+ case 'json':
+ break
+ default:
+ console.log("[ ERROR ] invalid value in `data_storage`\nPlease modify config.json. Value should be 'mysql' or 'json'.")
+ exit_flag = true
+ }
+ // auto_generated
+ if (config.auto_generated)
+ {
+ console.log("[ ERROR ] `autogenerated` option set to true\nplease edit the config.json file to include your relevant information, then set to false or remove the autogenerated option.")
+ exit_flag = true
+ }
+ // Check required values are present
+ required_values.forEach((value) => { // Use a loop to check each required value is present
+ if (typeof config[value] == 'undefined') {
+ exit_flag = true
+ console.log(`[ ERROR ] \`${value}\` is undefined\nPlease set it to something, read the documentation for help.`)
+ }
+ });
+ if (exit_flag)
+ {
+ console.log("Exiting due to errors.")
+ process.exit(1)
+ }
}
perform_checks()
-
app.listen(config.port, () => {
console.log(`Server is running at http://localhost:${config.port} webroot: ${config.root_path}`);
- console.log("Running in: ", __dirname)
-});
+ console.log("Running in: ", __dirname)
+})