mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-08 19:36:31 +00:00
Add API mode to partition switch u4
This commit is contained in:
parent
963909170f
commit
b687d9f17d
@ -2896,6 +2896,15 @@ void HandlePreflightRequest(void)
|
|||||||
// `false`: the current partition is not the target, but a restart to factory is triggered (polling required)
|
// `false`: the current partition is not the target, but a restart to factory is triggered (polling required)
|
||||||
// `true`: the current partition is the one required
|
// `true`: the current partition is the one required
|
||||||
// `none`: there is no factory partition
|
// `none`: there is no factory partition
|
||||||
|
|
||||||
|
// return a simple status page as text/plain code 200
|
||||||
|
static void WSReturnSimpleString(const char *msg) {
|
||||||
|
if (nullptr == msg) { msg = ""; }
|
||||||
|
Webserver->client().flush();
|
||||||
|
WSHeaderSend();
|
||||||
|
Webserver->send(200, "text/plain", msg);
|
||||||
|
}
|
||||||
|
|
||||||
void HandleSwitchFactory(void)
|
void HandleSwitchFactory(void)
|
||||||
{
|
{
|
||||||
if (!HttpCheckPriviledgedAccess()) { return; }
|
if (!HttpCheckPriviledgedAccess()) { return; }
|
||||||
@ -2905,9 +2914,12 @@ void HandleSwitchFactory(void)
|
|||||||
|
|
||||||
bool switch_factory = false; // trigger a restart to factory partition?
|
bool switch_factory = false; // trigger a restart to factory partition?
|
||||||
bool switch_ota = false; // switch back to OTA partition
|
bool switch_ota = false; // switch back to OTA partition
|
||||||
|
bool single_ota = false;
|
||||||
|
bool api_mode = Webserver->hasArg("api"); // api-mode, returns `true`, `false` or `none`
|
||||||
|
|
||||||
// switch to factory ?
|
// switch to factory ?
|
||||||
if (EspSingleOtaPartition()) {
|
if (EspSingleOtaPartition()) {
|
||||||
|
single_ota = true;
|
||||||
if (strcmp("fct", tmp1) == 0 && !EspRunningFactoryPartition()) {
|
if (strcmp("fct", tmp1) == 0 && !EspRunningFactoryPartition()) {
|
||||||
switch_factory = true;
|
switch_factory = true;
|
||||||
}
|
}
|
||||||
@ -2917,6 +2929,7 @@ void HandleSwitchFactory(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apply the change in flash and return result
|
||||||
if (switch_factory || switch_ota) {
|
if (switch_factory || switch_ota) {
|
||||||
SettingsSaveAll();
|
SettingsSaveAll();
|
||||||
if (switch_factory) {
|
if (switch_factory) {
|
||||||
@ -2925,11 +2938,22 @@ void HandleSwitchFactory(void)
|
|||||||
const esp_partition_t* partition = esp_ota_get_next_update_partition(nullptr);
|
const esp_partition_t* partition = esp_ota_get_next_update_partition(nullptr);
|
||||||
esp_ota_set_boot_partition(partition);
|
esp_ota_set_boot_partition(partition);
|
||||||
}
|
}
|
||||||
// display restart page
|
|
||||||
WebRestart(0);
|
if (api_mode) {
|
||||||
|
WSReturnSimpleString("false");
|
||||||
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_RESTART));
|
||||||
|
EspRestart();
|
||||||
|
} else {
|
||||||
|
WebRestart(0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Webserver->sendHeader("Location", "/", true);
|
if (api_mode) {
|
||||||
Webserver->send(302, "text/plain", "");
|
// return `none` or `true`
|
||||||
|
WSReturnSimpleString(EspSingleOtaPartition() ? "true" : "none");
|
||||||
|
} else {
|
||||||
|
Webserver->sendHeader("Location", "/", true);
|
||||||
|
Webserver->send(302, "text/plain", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user