From 6968772a3123b5de558fa482b3e0e586f8aff3cf Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 29 Jun 2025 21:48:35 -0500 Subject: [PATCH] preen --- .../web_server_idf/web_server_idf.cpp | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/esphome/components/web_server_idf/web_server_idf.cpp b/esphome/components/web_server_idf/web_server_idf.cpp index d51b3485cc..ebd51b481e 100644 --- a/esphome/components/web_server_idf/web_server_idf.cpp +++ b/esphome/components/web_server_idf/web_server_idf.cpp @@ -572,11 +572,6 @@ esp_err_t AsyncWebServer::handle_multipart_upload_(httpd_req_t *r, const char *c // Constants for upload handling static constexpr size_t MULTIPART_CHUNK_SIZE = 1460; // Match Arduino AsyncWebServer buffer size static constexpr size_t YIELD_INTERVAL_BYTES = 16 * 1024; // Yield every 16KB to prevent watchdog - - // Upload indices for handleUpload callbacks - static constexpr size_t UPLOAD_INDEX_BEGIN = 0; - static constexpr size_t UPLOAD_INDEX_WRITE = 1; - static constexpr size_t UPLOAD_INDEX_END = 2; // Parse boundary from content type const char *boundary_start = nullptr; size_t boundary_len = 0; @@ -611,7 +606,7 @@ esp_err_t AsyncWebServer::handle_multipart_upload_(httpd_req_t *r, const char *c AsyncWebHandler *handler; AsyncWebServerRequest *req; std::string filename; - bool started = false; + size_t index = 0; // Byte position in the current upload } ctx{handler, &req}; // Configure callbacks @@ -624,19 +619,22 @@ esp_err_t AsyncWebServer::handle_multipart_upload_(httpd_req_t *r, const char *c ESP_LOGV(TAG, "Processing file: '%s'", ctx.filename.c_str()); } - if (!ctx.started) { - ctx.handler->handleUpload(ctx.req, ctx.filename, UPLOAD_INDEX_BEGIN, nullptr, 0, false); - ctx.started = true; + if (ctx.index == 0) { + // First call with index 0 to indicate start of upload + ctx.handler->handleUpload(ctx.req, ctx.filename, 0, nullptr, 0, false); } - ctx.handler->handleUpload(ctx.req, ctx.filename, UPLOAD_INDEX_WRITE, const_cast(data), len, false); + // Write data with current index + ctx.handler->handleUpload(ctx.req, ctx.filename, ctx.index, const_cast(data), len, false); + ctx.index += len; }); reader.set_part_complete_callback([&ctx]() { - if (ctx.started) { - ctx.handler->handleUpload(ctx.req, ctx.filename, UPLOAD_INDEX_END, nullptr, 0, true); + if (ctx.index > 0) { + // Final call with final=true to indicate end of upload + ctx.handler->handleUpload(ctx.req, ctx.filename, ctx.index, nullptr, 0, true); ctx.filename.clear(); - ctx.started = false; + ctx.index = 0; } });