apollo/config/configuration.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

const Ajv = require("ajv");
const fs = require("fs");
const logger = require("../services/logging");
const yaml = require("js-yaml");
const configurationBase = {
plex: {
url: null,
token: null,
filters: [] // { library, ip, deviceId, platform, product }
},
scrobble: {
minimum: {
percent: null,
duration: null
},
},
spotify: {
client_id: null,
client_secret: null,
redirect_uri: null
},
web: {
host: null,
port: null
}
};
const configurationFile = yaml.load(fs.readFileSync('config/config.yml'), yaml.JSON_SCHEMA);
const configuration = { ...configurationBase, ...configurationFile }
const ajv = new Ajv({ allErrors: true });
const schema = require("./config.schema");
const { exit } = require("process");
const validation = ajv.compile(schema);
const valid = validation(configurationFile);
if (!valid) {
logger.error("Configuration is invalid. " + validation.errors.map(e => e.message).join(". ") + ".");
(async () => { await new Promise(resolve => setTimeout(resolve, 1000)); exit(1); })();
}
module.exports = configuration;