mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 17:39:07 +08:00
Better handle and report failing upload
This commit is contained in:
parent
e3bf7e4bf8
commit
6641e4aa4f
@ -158,7 +158,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
//version and sources location
|
//version and sources location
|
||||||
#define FW_VERSION "0.9.70"
|
#define FW_VERSION "0.9.71"
|
||||||
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
||||||
|
|
||||||
|
|
||||||
|
@ -2326,12 +2326,12 @@ void SPIFFSFileupload()
|
|||||||
Serial.println("M117 Error ESP upload");
|
Serial.println("M117 Error ESP upload");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
static String filename;
|
||||||
//get current file ID
|
//get current file ID
|
||||||
HTTPUpload& upload = (web_interface->WebServer).upload();
|
HTTPUpload& upload = (web_interface->WebServer).upload();
|
||||||
//Upload start
|
//Upload start
|
||||||
//**************
|
//**************
|
||||||
if(upload.status == UPLOAD_FILE_START) {
|
if(upload.status == UPLOAD_FILE_START) {
|
||||||
String filename;
|
|
||||||
//according User or Admin the root is different as user is isolate to /user when admin has full access
|
//according User or Admin the root is different as user is isolate to /user when admin has full access
|
||||||
if(auth_level == LEVEL_ADMIN) {
|
if(auth_level == LEVEL_ADMIN) {
|
||||||
filename = upload.filename;
|
filename = upload.filename;
|
||||||
@ -2359,7 +2359,7 @@ void SPIFFSFileupload()
|
|||||||
//no error so write post date
|
//no error so write post date
|
||||||
web_interface->fsUploadFile.write(upload.buf, upload.currentSize);
|
web_interface->fsUploadFile.write(upload.buf, upload.currentSize);
|
||||||
} else {
|
} else {
|
||||||
//we have a proble set flag UPLOAD_STATUS_CANCELLED
|
//we have a problem set flag UPLOAD_STATUS_CANCELLED
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
Serial.println("M117 Error ESP write");
|
Serial.println("M117 Error ESP write");
|
||||||
}
|
}
|
||||||
@ -2373,14 +2373,16 @@ void SPIFFSFileupload()
|
|||||||
web_interface->fsUploadFile.close();
|
web_interface->fsUploadFile.close();
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
||||||
} else {
|
} else {
|
||||||
//we have a proble set flag UPLOAD_STATUS_CANCELLED
|
//we have a problem set flag UPLOAD_STATUS_CANCELLED
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
|
SPIFFS.remove(filename);
|
||||||
Serial.println("M117 Error ESP close");
|
Serial.println("M117 Error ESP close");
|
||||||
}
|
}
|
||||||
//Upload cancelled
|
//Upload cancelled
|
||||||
//**************
|
//**************
|
||||||
} else {
|
} else {
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
|
SPIFFS.remove(filename);
|
||||||
Serial.println("M117 Error ESP upload");
|
Serial.println("M117 Error ESP upload");
|
||||||
}
|
}
|
||||||
delay(0);
|
delay(0);
|
||||||
@ -2396,6 +2398,7 @@ void SDFileupload()
|
|||||||
static int buffer_size;
|
static int buffer_size;
|
||||||
static bool com_error = false;
|
static bool com_error = false;
|
||||||
static bool is_comment = false;
|
static bool is_comment = false;
|
||||||
|
static String filename;
|
||||||
String response;
|
String response;
|
||||||
//Guest cannot upload - only admin and user
|
//Guest cannot upload - only admin and user
|
||||||
if(web_interface->is_authenticated() == LEVEL_GUEST) {
|
if(web_interface->is_authenticated() == LEVEL_GUEST) {
|
||||||
@ -2434,6 +2437,7 @@ static size_t filesize;
|
|||||||
String filename = "M28 " + upload.filename;
|
String filename = "M28 " + upload.filename;
|
||||||
Serial.println(filename);
|
Serial.println(filename);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
|
filename = upload.filename;
|
||||||
//now need to purge all serial data
|
//now need to purge all serial data
|
||||||
//let's sleep 1s
|
//let's sleep 1s
|
||||||
delay(1000);
|
delay(1000);
|
||||||
@ -2653,6 +2657,8 @@ static size_t filesize;
|
|||||||
if (com_error) {
|
if (com_error) {
|
||||||
LOG("with error\r\n");
|
LOG("with error\r\n");
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
|
filename = "M30 " + filename;
|
||||||
|
Serial.println(filename);
|
||||||
Serial.println("M117 SD upload failed");
|
Serial.println("M117 SD upload failed");
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
} else {
|
} else {
|
||||||
@ -2677,6 +2683,8 @@ static size_t filesize;
|
|||||||
//resend M29 command to close file on SD as first command may be lost
|
//resend M29 command to close file on SD as first command may be lost
|
||||||
Serial.print("\r\nM29\r\n");
|
Serial.print("\r\nM29\r\n");
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
|
filename = "M30 " + filename;
|
||||||
|
Serial.println(filename);
|
||||||
Serial.println("M117 SD upload failed");
|
Serial.println("M117 SD upload failed");
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
}
|
}
|
||||||
@ -2766,7 +2774,7 @@ void handleUpdate()
|
|||||||
//if success restart
|
//if success restart
|
||||||
if (web_interface->_upload_status==UPLOAD_STATUS_SUCCESSFUL) {
|
if (web_interface->_upload_status==UPLOAD_STATUS_SUCCESSFUL) {
|
||||||
web_interface->restartmodule=true;
|
web_interface->restartmodule=true;
|
||||||
}
|
} else web_interface->_upload_status=UPLOAD_STATUS_NONE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2774,10 +2782,12 @@ void handleFileList()
|
|||||||
{
|
{
|
||||||
level_authenticate_type auth_level = web_interface->is_authenticated();
|
level_authenticate_type auth_level = web_interface->is_authenticated();
|
||||||
if (auth_level == LEVEL_GUEST) {
|
if (auth_level == LEVEL_GUEST) {
|
||||||
|
web_interface->_upload_status=UPLOAD_STATUS_NONE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String path ;
|
String path ;
|
||||||
String status = "Ok";
|
String status = "Ok";
|
||||||
|
if ((web_interface->_upload_status == UPLOAD_STATUS_FAILED) || (web_interface->_upload_status == UPLOAD_STATUS_CANCELLED)) status = "Upload failed";
|
||||||
//be sure root is correct according authentication
|
//be sure root is correct according authentication
|
||||||
if (auth_level == LEVEL_ADMIN) {
|
if (auth_level == LEVEL_ADMIN) {
|
||||||
path = "/";
|
path = "/";
|
||||||
@ -2938,17 +2948,20 @@ void handleFileList()
|
|||||||
path = "";
|
path = "";
|
||||||
web_interface->WebServer.sendHeader("Cache-Control", "no-cache");
|
web_interface->WebServer.sendHeader("Cache-Control", "no-cache");
|
||||||
web_interface->WebServer.send(200, "application/json", jsonfile);
|
web_interface->WebServer.send(200, "application/json", jsonfile);
|
||||||
|
web_interface->_upload_status=UPLOAD_STATUS_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleSDFileList()
|
void handleSDFileList()
|
||||||
{
|
{
|
||||||
char tmp[255];
|
char tmp[255];
|
||||||
if (web_interface->is_authenticated() == LEVEL_GUEST) {
|
if (web_interface->is_authenticated() == LEVEL_GUEST) {
|
||||||
|
web_interface->_upload_status=UPLOAD_STATUS_NONE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG("List SD FILES\r\n")
|
LOG("List SD FILES\r\n")
|
||||||
String path="/";
|
String path="/";
|
||||||
String sstatus="Ok";
|
String sstatus="Ok";
|
||||||
|
if ((web_interface->_upload_status == UPLOAD_STATUS_FAILED) || (web_interface->_upload_status == UPLOAD_STATUS_CANCELLED)) sstatus = "Upload failed";
|
||||||
uint32_t totalspace = 0;
|
uint32_t totalspace = 0;
|
||||||
uint32_t usedspace = 0;
|
uint32_t usedspace = 0;
|
||||||
//get current path
|
//get current path
|
||||||
@ -3091,6 +3104,7 @@ void handleSDFileList()
|
|||||||
web_interface->WebServer.sendHeader("Cache-Control", "no-cache");
|
web_interface->WebServer.sendHeader("Cache-Control", "no-cache");
|
||||||
web_interface->WebServer.send(200, "application/json", jsonfile);
|
web_interface->WebServer.send(200, "application/json", jsonfile);
|
||||||
web_interface->blockserial = false;
|
web_interface->blockserial = false;
|
||||||
|
web_interface->_upload_status=UPLOAD_STATUS_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//do a redirect to avoid to many query
|
//do a redirect to avoid to many query
|
||||||
|
Loading…
x
Reference in New Issue
Block a user