20 #include "../../../include/esp3d_config.h"
21 #if defined (HTTP_FEATURE) && defined(FILESYSTEM_FEATURE)
22 #include "../http_server.h"
23 #if defined (ARDUINO_ARCH_ESP32)
24 #include <WebServer.h>
25 #endif //ARDUINO_ARCH_ESP32
26 #if defined (ARDUINO_ARCH_ESP8266)
27 #include <ESP8266WebServer.h>
28 #endif //ARDUINO_ARCH_ESP8266
29 #include "../../filesystem/esp_filesystem.h"
30 #include "../../authentication/authentication_service.h"
33 void HTTP_Server::handleFSFileList ()
38 _webserver->send (401,
"text/plain",
"Wrong authentication!");
44 status =
"Upload failed";
47 if (_webserver->hasArg (
"quiet")) {
48 if(_webserver->arg (
"quiet") ==
"yes") {
49 Serial.println(
"quiet");
50 _webserver->send (200,
"text/plain",
"{\"status\":\"ok\"}");
55 if (_webserver->hasArg (
"path") ) {
56 path += _webserver->arg (
"path") ;
60 path.replace (
"//",
"/");
61 if (path[path.length() - 1] !=
'/') {
65 if (_webserver->hasArg (
"action") ) {
67 if (_webserver->arg (
"action") ==
"delete" && _webserver->hasArg (
"filename") ) {
69 String shortname = _webserver->arg (
"filename");
70 shortname.replace (
"/",
"");
71 filename = path + _webserver->arg (
"filename");
72 filename.replace (
"//",
"/");
74 status = shortname +
" does not exists!";
77 status = shortname +
" deleted";
80 if ( (path !=
"/") && (path[path.length() - 1] =
'/') ) {
81 ptmp = path.substring (0, path.length() - 1);
87 status =
"Cannot deleted " ;
93 if (_webserver->arg (
"action") ==
"deletedir" && _webserver->hasArg (
"filename") ) {
95 String shortname = _webserver->arg (
"filename");
96 shortname.replace (
"/",
"");
97 filename = path + _webserver->arg (
"filename");
99 filename.replace (
"//",
"/");
100 if (filename !=
"/") {
102 log_esp3d(
"Deleting %s",filename.c_str());
104 status +=
" deleted";
106 status =
"Cannot deleted " ;
107 status += shortname ;
112 if (_webserver->arg (
"action") ==
"createdir" && _webserver->hasArg (
"filename") ) {
114 filename = path + _webserver->arg (
"filename") +
"/.";
115 String shortname = _webserver->arg (
"filename");
116 shortname.replace (
"/",
"");
117 filename.replace (
"//",
"/");
119 status = shortname +
" already exists!";
122 status =
"Cannot create ";
123 status += shortname ;
125 status = shortname +
" created";
131 buffer2send.reserve(1200);
132 buffer2send =
"{\"files\":[";
134 if ( (path !=
"/") && (path[path.length() - 1] =
'/') ) {
135 ptmp = path.substring (0, path.length() - 1);
137 _webserver->setContentLength(CONTENT_LENGTH_UNKNOWN);
138 _webserver->sendHeader(
"Content-Type",
"application/json");
139 _webserver->sendHeader(
"Cache-Control",
"no-cache");
140 _webserver->send(200);
146 bool needseparator =
false;
154 buffer2send+=
"{\"name\":\"";
155 buffer2send+=sub.
name();
156 buffer2send+=
"\",\"size\":\"";
162 #ifdef FILESYSTEM_TIMESTAMP_FEATURE
163 buffer2send+=
"\",\"time\":\"";
165 struct tm * tmstruct = localtime(&t);
167 sprintf(str,
"%d-%02d-%02d %02d:%02d:%02d",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
169 #endif //FILESYSTEM_TIMESTAMP_FEATURE
171 if (buffer2send.length() > 1100) {
172 _webserver->sendContent_P(buffer2send.c_str(),buffer2send.length());
180 if (status ==
"ok") {
181 status =
"cannot open" + ptmp;
183 status +=
", cannot open" + ptmp;
187 if (status ==
"ok") {
188 status = ptmp +
" does not exists!";
190 status +=
", " + ptmp +
" does not exists!";
193 buffer2send +=
"],\"path\":\"" + path +
"\",";
198 status =
"FileSystem Error";
199 buffer2send +=
"\"occupation\":\"0\",";
201 buffer2send +=
"\"status\":\"" + status +
"\",";
205 _webserver->sendContent_P(buffer2send.c_str(),buffer2send.length());
206 _webserver->sendContent(
"");
210 #endif //HTTP_FEATURE && FILESYSTEM_FEATURE