summaryrefslogtreecommitdiff
path: root/server/js/config.js
blob: c21a246eb9d9d3c71e43b764f68f763dd0a164a1 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use strict";

// Imports
const fs = require('fs');
const path = require('path');
const { ensureFolder, envPaths } = require('./paths');

// Handling Variables
const configFolder = ensureFolder(path.join(envPaths.CONFIG, 'sneedbay'));
const defaultConfigPath = path.join(configFolder, 'config.json');
var loadedConfig = {};

function createConfig()
{
	const defaultConfig = {
		'settings': {
			'nsfw_content': false
		}
	};

	try
	{
		fs.writeFileSync(configPath, JSON.stringify(defaultConfig), 'utf-8');
	} 

	catch (err)
	{
		console.log(err);
	}
}

function loadConfig(configPath)
{
	try
	{
		if (!fs.existsSync(configPath))
		{
			createConfig(configPath, defaultConfig);
		}

		this.loadedConfig = JSON.parse(fs.readFileSync(configPath));
	}

	catch (err)
	{
		console.log(err);
	}
}

module.exports = { loadConfig, defaultConfigPath, loadedConfig };