-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataProvider.js
36 lines (28 loc) · 1.19 KB
/
dataProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// get data from assets index.json file and convert it to a javascript object
const fs = require('fs')
function readJSONFile(filename) {
return JSON.parse(fs.readFileSync(filename, 'utf8'))
}
const path = require('path')
function readData(filename) {
try {
return readJSONFile(path.join(__dirname, 'assets', filename))
}
catch (err) { console.log(" -- X -- Error reading json file: " + filename+"\n Is json data valid ?") }
}
function readconfig() {
try {
config_obj = readJSONFile(path.join(__dirname, 'config.json'))
// if a config file is found in assets folder, merge its contents with the default config
if (fs.existsSync(path.join(__dirname, 'assets', 'config.json'))) {
config_obj = Object.assign(config_obj, readJSONFile(path.join(__dirname, 'assets', 'config.json')))
}
return config_obj;
} catch(err) { console.log(" -- X -- Failed to read config.json file..."); exit(); }
}
function defaultData() {
return {poweredByLink: "<a href='https://github.com/wiz64/priva-startpage' target='_blank'>Powered By Priva Startpage</a>"}
}
module.exports.data = readData;
module.exports.config = readconfig();
module.exports.defaultData = defaultData;