@@ -123,11 +123,14 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
123123 // handler for the file upload, gets the sketch bytes, and writes
124124 // them through the Update object
125125
126- String inputName = request->getParam (" name" )->value ();
126+ _updateType = request->getParam (" name" )->value () == " filesystem" ?
127+ UpdateType::FILE_SYSTEM :
128+ UpdateType::FIRMWARE;
127129
128130 if (!index)
129131 {
130132 _updaterError.clear ();
133+
131134#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
132135 ESPASYNCHTTPUPDATESERVER_SerialOutput.setDebugOutput (true );
133136#endif
@@ -137,11 +140,25 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
137140 Log (" Unauthenticated Update\n " );
138141 return ;
139142 }
143+
144+ if (onUpdateBegin)
145+ {
146+ _updateResult = UpdateResult::UPDATE_OK;
147+ onUpdateBegin (_updateType, _updateResult);
148+ if (_updateResult != UpdateResult::UPDATE_OK)
149+ {
150+ Log (" Update aborted by server: %d\n " , _updateResult);
151+ if (onUpdateEnd)
152+ onUpdateEnd (_updateType, _updateResult);
153+ return ;
154+ }
155+ }
156+
140157 Log (" Update: %s\n " , filename.c_str ());
141158#ifdef ESP8266
142159 Update.runAsync (true );
143160#endif
144- if (inputName == " filesystem " )
161+ if (_updateType == UpdateType::FILE_SYSTEM )
145162 {
146163 Log (" updating filesystem" );
147164#ifdef ESP8266
@@ -183,6 +200,9 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
183200 {
184201 if (Update.end (true ))
185202 { // true to set the size to the current progress
203+ _updateResult = UpdateResult::UPDATE_OK;
204+ if (onUpdateEnd)
205+ onUpdateEnd (_updateType, _updateResult);
186206 Log (" Update Success: \n Rebooting...\n " );
187207 }
188208 else
@@ -204,4 +224,8 @@ void ESPAsyncHTTPUpdateServer::_setUpdaterError()
204224 StreamString str;
205225 Update.printError (str);
206226 _updaterError = str.c_str ();
227+
228+ _updateResult = UpdateResult::UPDATE_ERROR;
229+ if (onUpdateEnd)
230+ onUpdateEnd (_updateType, _updateResult);
207231}
0 commit comments