remove some unnecessary method calls

This commit is contained in:
Daniel Sommer 2021-04-07 12:03:07 +02:00
parent 1a52bc31e7
commit 4dca1d43b0

View file

@ -85,24 +85,20 @@ function handleRequests() {
// POST methods
app.post('*', function (request, response) {
logger.logRequest(request);
if (!blinkstick.isAnimationInProgress() || blinkstick.isInfiniteAnimationInProgress()) {
response.end();
blinkstick.parseColor(parseRequest(request.body))
.then(blinkstick.illuminate)
blinkstick.illuminate(parseRequest(request.body))
.then(logger.info)
.catch(logger.error);
return;
}
response.sendStatus(503);
});
}
// parse the request and return an object with sane defaults
function parseRequest(data) {
const blinkstickConfig = {
let blinkstickConfig = {
"id": Math.random(),
"mode": data["mode"] || config.api.post.mode.default,
"color": data["color"] || config.api.post.color.default,
"color": blinkstick.parseColor(data["color"]),
"options": {
"duration": data["duration"] || config.api.post.duration.default,
"pulse": {