MCPcopy Create free account
hub / github.com/bmorcelli/Launcher / fileHandler

Function fileHandler

src/webInterface.cpp:647–677  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

645}
646
647esp_err_t fileHandler(httpd_req_t *req) {
648 if (!checkUserWebAuth(req)) return ESP_OK;
649 String fileName = queryValue(req, "name");
650 String fileAction = queryValue(req, "action");
651 if (fileName.isEmpty() || fileAction.isEmpty()) {
652 sendText(req, 400, "text/plain", "ERROR: name and action params required");
653 return ESP_OK;
654 }
655
656 if (!SDM.exists(fileName)) {
657 if (fileAction == "create") {
658 if (!SDM.mkdir(fileName)) sendText(req, "text/plain", "FAIL creating folder: " + fileName);
659 else sendText(req, "text/plain", "Created new folder: " + fileName);
660 } else {
661 sendText(req, 400, "text/plain", "ERROR: file does not exist");
662 }
663 return ESP_OK;
664 }
665
666 if (fileAction == "download") sendFileDownload(req, fileName);
667 else if (fileAction == "delete") {
668 if (deleteFromSd(fileName)) sendText(req, "text/plain", "Deleted : " + fileName);
669 else sendText(req, "text/plain", "FAIL delating: " + fileName);
670 } else if (fileAction == "create") {
671 if (!SDM.mkdir(fileName)) sendText(req, "text/plain", "FAIL creating existing folder: " + fileName);
672 else sendText(req, "text/plain", "Created new folder: " + fileName);
673 } else {
674 sendText(req, 400, "text/plain", "ERROR: invalid action param supplied");
675 }
676 return ESP_OK;
677}
678
679esp_err_t editfileHandler(httpd_req_t *req) {
680 if (!checkUserWebAuth(req)) return ESP_OK;

Callers

nothing calls this directly

Calls 5

checkUserWebAuthFunction · 0.85
queryValueFunction · 0.85
sendTextFunction · 0.85
sendFileDownloadFunction · 0.85
deleteFromSdFunction · 0.85

Tested by

no test coverage detected