diff --git a/lib/hal/HalStorage.cpp b/lib/hal/HalStorage.cpp index a565b355..a30469c2 100644 --- a/lib/hal/HalStorage.cpp +++ b/lib/hal/HalStorage.cpp @@ -2,11 +2,13 @@ #include "HalStorage.h" #include // need to be included before SdFat.h for compatibility with FS.h's File class +#include #include #include #include #include +#include #include #define SDCard SDCardManager::getInstance() @@ -20,7 +22,26 @@ HalStorage::HalStorage() { // begin() and ready() are only called from setup, no need to acquire mutex for them -bool HalStorage::begin() { return SDCard.begin(); } +bool HalStorage::begin() { + if (!SDCard.begin()) return false; + FsDateTime::setCallback([](uint16_t* date, uint16_t* time) { + if (!HalClock::isSynced()) { + *date = FS_DATE(1980, 1, 1); + *time = FS_TIME(0, 0, 0); + return; + } + const time_t t = HalClock::now(); + const struct tm* tm = localtime(&t); + if (!tm) { + *date = FS_DATE(1980, 1, 1); + *time = FS_TIME(0, 0, 0); + return; + } + *date = FS_DATE(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); + *time = FS_TIME(tm->tm_hour, tm->tm_min, tm->tm_sec); + }); + return true; +} bool HalStorage::ready() const { return SDCard.ready(); } diff --git a/src/network/CrossPointWebServer.cpp b/src/network/CrossPointWebServer.cpp index 77049ff3..1d922ce8 100644 --- a/src/network/CrossPointWebServer.cpp +++ b/src/network/CrossPointWebServer.cpp @@ -998,13 +998,6 @@ void CrossPointWebServer::handleMove() const { server->send(403, "text/plain", "Cannot move protected item"); return; } - if (destPath != "/") { - const String destName = destPath.substring(destPath.lastIndexOf('/') + 1); - if (isProtectedItemName(destName)) { - server->send(403, "text/plain", "Cannot move into protected folder"); - return; - } - } if (!Storage.exists(itemPath.c_str())) { server->send(404, "text/plain", "Item not found"); @@ -1210,9 +1203,9 @@ void CrossPointWebServer::handleSettingsPage() const { void CrossPointWebServer::handleGetSettings() const { const auto& settings = getSettingsList(); - server->setContentLength(CONTENT_LENGTH_UNKNOWN); - server->send(200, "application/json", ""); - server->sendContent("["); + String result; + result.reserve(4096); + result += "["; char output[512]; constexpr size_t outputSize = sizeof(output); @@ -1226,6 +1219,8 @@ void CrossPointWebServer::handleGetSettings() const { doc["key"] = s.key; doc["name"] = I18N.get(s.nameId); doc["category"] = I18N.get(s.category); + doc["subcategory"] = s.subcategory != StrId::STR_NONE_OPT ? I18N.get(s.subcategory) : ""; + doc["submenu"] = s.submenu != StrId::STR_NONE_OPT ? I18N.get(s.submenu) : ""; switch (s.type) { case SettingType::TOGGLE: { @@ -1272,21 +1267,23 @@ void CrossPointWebServer::handleGetSettings() const { } const size_t written = serializeJson(doc, output, outputSize); + const char* jsonEntry = output; + String dynBuffer; if (written >= outputSize) { - LOG_DBG("WEB", "Skipping oversized setting JSON for: %s", s.key); - continue; + serializeJson(doc, dynBuffer); + jsonEntry = dynBuffer.c_str(); } if (seenFirst) { - server->sendContent(","); + result += ","; } else { seenFirst = true; } - server->sendContent(output); + result += jsonEntry; } - server->sendContent("]"); - server->sendContent(""); + result += "]"; + server->send(200, "application/json", result); LOG_DBG("WEB", "Served settings API"); } diff --git a/src/network/html/FilesPage.html b/src/network/html/FilesPage.html index 7b95966e..256a86d0 100644 --- a/src/network/html/FilesPage.html +++ b/src/network/html/FilesPage.html @@ -7,6 +7,9 @@ CrossPoint Reader - Files