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:
15
src/data.js
15
src/data.js
@@ -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
|
||||
|
Reference in New Issue
Block a user