const logger = require('./logger.js'); const util = require('./util.js'); const constants = require('./constants.js'); const modep = require('./modep.js'); const osc = require('./osc.js'); const info = require('./info.js'); const systemd = require('./systemd.js'); const endpoints = new Map(); function setEndpoint(url, get, post) { if (get === undefined && post === undefined) { return; } var endpoint = {}; if (get !== undefined) { endpoint.GET = get; } if (post !== undefined) { endpoint.POST = post; } endpoints.set(url, endpoint); logger.debug('set up endpoint \'' + url + '\' > GET: ' + (endpoint.GET !== undefined) + ', POST ' + (endpoint.POST !== undefined)); } function getEndpoints() { return endpoints; } async function setupEndpoints() { const timestamp = new Date(); logger.debug('setting up endpoints...'); setEndpoint(constants.API_INFO, { method: info.getHostInfo }); setEndpoint(constants.API_TEMPERATURE, { method: info.getTemperature }); setEndpoint(constants.API_BANKS, { method: modep.getBanks }) setEndpoint(constants.API_BANKS_BY_ID, { method: modep.getBankById }); setEndpoint(constants.API_PEDALBOARDS, { method: modep.getPedalboards }); setEndpoint( constants.API_PEDALBOARDS_BY_ID, { method: modep.getPedalboardById }, { method: modep.setPedalboardById } ); setEndpoint( constants.API_PEDALBOARDS_DEFAULT, { method: modep.getDefaultPedalboard } ); setEndpoint( constants.API_PEDALBOARDS_CURRENT, { method: modep.getCurrentPedalboard } ); setEndpoint( constants.API_PEDALS, { method: modep.getCurrentPedals } ); setEndpoint( constants.API_PEDAL_BY_ID, { method: modep.getCurrentPedalById }, { method: modep.setControlByRequest } ); setEndpoint( constants.API_BYPASS, undefined, { method: modep.toggleBypass } ); setEndpoint( constants.API_BYPASS_BY_ID, undefined, { method: modep.toggleBypass } ); setEndpoint( constants.API_MIDI, undefined, { method: osc.sendByRequest } ) if (global.config.systemd !== undefined) { for (let index = 0; index < global.config.systemd.length; index++) { setEndpoint( constants.API_SYSTEMD + '/' + global.config.systemd[index], { method: systemd.getServiceState }, { method: systemd.setServiceState } ) } } logger.debug('setting up ' + endpoints.size + ' endpoints took ' + util.timeDiff(timestamp) + 'ms'); } module.exports = { setupEndpoints, getEndpoints }