mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
fix customSupport for ArduinoJson 7.2.1
This commit is contained in:
@@ -39,7 +39,7 @@ const Help = () => {
|
|||||||
const [customSupportHTML, setCustomSupportHTML] = useState<string | null>(null);
|
const [customSupportHTML, setCustomSupportHTML] = useState<string | null>(null);
|
||||||
const [notFound, setNotFound] = useState<boolean>(false);
|
const [notFound, setNotFound] = useState<boolean>(false);
|
||||||
|
|
||||||
useRequest(() => callAction({ action: 'customSupport' })).onSuccess((event) => {
|
useRequest(() => callAction({ action: 'getCustomSupport' })).onSuccess((event) => {
|
||||||
if (event && event.data && Object.keys(event.data).length !== 0) {
|
if (event && event.data && Object.keys(event.data).length !== 0) {
|
||||||
const data = event.data.Support;
|
const data = event.data.Support;
|
||||||
if (data.img_url) {
|
if (data.img_url) {
|
||||||
|
|||||||
@@ -1014,10 +1014,10 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
|||||||
// request.url("/api");
|
// request.url("/api");
|
||||||
// EMSESP::webAPIService.webAPIService(&request, doc.as<JsonVariant>());
|
// EMSESP::webAPIService.webAPIService(&request, doc.as<JsonVariant>());
|
||||||
|
|
||||||
// char data2[] = "{\"action\":\"customSupport\", \"param\":\"hello\"}";
|
char data2[] = "{\"action\":\"getCustomSupport\", \"param\":\"hello\"}";
|
||||||
// deserializeJson(doc, data2);
|
deserializeJson(doc, data2);
|
||||||
// request.url("/rest/action");
|
request.url("/rest/action");
|
||||||
// EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||||
|
|
||||||
// char data3[] = "{\"action\":\"export\", \"param\":\"schedule\"}";
|
// char data3[] = "{\"action\":\"export\", \"param\":\"schedule\"}";
|
||||||
// deserializeJson(doc, data3);
|
// deserializeJson(doc, data3);
|
||||||
@@ -1031,11 +1031,11 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
|||||||
|
|
||||||
// test version checks
|
// test version checks
|
||||||
// test with "current_version_s = "3.7.1-dev.8" in WebStatusService::checkUpgrade()
|
// test with "current_version_s = "3.7.1-dev.8" in WebStatusService::checkUpgrade()
|
||||||
request.url("/rest/action");
|
// request.url("/rest/action");
|
||||||
deserializeJson(doc, "{\"action\":\"checkUpgrade\", \"param\":\"3.7.1-dev.9,3.7.0\"}"); // is upgradable
|
// deserializeJson(doc, "{\"action\":\"checkUpgrade\", \"param\":\"3.7.1-dev.9,3.7.0\"}"); // is upgradable
|
||||||
EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
// EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||||
deserializeJson(doc, "{\"action\":\"checkUpgrade\", \"param\":\"3.7.1-dev.7,3.7.0\"}"); // is not upgradable
|
// deserializeJson(doc, "{\"action\":\"checkUpgrade\", \"param\":\"3.7.1-dev.7,3.7.0\"}"); // is not upgradable
|
||||||
EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
// EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||||
|
|
||||||
// test with "current_version_s = "3.6.5" in WebStatusService::checkUpgrade()
|
// test with "current_version_s = "3.6.5" in WebStatusService::checkUpgrade()
|
||||||
// request.url("/rest/action");
|
// request.url("/rest/action");
|
||||||
@@ -1044,7 +1044,6 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
|||||||
// deserializeJson(doc, "{\"action\":\"checkUpgrade\", \"param\":\"3.7.1-dev.7,3.7.0\"}"); // is upgradable
|
// deserializeJson(doc, "{\"action\":\"checkUpgrade\", \"param\":\"3.7.1-dev.7,3.7.0\"}"); // is upgradable
|
||||||
// EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
// EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||||
|
|
||||||
|
|
||||||
// char data6[] = "{\"device\":\"system\", \"cmd\":\"read\",\"value\":\"8 2 27 1\"}";
|
// char data6[] = "{\"device\":\"system\", \"cmd\":\"read\",\"value\":\"8 2 27 1\"}";
|
||||||
// deserializeJson(doc, data6);
|
// deserializeJson(doc, data6);
|
||||||
// json = doc.as<JsonVariant>();
|
// json = doc.as<JsonVariant>();
|
||||||
|
|||||||
@@ -179,8 +179,8 @@ void WebStatusService::action(AsyncWebServerRequest * request, JsonVariant json)
|
|||||||
if (has_param) {
|
if (has_param) {
|
||||||
ok = exportData(root, param);
|
ok = exportData(root, param);
|
||||||
}
|
}
|
||||||
} else if (action == "customSupport") {
|
} else if (action == "getCustomSupport") {
|
||||||
ok = customSupport(root);
|
ok = getCustomSupport(root);
|
||||||
} else if (action == "uploadURL" && is_admin) {
|
} else if (action == "uploadURL" && is_admin) {
|
||||||
ok = uploadURL(param.c_str());
|
ok = uploadURL(param.c_str());
|
||||||
}
|
}
|
||||||
@@ -301,19 +301,27 @@ bool WebStatusService::exportData(JsonObject root, std::string & type) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// action = customSupport
|
// action = getCustomSupport
|
||||||
// reads any upload customSupport.json file and sends to to Help page to be shown as Guest
|
// reads any upload customSupport.json file and sends to to Help page to be shown as Guest
|
||||||
bool WebStatusService::customSupport(JsonObject root) {
|
bool WebStatusService::getCustomSupport(JsonObject root) {
|
||||||
#ifndef EMSESP_STANDALONE
|
JsonDocument doc;
|
||||||
|
|
||||||
|
#if defined(EMSESP_STANDALONE)
|
||||||
|
// dummy test data for "test api3"
|
||||||
|
deserializeJson(doc, "{\"type\":\"customSupport\",\"Support\":{\"html\":[\"html code\",\"here\"], \"img_url\": \"https://docs.emsesp.org/_media/images/designer.png\"}");
|
||||||
|
#else
|
||||||
// check if we have custom support file uploaded
|
// check if we have custom support file uploaded
|
||||||
File file = LittleFS.open(EMSESP_CUSTOMSUPPORT_FILE, "r");
|
File file = LittleFS.open(EMSESP_CUSTOMSUPPORT_FILE, "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
// there is no custom file, return empty object
|
// there is no custom file, return empty object
|
||||||
|
#if defined(EMSESP_DEBUG)
|
||||||
|
emsesp::EMSESP::logger().debug("No custom support file found");
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the contents of the file into the root output json object
|
// read the contents of the file into a json doc. We can't do this direct to object since 7.2.1
|
||||||
DeserializationError error = deserializeJson(root, file);
|
DeserializationError error = deserializeJson(doc, file);
|
||||||
if (error) {
|
if (error) {
|
||||||
emsesp::EMSESP::logger().err("Failed to read custom support file");
|
emsesp::EMSESP::logger().err("Failed to read custom support file");
|
||||||
return false;
|
return false;
|
||||||
@@ -321,6 +329,13 @@ bool WebStatusService::customSupport(JsonObject root) {
|
|||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(EMSESP_DEBUG)
|
||||||
|
emsesp::EMSESP::logger().debug("Showing custom support page");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
root.set(doc.as<JsonObject>()); // add to web response root object
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class WebStatusService {
|
|||||||
// actions
|
// actions
|
||||||
bool checkUpgrade(JsonObject root, std::string & latest_version);
|
bool checkUpgrade(JsonObject root, std::string & latest_version);
|
||||||
bool exportData(JsonObject root, std::string & type);
|
bool exportData(JsonObject root, std::string & type);
|
||||||
bool customSupport(JsonObject root);
|
bool getCustomSupport(JsonObject root);
|
||||||
bool uploadURL(const char * url);
|
bool uploadURL(const char * url);
|
||||||
|
|
||||||
void allvalues(JsonObject output);
|
void allvalues(JsonObject output);
|
||||||
|
|||||||
18
test/test_data/custom_support.json
Normal file
18
test/test_data/custom_support.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"type": "customSupport",
|
||||||
|
"Support": {
|
||||||
|
"html": [
|
||||||
|
"This product is installed and managed by:",
|
||||||
|
"",
|
||||||
|
"<b>Bosch Installer Example</b>",
|
||||||
|
"",
|
||||||
|
"Nefit Road 12",
|
||||||
|
"1234 AB Amsterdam",
|
||||||
|
"Phone: +31 123 456 789",
|
||||||
|
"email: support@boschinstaller.nl",
|
||||||
|
"",
|
||||||
|
"For help and questions please <a target='_blank' href='https://emsesp.org'>contact</a> your installer."
|
||||||
|
],
|
||||||
|
"img_url": "https://docs.emsesp.org/_media/images/designer.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user