Skip to content

Commit 346278c

Browse files
s-hadingerjosef109
authored andcommitted
File upload improvements: "/ufsu" api mode, no interrupts disanling, cleaner confirmation page (arendst#24521)
1 parent e144706 commit 346278c

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
2222
- Do not free BT memory when in use (#24480)
2323
- Berry avoid `tasmota.wifi()` returning bad values when wifi is turned off (#24505)
2424
- Don't send extraneous `0\r\n\r\n` with non-chunked HTTP/1.0 (#24518)
25+
- File upload improvements: "/ufsu" api mode, no interrupts disanling, cleaner confirmation page
2526

2627
### Removed
2728
- Berry `tasmota.urlbecload()` superseded by Extension Manager (#24493)

tasmota/include/tasmota.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,17 @@ enum EmulationOptions {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX};
386386

387387
enum TopicOptions { CMND, STAT, TELE, nu1, RESULT_OR_CMND, RESULT_OR_STAT, RESULT_OR_TELE };
388388

389+
// Upload type used by HandleUploadLoop() to route incoming data.
390+
// Value 0 is invalid/unset. Each upload endpoint must set the appropriate
391+
// type before HandleUploadLoop() processes the first data block.
392+
// UPL_TASMOTA - OTA firmware update (/u2)
393+
// UPL_SETTINGS - Settings backup restore (/u2)
394+
// UPL_EFM8BB1 - Sonoff RF bridge EFM8BB1 firmware
395+
// UPL_TASMOTACLIENT - Tasmota client (Arduino) hex file
396+
// UPL_EFR32 - Zigbee EZSP (EFR32) firmware
397+
// UPL_SHD - Shelly dimmer firmware
398+
// UPL_CCL - CC2530 Zigbee firmware via CCLoader
399+
// UPL_UFSFILE - Filesystem file upload (/ufsu)
389400
enum UploadTypes { UPL_TASMOTA = 1, UPL_SETTINGS, UPL_EFM8BB1, UPL_TASMOTACLIENT, UPL_EFR32, UPL_SHD, UPL_CCL, UPL_UFSFILE };
390401

391402
enum ExecuteCommandPowerOptions { POWER_OFF, POWER_ON, POWER_TOGGLE, POWER_BLINK, POWER_BLINK_STOP, POWER_OFF_FORCE,

tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,7 +3502,9 @@ void HandleUploadLoop(void) {
35023502
if (Web.upload_error) {
35033503
if (!upload_error_signalled) {
35043504
if (UPL_TASMOTA == Web.upload_file_type) { Update.end(); }
3505-
UploadServices(1);
3505+
if (UPL_UFSFILE != Web.upload_file_type) {
3506+
UploadServices(1);
3507+
}
35063508

35073509
// AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "Upload error %d"), Web.upload_error);
35083510

@@ -3522,7 +3524,10 @@ void HandleUploadLoop(void) {
35223524
WebGetArg("fsz", tmp, sizeof(tmp)); // filesize
35233525
upload_size = (!strlen(tmp)) ? 0 : atoi(tmp);
35243526

3525-
UploadServices(0);
3527+
// Filesystem uploads don't need to disable interrupts/services
3528+
if (UPL_UFSFILE != Web.upload_file_type) {
3529+
UploadServices(0);
3530+
}
35263531

35273532
if (0 == upload.filename.c_str()[0]) {
35283533
Web.upload_error = 1; // No file selected
@@ -3667,7 +3672,9 @@ void HandleUploadLoop(void) {
36673672

36683673
// ***** Step3: Finish upload file
36693674
else if (UPLOAD_FILE_END == upload.status) {
3670-
UploadServices(1);
3675+
if (UPL_UFSFILE != Web.upload_file_type) {
3676+
UploadServices(1);
3677+
}
36713678
if (UPL_SETTINGS == Web.upload_file_type) {
36723679
if (!SettingsConfigRestore()) {
36733680
Web.upload_error = 8; // File invalid
@@ -3733,7 +3740,9 @@ void HandleUploadLoop(void) {
37333740

37343741
// ***** Step4: Abort upload file
37353742
else {
3736-
UploadServices(1);
3743+
if (UPL_UFSFILE != Web.upload_file_type) {
3744+
UploadServices(1);
3745+
}
37373746
Web.upload_error = 7; // Upload aborted
37383747
if (UPL_TASMOTA == Web.upload_file_type) { Update.end(); }
37393748
}

tasmota/tasmota_xdrv_driver/xdrv_50_filesystem.ino

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,21 @@ const char HTTP_EDITOR_FORM_END[] PROGMEM =
13531353

13541354
#endif // #ifdef GUI_EDIT_FILE
13551355

1356+
// Wrapper around HandleUploadLoop() for /ufsu file uploads.
1357+
// HandleUploadLoop() is shared between OTA firmware updates (/u2) and filesystem
1358+
// uploads (/ufsu), and uses Web.upload_file_type to distinguish them.
1359+
// When uploading via the web UI, the browser first does a GET which calls
1360+
// UfsDirectory() and sets upload_file_type = UPL_UFSFILE. But direct POST
1361+
// requests (e.g. curl -F "file=@..." /ufsu) skip the GET, leaving
1362+
// upload_file_type unset and causing HandleUploadLoop() to treat the file
1363+
// as a firmware image, which fails.
1364+
// This wrapper ensures upload_file_type is always set before entering the
1365+
// shared upload handler.
1366+
void HandleUploadUFSLoop(void) {
1367+
Web.upload_file_type = UPL_UFSFILE;
1368+
HandleUploadLoop();
1369+
}
1370+
13561371
void HandleUploadUFSDone(void) {
13571372
if (!HttpCheckPriviledgedAccess()) { return; }
13581373

@@ -1382,7 +1397,7 @@ void HandleUploadUFSDone(void) {
13821397
}
13831398
WSContentSend_P(PSTR("</div><br>"));
13841399

1385-
XdrvCall(FUNC_WEB_ADD_MANAGEMENT_BUTTON);
1400+
WSContentSend_PD(UFS_WEB_DIR, "/", PSTR(D_MANAGE_FILE_SYSTEM));
13861401

13871402
WSContentStop();
13881403
}
@@ -1974,13 +1989,9 @@ bool Xdrv50(uint32_t function) {
19741989
}
19751990
break;
19761991
case FUNC_WEB_ADD_HANDLER:
1977-
// Webserver->on(F("/ufsd"), UfsDirectory);
1978-
// Webserver->on(F("/ufsu"), HTTP_GET, UfsDirectory);
1979-
// Webserver->on(F("/ufsu"), HTTP_POST,[](){Webserver->sendHeader(F("Location"),F("/ufsu"));Webserver->send(303);}, HandleUploadLoop);
19801992
Webserver->on("/ufsd", UfsDirectory);
19811993
Webserver->on("/ufsu", HTTP_GET, UfsDirectory);
1982-
//Webserver->on("/ufsu", HTTP_POST,[](){Webserver->sendHeader(F("Location"),F("/ufsu"));Webserver->send(303);}, HandleUploadLoop);
1983-
Webserver->on("/ufsu", HTTP_POST, HandleUploadUFSDone, HandleUploadLoop);
1994+
Webserver->on("/ufsu", HTTP_POST, HandleUploadUFSDone, HandleUploadUFSLoop);
19841995
#ifdef GUI_EDIT_FILE
19851996
Webserver->on("/ufse", HTTP_GET, UfsEditor);
19861997
Webserver->on("/ufse", HTTP_POST, UfsEditorUpload);

0 commit comments

Comments
 (0)