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