const Ajv = require("ajv"); const fs = require("fs"); const logger = require("../services/logging"); const yaml = require("js-yaml"); const configurationBase = { plex: { name: null, url: null, token: null, filters: [], // { library, ip, deviceId, platform, product } scrobblers: [] }, scrobble: { minimum: { percent: null, duration: null }, }, spotify: { name: null, client_id: null, client_secret: null, redirect_uri: null, scrobblers: [] }, web: { host: null, port: null } }; const configurationFile = yaml.load(fs.readFileSync('config/config.yml'), yaml.JSON_SCHEMA); 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); })(); } const configuration = { ...configurationBase, ...configurationFile } module.exports = configuration;