Everything uses data.getdata()
data.getdata() excepts two parameters, if desired, the second will be the index, however if you don't specify anything, the whole array will be returned Also, comments now have a composite key of postID-commentID, with each post's comments having their own set starting at 0, this makes it easier to index and find a specific comment, and making the getcomment() function unessesary
This commit is contained in:
14
src/data.js
14
src/data.js
@@ -4,22 +4,18 @@ const require = createRequire(import.meta.url);
|
||||
const config = require("../config.json")
|
||||
const fs = require("fs")
|
||||
|
||||
export function getdata(data, key='', value='') {
|
||||
export function getdata(data, index=-1) {
|
||||
|
||||
if (config["data_storage"] == "json") {
|
||||
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
|
||||
}
|
||||
})
|
||||
if (index != -1) {
|
||||
return result[index]
|
||||
}
|
||||
return result
|
||||
}
|
||||
else if (data == "hitcount") {
|
||||
let result = fs.readFileSync("../data/hitcount.txt")
|
||||
else if (data == "other_data") {
|
||||
let result = require('../data/data.json') // This file is actually called data.json
|
||||
return result
|
||||
}
|
||||
else {
|
||||
|
Reference in New Issue
Block a user