From b08bc64bd4d9606b25ca060534dfab792dd0359d Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Thu, 28 Oct 2021 14:18:59 +0200 Subject: [PATCH] feat: import settings --- server/src/controllers/ontimeController.js | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/server/src/controllers/ontimeController.js b/server/src/controllers/ontimeController.js index a3ba51654..8b0657d94 100644 --- a/server/src/controllers/ontimeController.js +++ b/server/src/controllers/ontimeController.js @@ -32,6 +32,7 @@ async function deleteFile(file) { async function parsev1(jsonData) { let numEntries = 0; if ('events' in jsonData) { + console.log('Found events definition, importing...'); let events = []; let ids = []; for (const e of jsonData.events) { @@ -69,6 +70,7 @@ async function parsev1(jsonData) { } if ('event' in jsonData) { + console.log('Found event data, importing...'); const e = jsonData.event; // filter known properties const event = { @@ -77,6 +79,7 @@ async function parsev1(jsonData) { url: e.url, publicInfo: e.publicInfo, backstageInfo: e.backstageInfo, + endMessage: e.endMessage, }; // write to db @@ -84,17 +87,30 @@ async function parsev1(jsonData) { db.write(); } - // Not handling settings yet - // let settings = {}; - // if ('settings' in jsonData) { - // } + // Settings handled partially + if ('settings' in jsonData) { + console.log('Found settings definition, importing...'); + const s = jsonData.settings; + let settings = {}; + + if (s.oscInPort) settings.oscInPort = s.oscInPort; + if (s.oscOutPort) settings.oscOutPort = s.oscOutPort; + if (s.oscOutIP) settings.oscOutIP = s.oscOutIP; + + // write to db + db.data.settings = { + ...dbModel.settings, + ...settings, + }; + db.write(); + } } // Create controller for GET request to '/ontime/db' // Returns - export const dbDownload = async (req, res) => { const fileTitle = getEventTitle() || 'ontime events'; - const dbFile = path.resolve(__dirname, '../../', 'data/db.json'); + const dbFile = path.resolve(__dirname, '../', 'data/db.json'); res.download(dbFile, `${fileTitle}.json`, (err) => { if (err) {