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

@@ -4,17 +4,20 @@ const require = createRequire(import.meta.url);
const config = require("../config.json")
const fs = require("fs")
export function getdata(data) {
export function getdata(data, key='', value='') {
if (config["data_storage"] == "json") {
if (data == "posts" || data == "users") {
if (data == "posts" || data == 'users' || data == 'comments') {
let result = require(`../data/${data}.json`)
if (key != '') {
result.forEach((object, index) => {
if (object[key] == value) {
return object
}
})
}
return result
}
else if (data == "comments") {
let result = require("../data/comments.json")
return result.comments
}
else if (data == "hitcount") {
let result = fs.readFileSync("../data/hitcount.txt")
return result