Added console server path remapping for long filenames

This commit is contained in:
Mark Qvist 2023-01-13 01:12:42 +01:00
parent 6e03084c1b
commit 70f40e3a77
2 changed files with 28 additions and 3 deletions

View File

@ -79,6 +79,14 @@ bool console_serve_file(String path) {
path += "index.html"; path += "index.html";
} }
if (path == "/r/manual/index.html") {
path = "/m.html"
}
if (path == "/r/manual/Reticulum Manual.pdf") {
path = "/h.html"
}
String content_type = console_get_content_type(path); String content_type = console_get_content_type(path);
String pathWithGz = path + ".gz"; String pathWithGz = path + ".gz";
if (exists(pathWithGz) || exists(path)) { if (exists(pathWithGz) || exists(path)) {
@ -89,14 +97,31 @@ bool console_serve_file(String path) {
File file = SPIFFS.open(path, "r"); File file = SPIFFS.open(path, "r");
console_dbg("Serving file to client"); console_dbg("Serving file to client");
server.streamFile(file, content_type); server.streamFile(file, content_type);
console_dbg("Closing file");
file.close(); file.close();
console_dbg("File serving done"); console_dbg("File serving done\n");
return true; return true;
} else {
int spos = pathWithGz.lastIndexOf('/');
if (spos > 0) {
String remap_path = "/d";
remap_path.concat(pathWithGz.substring(spos));
Serial.println(remap_path);
if (exists(remap_path)) {
File file = SPIFFS.open(remap_path, "r");
console_dbg("Serving remapped file to client");
server.streamFile(file, content_type);
console_dbg("Closing file");
file.close();
console_dbg("File serving done\n");
return true;
}
}
} }
console_dbg("Error: Could not open file for serving"); console_dbg("Error: Could not open file for serving\n");
return false; return false;
} }

Binary file not shown.