mirror of
https://github.com/wled/WLED.git
synced 2025-07-13 22:06:31 +00:00
handleHttpApi: Move web response to web context
No need to even consider this for non-web requests. Move the request special case to that context as well.
This commit is contained in:
parent
e65f6c7bc7
commit
cab2f91bc6
@ -235,7 +235,7 @@ void handleRemote(uint8_t *data, size_t len);
|
|||||||
//set.cpp
|
//set.cpp
|
||||||
bool isAsterisksOnly(const char* str, byte maxLen);
|
bool isAsterisksOnly(const char* str, byte maxLen);
|
||||||
void handleSettingsSet(AsyncWebServerRequest *request, byte subPage);
|
void handleSettingsSet(AsyncWebServerRequest *request, byte subPage);
|
||||||
bool handleHttpApi(AsyncWebServerRequest *request, const String& req, bool apply=true);
|
bool handleHttpApi(const String& req, bool apply=true);
|
||||||
|
|
||||||
//udp.cpp
|
//udp.cpp
|
||||||
void notify(byte callMode, bool followUp=false);
|
void notify(byte callMode, bool followUp=false);
|
||||||
|
@ -606,7 +606,7 @@ static void decodeIRJson(uint32_t code)
|
|||||||
cmdStr += tmp;
|
cmdStr += tmp;
|
||||||
}
|
}
|
||||||
fdo.clear(); // clear JSON buffer (it is no longer needed)
|
fdo.clear(); // clear JSON buffer (it is no longer needed)
|
||||||
handleHttpApi(nullptr, cmdStr, false); // no stateUpdated() call here
|
handleHttpApi(cmdStr, false); // no stateUpdated() call here
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// command is JSON object (TODO: currently will not handle irApplyToAllSelected correctly)
|
// command is JSON object (TODO: currently will not handle irApplyToAllSelected correctly)
|
||||||
|
@ -449,7 +449,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
|
|||||||
// HTTP API commands (must be handled before "ps")
|
// HTTP API commands (must be handled before "ps")
|
||||||
const char* httpwin = root["win"];
|
const char* httpwin = root["win"];
|
||||||
if (httpwin) {
|
if (httpwin) {
|
||||||
handleHttpApi(nullptr, httpwin, false); // may set stateChanged
|
handleHttpApi(httpwin, false); // may set stateChanged
|
||||||
}
|
}
|
||||||
|
|
||||||
// Applying preset from JSON API has 2 cases: a) "pd" AKA "preset direct" and b) "ps" AKA "preset select"
|
// Applying preset from JSON API has 2 cases: a) "pd" AKA "preset direct" and b) "ps" AKA "preset select"
|
||||||
|
@ -107,7 +107,7 @@ static void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProp
|
|||||||
deserializeJson(*pDoc, payloadStr);
|
deserializeJson(*pDoc, payloadStr);
|
||||||
deserializeState(pDoc->as<JsonObject>());
|
deserializeState(pDoc->as<JsonObject>());
|
||||||
} else { //HTTP API
|
} else { //HTTP API
|
||||||
handleHttpApi(nullptr, payloadStr);
|
handleHttpApi(payloadStr);
|
||||||
}
|
}
|
||||||
releaseJSONBufferLock();
|
releaseJSONBufferLock();
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ void handlePresets()
|
|||||||
//HTTP API commands
|
//HTTP API commands
|
||||||
const char* httpwin = fdo["win"];
|
const char* httpwin = fdo["win"];
|
||||||
if (httpwin) {
|
if (httpwin) {
|
||||||
handleHttpApi(nullptr, httpwin, false); // may call applyPreset() via PL=
|
handleHttpApi(httpwin, false); // may call applyPreset() via PL=
|
||||||
setValuesFromFirstSelectedSeg(); // fills legacy values
|
setValuesFromFirstSelectedSeg(); // fills legacy values
|
||||||
changePreset = true;
|
changePreset = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -160,7 +160,7 @@ static bool remoteJson(int button)
|
|||||||
cmdStr += tmp;
|
cmdStr += tmp;
|
||||||
}
|
}
|
||||||
fdo.clear(); // clear JSON buffer (it is no longer needed)
|
fdo.clear(); // clear JSON buffer (it is no longer needed)
|
||||||
handleHttpApi(nullptr, cmdStr, false); // no stateUpdated() call here
|
handleHttpApi(cmdStr, false); // no stateUpdated() call here
|
||||||
stateUpdated(CALL_MODE_BUTTON);
|
stateUpdated(CALL_MODE_BUTTON);
|
||||||
parsed = true;
|
parsed = true;
|
||||||
}
|
}
|
||||||
|
@ -803,7 +803,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
|
|
||||||
|
|
||||||
//HTTP API request parser
|
//HTTP API request parser
|
||||||
bool handleHttpApi(AsyncWebServerRequest *request, const String& req, bool apply)
|
bool handleHttpApi(const String& req, bool apply)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
DEBUG_PRINTF_P(PSTR("API req: %s\n"), req.c_str());
|
DEBUG_PRINTF_P(PSTR("API req: %s\n"), req.c_str());
|
||||||
@ -1030,10 +1030,7 @@ bool handleHttpApi(AsyncWebServerRequest *request, const String& req, bool apply
|
|||||||
bool fxModeChanged = false, speedChanged = false, intensityChanged = false, paletteChanged = false;
|
bool fxModeChanged = false, speedChanged = false, intensityChanged = false, paletteChanged = false;
|
||||||
bool custom1Changed = false, custom2Changed = false, custom3Changed = false, check1Changed = false, check2Changed = false, check3Changed = false;
|
bool custom1Changed = false, custom2Changed = false, custom3Changed = false, check1Changed = false, check2Changed = false, check3Changed = false;
|
||||||
// set effect parameters
|
// set effect parameters
|
||||||
if (updateVal(req.c_str(), "FX=", &effectIn, 0, strip.getModeCount()-1)) {
|
fxModeChanged = updateVal(req.c_str(), "FX=", &effectIn, 0, strip.getModeCount()-1);
|
||||||
if (request != nullptr) unloadPlaylist(); // unload playlist if changing FX using web request
|
|
||||||
fxModeChanged = true;
|
|
||||||
}
|
|
||||||
speedChanged = updateVal(req.c_str(), "SX=", &speedIn);
|
speedChanged = updateVal(req.c_str(), "SX=", &speedIn);
|
||||||
intensityChanged = updateVal(req.c_str(), "IX=", &intensityIn);
|
intensityChanged = updateVal(req.c_str(), "IX=", &intensityIn);
|
||||||
paletteChanged = updateVal(req.c_str(), "FP=", &paletteIn, 0, strip.getPaletteCount()-1);
|
paletteChanged = updateVal(req.c_str(), "FP=", &paletteIn, 0, strip.getPaletteCount()-1);
|
||||||
@ -1187,12 +1184,5 @@ bool handleHttpApi(AsyncWebServerRequest *request, const String& req, bool apply
|
|||||||
pos = req.indexOf(F("&NN")); //do not send UDP notifications this time
|
pos = req.indexOf(F("&NN")); //do not send UDP notifications this time
|
||||||
stateUpdated((pos >= 0) ? CALL_MODE_NO_NOTIFY : CALL_MODE_DIRECT_CHANGE);
|
stateUpdated((pos >= 0) ? CALL_MODE_NO_NOTIFY : CALL_MODE_DIRECT_CHANGE);
|
||||||
|
|
||||||
// internal call, does not send XML response
|
|
||||||
if (request != nullptr) {
|
|
||||||
auto response = request->beginResponseStream("text/xml");
|
|
||||||
XML_response(*response);
|
|
||||||
request->send(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -681,7 +681,7 @@ void handleNotifications()
|
|||||||
|
|
||||||
if (requestJSONBufferLock(18)) {
|
if (requestJSONBufferLock(18)) {
|
||||||
if (udpIn[0] >= 'A' && udpIn[0] <= 'Z') { //HTTP API
|
if (udpIn[0] >= 'A' && udpIn[0] <= 'Z') { //HTTP API
|
||||||
handleHttpApi(nullptr, (char*)udpIn);
|
handleHttpApi((char*)udpIn);
|
||||||
} else if (udpIn[0] == '{') { //JSON API
|
} else if (udpIn[0] == '{') { //JSON API
|
||||||
DeserializationError error = deserializeJson(*pDoc, udpIn);
|
DeserializationError error = deserializeJson(*pDoc, udpIn);
|
||||||
JsonObject root = pDoc->as<JsonObject>();
|
JsonObject root = pDoc->as<JsonObject>();
|
||||||
|
@ -483,7 +483,15 @@ void initServer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (request->url().indexOf("win") == 0) {
|
if (request->url().indexOf("win") == 0) {
|
||||||
if(handleHttpApi(request, request->url().substring(3))) return;
|
if (handleHttpApi(request->url().substring(3))) {
|
||||||
|
if (request->url().indexOf(F("&FX=")) > 0) {
|
||||||
|
unloadPlaylist(); // Setting an FX via HTTP disables any active playlist.
|
||||||
|
}
|
||||||
|
auto response = request->beginResponseStream(CONTENT_TYPE_XML);
|
||||||
|
XML_response(*response);
|
||||||
|
request->send(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifndef WLED_DISABLE_ALEXA
|
#ifndef WLED_DISABLE_ALEXA
|
||||||
if(espalexa.handleAlexaApiCall(request)) return;
|
if(espalexa.handleAlexaApiCall(request)) return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user