From 0520d24e29e033b6f65332ce61d41fc884173fc0 Mon Sep 17 00:00:00 2001 From: velvettear Date: Fri, 11 Feb 2022 01:13:51 +0100 Subject: [PATCH] fixed some stuff, caching may still be broken --- config.json | 2 +- libs/modep.js | 8 +++++--- libs/server.js | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/config.json b/config.json index f07e1d1..0d71d20 100644 --- a/config.json +++ b/config.json @@ -5,7 +5,7 @@ "timestamp": "DD.MM.YYYY HH:mm:ss:SS" }, "cache": { - "active": true, + "active": false, "lifetime": 15 }, "log": { diff --git a/libs/modep.js b/libs/modep.js index 12e17e4..aa074e2 100644 --- a/libs/modep.js +++ b/libs/modep.js @@ -22,7 +22,7 @@ function getBanks() { if (banks != undefined) { return resolve(banks); } - + // FAKE DATA // var fake = [{ "title": "The Button", "pedalboards": [{ "valid": true, "broken": false, "uri": "file:///var/modep/pedalboards/default.pedalboard/default.ttl", "bundle": "/var/modep/pedalboards/default.pedalboard", "title": "Default", "version": 0 }, { "valid": true, "broken": false, "uri": "file:///var/modep/pedalboards/FUZZ.pedalboard/FUZZ.ttl", "bundle": "/var/modep/pedalboards/FUZZ.pedalboard", "title": "FUZZ", "version": 1 }] }]; // for (var index = 0; index < fake.length; index++) { @@ -235,6 +235,7 @@ function parseCurrentPedalboard(currentPedalboard) { return new Promise(function (resolve, reject) { getDefaultPedalboard() .then(function (defaultPedalboard) { + test = defaultPedalboard; currentPedals = []; if (defaultPedalboard.id == currentPedalboard.id) { return resolve(currentPedals); @@ -366,11 +367,13 @@ function setPedalboard(pedalboard) { if (!pedalboard || !pedalboard.bundle) { return reject('error: no bundle set for pedalboard'); } + var tmpPedalboard; getCurrentPedalboard() .then(function (currentPedalboard) { if (pedalboard.id == currentPedalboard.id) { return Promise.reject('pedalboard \'' + pedalboard.id + '\' is already active'); } + tmpPedalboard = currentPedalboard; }) .then(function () { return reset() @@ -379,8 +382,7 @@ function setPedalboard(pedalboard) { return util.httpPOST(config.modep.host, config.modep.port, '/pedalboard/load_bundle/?bundlepath=' + pedalboard.bundle) }) .then(function () { - currentPedalboard = pedalboard - parseCurrentPedalboard(currentPedalboard) + parseCurrentPedalboard(tmpPedalboard); }) .then(resolve) .catch(reject); diff --git a/libs/server.js b/libs/server.js index a9df843..ada0118 100644 --- a/libs/server.js +++ b/libs/server.js @@ -56,7 +56,7 @@ function handleRequests() { if (code == undefined) { code = 500; } - endRequest(request, response, code, err); + endRequest(request, response, err, code); }); }); } @@ -70,9 +70,11 @@ function endRequest(request, response, msg, code) { code: code } if (msg != undefined) { - try { + if (msg instanceof Object) { object.data = JSON.stringify(msg); - } catch { + } else if (msg instanceof Error) { + object.data = msg.toString(); + } else { object.data = msg; } }