27
27
#include < ESP8266WebServer.h>
28
28
#include < ESP8266mDNS.h>
29
29
#include < FS.h>
30
+ #include < LittleFS.h>
31
+
32
+ // FS* filesystem = &SPIFFS;
33
+ FS* filesystem = &LittleFS;
30
34
31
35
#define DBG_OUTPUT_PORT Serial
32
36
@@ -94,11 +98,11 @@ bool handleFileRead(String path) {
94
98
}
95
99
String contentType = getContentType (path);
96
100
String pathWithGz = path + " .gz" ;
97
- if (SPIFFS. exists (pathWithGz) || SPIFFS. exists (path)) {
98
- if (SPIFFS. exists (pathWithGz)) {
101
+ if (filesystem-> exists (pathWithGz) || filesystem-> exists (path)) {
102
+ if (filesystem-> exists (pathWithGz)) {
99
103
path += " .gz" ;
100
104
}
101
- File file = SPIFFS. open (path, " r" );
105
+ File file = filesystem-> open (path, " r" );
102
106
server.streamFile (file, contentType);
103
107
file.close ();
104
108
return true ;
@@ -117,7 +121,7 @@ void handleFileUpload() {
117
121
filename = " /" + filename;
118
122
}
119
123
DBG_OUTPUT_PORT.print (" handleFileUpload Name: " ); DBG_OUTPUT_PORT.println (filename);
120
- fsUploadFile = SPIFFS. open (filename, " w" );
124
+ fsUploadFile = filesystem-> open (filename, " w" );
121
125
filename = String ();
122
126
} else if (upload.status == UPLOAD_FILE_WRITE) {
123
127
// DBG_OUTPUT_PORT.print("handleFileUpload Data: "); DBG_OUTPUT_PORT.println(upload.currentSize);
@@ -141,10 +145,10 @@ void handleFileDelete() {
141
145
if (path == " /" ) {
142
146
return server.send (500 , " text/plain" , " BAD PATH" );
143
147
}
144
- if (!SPIFFS. exists (path)) {
148
+ if (!filesystem-> exists (path)) {
145
149
return server.send (404 , " text/plain" , " FileNotFound" );
146
150
}
147
- SPIFFS. remove (path);
151
+ filesystem-> remove (path);
148
152
server.send (200 , " text/plain" , " " );
149
153
path = String ();
150
154
}
@@ -158,10 +162,10 @@ void handleFileCreate() {
158
162
if (path == " /" ) {
159
163
return server.send (500 , " text/plain" , " BAD PATH" );
160
164
}
161
- if (SPIFFS. exists (path)) {
165
+ if (filesystem-> exists (path)) {
162
166
return server.send (500 , " text/plain" , " FILE EXISTS" );
163
167
}
164
- File file = SPIFFS. open (path, " w" );
168
+ File file = filesystem-> open (path, " w" );
165
169
if (file) {
166
170
file.close ();
167
171
} else {
@@ -179,7 +183,7 @@ void handleFileList() {
179
183
180
184
String path = server.arg (" dir" );
181
185
DBG_OUTPUT_PORT.println (" handleFileList: " + path);
182
- Dir dir = SPIFFS. openDir (path);
186
+ Dir dir = filesystem-> openDir (path);
183
187
path = String ();
184
188
185
189
String output = " [" ;
@@ -192,7 +196,11 @@ void handleFileList() {
192
196
output += " {\" type\" :\" " ;
193
197
output += (isDir) ? " dir" : " file" ;
194
198
output += " \" ,\" name\" :\" " ;
195
- output += String (entry.name ()).substring (1 );
199
+ if (entry.name ()[0 ] == ' /' ) {
200
+ output += &(entry.name ()[1 ]);
201
+ } else {
202
+ output += entry.name ();
203
+ }
196
204
output += " \" }" ;
197
205
entry.close ();
198
206
}
@@ -205,9 +213,9 @@ void setup(void) {
205
213
DBG_OUTPUT_PORT.begin (115200 );
206
214
DBG_OUTPUT_PORT.print (" \n " );
207
215
DBG_OUTPUT_PORT.setDebugOutput (true );
208
- SPIFFS. begin ();
216
+ filesystem-> begin ();
209
217
{
210
- Dir dir = SPIFFS. openDir (" /" );
218
+ Dir dir = filesystem-> openDir (" /" );
211
219
while (dir.next ()) {
212
220
String fileName = dir.fileName ();
213
221
size_t fileSize = dir.fileSize ();
0 commit comments