fixed some stuff, caching may still be broken

This commit is contained in:
Daniel Sommer 2022-02-11 01:13:51 +01:00
parent adb597e83b
commit 0520d24e29
3 changed files with 11 additions and 7 deletions

View file

@ -5,7 +5,7 @@
"timestamp": "DD.MM.YYYY HH:mm:ss:SS" "timestamp": "DD.MM.YYYY HH:mm:ss:SS"
}, },
"cache": { "cache": {
"active": true, "active": false,
"lifetime": 15 "lifetime": 15
}, },
"log": { "log": {

View file

@ -22,7 +22,7 @@ function getBanks() {
if (banks != undefined) { if (banks != undefined) {
return resolve(banks); return resolve(banks);
} }
// FAKE DATA // 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 }] }]; // 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++) { // for (var index = 0; index < fake.length; index++) {
@ -235,6 +235,7 @@ function parseCurrentPedalboard(currentPedalboard) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
getDefaultPedalboard() getDefaultPedalboard()
.then(function (defaultPedalboard) { .then(function (defaultPedalboard) {
test = defaultPedalboard;
currentPedals = []; currentPedals = [];
if (defaultPedalboard.id == currentPedalboard.id) { if (defaultPedalboard.id == currentPedalboard.id) {
return resolve(currentPedals); return resolve(currentPedals);
@ -366,11 +367,13 @@ function setPedalboard(pedalboard) {
if (!pedalboard || !pedalboard.bundle) { if (!pedalboard || !pedalboard.bundle) {
return reject('error: no bundle set for pedalboard'); return reject('error: no bundle set for pedalboard');
} }
var tmpPedalboard;
getCurrentPedalboard() getCurrentPedalboard()
.then(function (currentPedalboard) { .then(function (currentPedalboard) {
if (pedalboard.id == currentPedalboard.id) { if (pedalboard.id == currentPedalboard.id) {
return Promise.reject('pedalboard \'' + pedalboard.id + '\' is already active'); return Promise.reject('pedalboard \'' + pedalboard.id + '\' is already active');
} }
tmpPedalboard = currentPedalboard;
}) })
.then(function () { .then(function () {
return reset() return reset()
@ -379,8 +382,7 @@ function setPedalboard(pedalboard) {
return util.httpPOST(config.modep.host, config.modep.port, '/pedalboard/load_bundle/?bundlepath=' + pedalboard.bundle) return util.httpPOST(config.modep.host, config.modep.port, '/pedalboard/load_bundle/?bundlepath=' + pedalboard.bundle)
}) })
.then(function () { .then(function () {
currentPedalboard = pedalboard parseCurrentPedalboard(tmpPedalboard);
parseCurrentPedalboard(currentPedalboard)
}) })
.then(resolve) .then(resolve)
.catch(reject); .catch(reject);

View file

@ -56,7 +56,7 @@ function handleRequests() {
if (code == undefined) { if (code == undefined) {
code = 500; code = 500;
} }
endRequest(request, response, code, err); endRequest(request, response, err, code);
}); });
}); });
} }
@ -70,9 +70,11 @@ function endRequest(request, response, msg, code) {
code: code code: code
} }
if (msg != undefined) { if (msg != undefined) {
try { if (msg instanceof Object) {
object.data = JSON.stringify(msg); object.data = JSON.stringify(msg);
} catch { } else if (msg instanceof Error) {
object.data = msg.toString();
} else {
object.data = msg; object.data = msg;
} }
} }