| 25 | } |
| 26 | |
| 27 | int onUpload(HttpServerConnection& connection, HttpRequest& request, HttpResponse& response) |
| 28 | { |
| 29 | ReadWriteStream* file = request.files["firmware"]; |
| 30 | auto otaStream = static_cast<OtaUpgradeStream*>(file); |
| 31 | if(otaStream == nullptr) { |
| 32 | debug_e("Something went wrong with the file upload"); |
| 33 | return 1; |
| 34 | } |
| 35 | |
| 36 | if(response.isSuccess() && !otaStream->hasError()) { |
| 37 | // defer the reboot by 1000 milliseconds to give time to the web server to return the response |
| 38 | System.restart(1000); |
| 39 | |
| 40 | response.sendFile("restart.html"); |
| 41 | response.headers[HTTP_HEADER_CONNECTION] = "close"; |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | response.code = HTTP_STATUS_BAD_REQUEST; |
| 47 | response.setContentType(MIME_HTML); |
| 48 | String html = "<H2 color='#444'>" + toString(otaStream->errorCode) + "</H2>"; |
| 49 | response.headers[HTTP_HEADER_CONTENT_LENGTH] = html.length(); |
| 50 | response.sendString(html); |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | void fileUploadMapper(HttpFiles& files) |
| 56 | { |
nothing calls this directly
no test coverage detected