summaryrefslogtreecommitdiff
path: root/server/js/config.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/js/config.js')
-rw-r--r--server/js/config.js32
1 files changed, 19 insertions, 13 deletions
diff --git a/server/js/config.js b/server/js/config.js
index 077f928..b1e6836 100644
--- a/server/js/config.js
+++ b/server/js/config.js
@@ -1,28 +1,34 @@
"use strict";
+// Imports
const fs = require('fs');
+const path = require('path');
+const { ensureFolder, envPaths } = require('./paths');
-const defaultConfig = {
- 'settings': {
- 'nsfw_content': false
- }
-};
-var config = {};
+// Handling Variables
+const configFolder = ensureFolder(path.join(envPaths.CONFIG, 'sneedbay'));
+const defaultConfigPath = path.join(configFolder, 'config.json');
+var loadedConfig = {};
-function createConfig(configPath, data)
+function createConfig()
{
- fs.writeFileSync(configPath, JSON.stringify(data), 'utf-8');
+ const defaultConfig = {
+ 'settings': {
+ 'nsfw_content': false
+ }
+ };
+
+ fs.writeFileSync(configPath, JSON.stringify(defaultConfig), 'utf-8');
}
function loadConfig(configPath)
{
- if ( !fs.existsSync(configPath) )
+ if (!fs.existsSync(configPath))
{
createConfig(configPath, defaultConfig);
}
-
- return JSON.parse(fs.readFileSync(configPath));
-}
+ this.loadedConfig = JSON.parse(fs.readFileSync(configPath));
+}
-module.exports = {loadConfig, config}; \ No newline at end of file
+module.exports = { loadConfig, defaultConfigPath, loadedConfig }; \ No newline at end of file