forked from jishi/node-sonos-http-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.js
56 lines (49 loc) · 1.44 KB
/
settings.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
const fs = require('fs');
const path = require('path');
const logger = require('sonos-discovery/lib/helpers/logger');
const tryLoadJson = require('./lib/helpers/try-load-json');
function merge(target, source) {
Object.keys(source).forEach(key => {
if (
Object.getPrototypeOf(source[key]) === Object.prototype &&
target[key] !== undefined
) {
merge(target[key], source[key]);
} else {
target[key] = source[key];
}
});
}
var settings = {
port: 5005,
ip: '0.0.0.0',
securePort: 5006,
cacheDir: path.resolve(__dirname, 'cache'),
webroot: path.resolve(__dirname, 'static'),
presetDir: path.resolve(__dirname, 'presets'),
announceVolume: 40,
webhook: 'https://us-central1-ss-master-app.cloudfunctions.net/sonosEvent',
webhookCover:
'https://us-central1-ss-master-app.cloudfunctions.net/sonosCover',
};
// load user settings
const settingsFileFullPath = path.resolve(__dirname, 'settings.json');
const userSettings = tryLoadJson(settingsFileFullPath);
merge(settings, userSettings);
logger.debug(settings);
if (!fs.existsSync(settings.webroot + '/tts/')) {
fs.mkdirSync(settings.webroot + '/tts/');
}
if (!fs.existsSync(settings.cacheDir)) {
try {
fs.mkdirSync(settings.cacheDir);
} catch (err) {
logger.warn(
`Could not create cache directory ${
settings.cacheDir
}, please create it manually for all features to work.`
);
}
}
module.exports = settings;