fix(githubsync): replace SDCardManager with Storage HalStorage to resolve FsFile type conflict

This commit is contained in:
Justin Oros
2026-04-22 19:13:56 -07:00
parent 1918848b9a
commit 33946761d2
+13 -15
View File
@@ -1,13 +1,12 @@
#include "GitHubSyncPlugin.h" #include "GitHubSyncPlugin.h"
#include <HTTPClient.h> #include <HTTPClient.h>
#include <HalStorage.h>
#include <Logging.h> #include <Logging.h>
#include <WiFi.h> #include <WiFi.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "SDCardManager.h"
#include <string> #include <string>
#include <vector>
#include "CrossPointSettings.h" #include "CrossPointSettings.h"
@@ -53,9 +52,8 @@ std::string shaFilePath(const std::string& filename) {
} }
std::string loadLocalSha(const std::string& filename) { std::string loadLocalSha(const std::string& filename) {
auto& sd = SDCardManager::getInstance();
FsFile f; FsFile f;
if (!sd.openFileForRead("GHS", shaFilePath(filename), f)) return ""; if (!Storage.openFileForRead("GHS", shaFilePath(filename).c_str(), f)) return "";
char buf[41] = {}; char buf[41] = {};
f.read(buf, sizeof(buf) - 1); f.read(buf, sizeof(buf) - 1);
f.close(); f.close();
@@ -66,11 +64,10 @@ std::string loadLocalSha(const std::string& filename) {
} }
void saveLocalSha(const std::string& filename, const std::string& sha) { void saveLocalSha(const std::string& filename, const std::string& sha) {
auto& sd = SDCardManager::getInstance(); Storage.mkdir(GH_SHA_DIR);
sd.mkdir(GH_SHA_DIR);
FsFile f; FsFile f;
if (!sd.openFileForWrite("GHS", shaFilePath(filename), f)) return; if (!Storage.openFileForWrite("GHS", shaFilePath(filename).c_str(), f)) return;
f.print(sha.c_str()); f.write(reinterpret_cast<const uint8_t*>(sha.c_str()), sha.size());
f.close(); f.close();
} }
@@ -90,9 +87,8 @@ bool downloadFile(const std::string& downloadUrl, const std::string& pat,
return false; return false;
} }
auto& sd = SDCardManager::getInstance();
FsFile f; FsFile f;
if (!sd.openFileForWrite("GHS", destPath, f)) { if (!Storage.openFileForWrite("GHS", destPath.c_str(), f)) {
LOG_ERR("GHS", "Cannot open %s for write", destPath.c_str()); LOG_ERR("GHS", "Cannot open %s for write", destPath.c_str());
http.end(); http.end();
return false; return false;
@@ -107,7 +103,8 @@ bool downloadFile(const std::string& downloadUrl, const std::string& pat,
while (http.connected() && (remaining > 0 || total == -1)) { while (http.connected() && (remaining > 0 || total == -1)) {
size_t avail = stream->available(); size_t avail = stream->available();
if (avail) { if (avail) {
size_t read = stream->readBytes(buf, min(avail, sizeof(buf))); size_t toRead = avail < sizeof(buf) ? avail : sizeof(buf);
size_t read = stream->readBytes(buf, toRead);
f.write(buf, read); f.write(buf, read);
if (remaining > 0) remaining -= (int)read; if (remaining > 0) remaining -= (int)read;
lastData = millis(); lastData = millis();
@@ -141,8 +138,10 @@ bool syncContents(const RepoInfo& info, const std::string& pat) {
int code = http.GET(); int code = http.GET();
LOG_INF("GHS", "Contents API HTTP %d", code); LOG_INF("GHS", "Contents API HTTP %d", code);
if (code != 200) {
if (code != 200) { http.end(); return false; } http.end();
return false;
}
String body = http.getString(); String body = http.getString();
http.end(); http.end();
@@ -154,7 +153,6 @@ bool syncContents(const RepoInfo& info, const std::string& pat) {
} }
JsonArray files = doc.as<JsonArray>(); JsonArray files = doc.as<JsonArray>();
auto& sd = SDCardManager::getInstance();
for (JsonObject file : files) { for (JsonObject file : files) {
const char* type = file["type"] | ""; const char* type = file["type"] | "";
@@ -174,7 +172,7 @@ bool syncContents(const RepoInfo& info, const std::string& pat) {
std::string destPath = isSleep ? "/sleep.bmp" : "/" + n; std::string destPath = isSleep ? "/sleep.bmp" : "/" + n;
std::string localSha = loadLocalSha(n); std::string localSha = loadLocalSha(n);
if (localSha == sha && sd.exists(destPath.c_str())) { if (localSha == std::string(sha) && Storage.exists(destPath.c_str())) {
LOG_DBG("GHS", "Up to date: %s", name); LOG_DBG("GHS", "Up to date: %s", name);
continue; continue;
} }