From 06905b4d30e742108e3c107fb426406f599a2051 Mon Sep 17 00:00:00 2001 From: Darrell Date: Thu, 25 Aug 2022 08:23:57 -0400 Subject: [PATCH] Add Update button (#533) (#612) --- src/HttpReleaseUpdate.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/HttpReleaseUpdate.cpp b/src/HttpReleaseUpdate.cpp index 519f891..5304d70 100644 --- a/src/HttpReleaseUpdate.cpp +++ b/src/HttpReleaseUpdate.cpp @@ -4,23 +4,26 @@ #include #include -bool isSameVersion(WiFiClientSecure& client, const String& url, const String& version) { +bool hasNewVersion(WiFiClientSecure& client, const String& url, const String& version) { HTTPClient http; if (!http.begin(client, url)) return false; + bool ret = false; int httpCode = http.sendRequest("HEAD"); - bool ret = httpCode > 300 && httpCode < 400 && http.getLocation().indexOf(version) <= 0; - - if (ret) Serial.printf("Updating from (sc=%d): %s\n", httpCode, http.getLocation().c_str()); - else Serial.printf("Not updating from (sc=%d): %s\n", httpCode, http.getLocation().c_str()); - + bool isRedirect = httpCode > 300 && httpCode < 400; + if (isRedirect) { + if (http.getLocation().indexOf(version) < 0){ + Serial.printf("Found new version: %s\n", http.getLocation().c_str()); + ret = true; + } + } else Serial.printf("Error on checking for update (sc=%d)\n", httpCode); http.end(); return ret; } HttpUpdateResult HttpReleaseUpdate::update(WiFiClientSecure& client, const String& url, const String& version) { - if (version.length() > 0 && isSameVersion(client, url, version)) + if (version.length() > 0 && !hasNewVersion(client, url, version)) return HTTP_UPDATE_NO_UPDATES; HTTPClient http;