MCPcopy Create free account
hub / github.com/HASwitchPlate/openHASP / handleFileCreate

Function handleFileCreate

src/sys/svc/hasp_http_async.cpp:1048–1086  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1046}
1047
1048void handleFileCreate(AsyncWebServerRequest* request)
1049{
1050 if(!httpIsAuthenticated(request, F("filecreate"))) return;
1051
1052 if(request->args() == 0) {
1053 return request->send(500, PSTR("text/plain"), PSTR("BAD ARGS"));
1054 }
1055
1056 if(request->hasArg(F("path"))) {
1057 String path = request->arg(F("path"));
1058 LOG_TRACE(TAG_HTTP, F("handleFileCreate: %s"), path.c_str());
1059 if(path == "/") {
1060 return request->send(500, PSTR("text/plain"), PSTR("BAD PATH"));
1061 }
1062 if(HASP_FS.exists(path)) {
1063 return request->send(500, PSTR("text/plain"), PSTR("FILE EXISTS"));
1064 }
1065 File file = HASP_FS.open(path, "w");
1066 if(file) {
1067 file.close();
1068 } else {
1069 return request->send(500, PSTR("text/plain"), PSTR("CREATE FAILED"));
1070 }
1071 }
1072 if(request->hasArg(F("init"))) {
1073 dispatch_idle(NULL, "0");
1074 hasp_init();
1075 }
1076 if(request->hasArg(F("load"))) {
1077 dispatch_idle(NULL, "0");
1078 hasp_load_json();
1079 }
1080 if(request->hasArg(F("page"))) {
1081 uint8_t pageid = atoi(request->arg(F("page")).c_str());
1082 dispatch_idle(NULL, "0");
1083 dispatch_set_page(pageid, LV_SCR_LOAD_ANIM_NONE);
1084 }
1085 request->send(200, PSTR("text/plain"), "");
1086}
1087
1088void handleFileList(AsyncWebServerRequest* request)
1089{

Callers

nothing calls this directly

Calls 6

dispatch_idleFunction · 0.85
hasp_initFunction · 0.85
hasp_load_jsonFunction · 0.85
dispatch_set_pageFunction · 0.85
existsMethod · 0.80
httpIsAuthenticatedFunction · 0.70

Tested by

no test coverage detected