♻️ Adds filesystems endpoints back
This commit is contained in:
@@ -25,6 +25,7 @@ esp_err_t uploadFile(PsychicRequest *request, const std::string &filename, uint6
|
||||
bool last);
|
||||
|
||||
esp_err_t getFiles(PsychicRequest *request);
|
||||
esp_err_t getConfigFile(PsychicRequest *request);
|
||||
esp_err_t handleDelete(PsychicRequest *request, JsonVariant &json);
|
||||
esp_err_t handleEdit(PsychicRequest *request, JsonVariant &json);
|
||||
|
||||
|
||||
@@ -22,6 +22,20 @@ static Initializer initializer;
|
||||
|
||||
esp_err_t getFiles(PsychicRequest *request) { return request->reply(200, "application/json", listFiles("/").c_str()); }
|
||||
|
||||
esp_err_t getConfigFile(PsychicRequest *request) {
|
||||
String path = "/config" + request->uri().substring(11);
|
||||
if (!ESP_FS.exists(path)) {
|
||||
return request->reply(404, "text/plain", "File not found");
|
||||
}
|
||||
File file = ESP_FS.open(path, "r");
|
||||
if (!file) {
|
||||
return request->reply(500, "text/plain", "Failed to open file");
|
||||
}
|
||||
String content = file.readString();
|
||||
file.close();
|
||||
return request->reply(200, "application/json", content.c_str());
|
||||
}
|
||||
|
||||
esp_err_t handleDelete(PsychicRequest *request, JsonVariant &json) {
|
||||
if (json.is<JsonObject>()) {
|
||||
const char *filename = json["file"].as<const char *>();
|
||||
|
||||
+11
-1
@@ -42,7 +42,7 @@ WiFiService wifiService;
|
||||
APService apService;
|
||||
|
||||
void setupServer() {
|
||||
server.config.max_uri_handlers = 28 + WWW_ASSETS_COUNT;
|
||||
server.config.max_uri_handlers = 32 + WWW_ASSETS_COUNT;
|
||||
server.maxUploadSize = 1000000; // 1 MB;
|
||||
server.listen(80);
|
||||
server.serveStatic("/api/config/", ESP_FS, "/config/");
|
||||
@@ -112,6 +112,16 @@ void setupServer() {
|
||||
[&](PsychicRequest *request, JsonVariant &json) { return mdnsService.queryServices(request, json); });
|
||||
#endif
|
||||
|
||||
|
||||
// Filesystem
|
||||
server.on("/api/files", HTTP_GET, [&](PsychicRequest *request) { return FileSystem::getFiles(request); });
|
||||
server.on("/api/files", HTTP_POST, FileSystem::uploadHandler);
|
||||
server.on("/api/files/delete", HTTP_POST,
|
||||
[&](PsychicRequest *request, JsonVariant &json) { return FileSystem::handleDelete(request, json); });
|
||||
server.on("/api/files/edit", HTTP_POST,
|
||||
[&](PsychicRequest *request, JsonVariant &json) { return FileSystem::handleEdit(request, json); });
|
||||
server.on("/api/files/mkdir", HTTP_POST,
|
||||
[&](PsychicRequest *request, JsonVariant &json) { return FileSystem::mkdir(request, json); });
|
||||
#if EMBED_WEBAPP
|
||||
mountStaticAssets(server);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user