@@ -82,15 +82,25 @@ String getContentType(String filename) {
82
82
return " text/plain" ;
83
83
}
84
84
85
+ bool exists (String path){
86
+ bool yes = false ;
87
+ File file = SPIFFS.open (path, " r" );
88
+ if (!file.isDirectory ()){
89
+ yes = true ;
90
+ }
91
+ file.close ();
92
+ return yes;
93
+ }
94
+
85
95
bool handleFileRead (String path) {
86
96
DBG_OUTPUT_PORT.println (" handleFileRead: " + path);
87
97
if (path.endsWith (" /" )) {
88
98
path += " index.htm" ;
89
99
}
90
100
String contentType = getContentType (path);
91
101
String pathWithGz = path + " .gz" ;
92
- if (SPIFFS. exists (pathWithGz) || SPIFFS. exists (path)) {
93
- if (SPIFFS. exists (pathWithGz)) {
102
+ if (exists (pathWithGz) || exists (path)) {
103
+ if (exists (pathWithGz)) {
94
104
path += " .gz" ;
95
105
}
96
106
File file = SPIFFS.open (path, " r" );
@@ -136,7 +146,7 @@ void handleFileDelete() {
136
146
if (path == " /" ) {
137
147
return server.send (500 , " text/plain" , " BAD PATH" );
138
148
}
139
- if (!SPIFFS. exists (path)) {
149
+ if (!exists (path)) {
140
150
return server.send (404 , " text/plain" , " FileNotFound" );
141
151
}
142
152
SPIFFS.remove (path);
@@ -153,7 +163,7 @@ void handleFileCreate() {
153
163
if (path == " /" ) {
154
164
return server.send (500 , " text/plain" , " BAD PATH" );
155
165
}
156
- if (SPIFFS. exists (path)) {
166
+ if (exists (path)) {
157
167
return server.send (500 , " text/plain" , " FILE EXISTS" );
158
168
}
159
169
File file = SPIFFS.open (path, " w" );
@@ -189,7 +199,7 @@ void handleFileList() {
189
199
output += " {\" type\" :\" " ;
190
200
output += (file.isDirectory ()) ? " dir" : " file" ;
191
201
output += " \" ,\" name\" :\" " ;
192
- output += String (file.name ());
202
+ output += String (file.name ()). substring ( 1 ) ;
193
203
output += " \" }" ;
194
204
file = root.openNextFile ();
195
205
}
0 commit comments