delete, move files
This commit is contained in:
30
src/main.cpp
30
src/main.cpp
@@ -174,6 +174,33 @@ void handleUpload(AsyncWebServerRequest *request, String filename, size_t index,
|
||||
}
|
||||
}
|
||||
|
||||
void handleMoveFile(AsyncWebServerRequest *request) {
|
||||
String from = request->arg("from");
|
||||
String to = request->arg("to");
|
||||
|
||||
if (SD.exists(from)) {
|
||||
SD.rename(from.c_str(), to.c_str());
|
||||
Serial.println("Moved file: " + from + " to " + to);
|
||||
request->send(200, "text/plain", "File moved successfully.");
|
||||
} else {
|
||||
Serial.println("File not found: " + from);
|
||||
request->send(404, "text/plain", "File not found.");
|
||||
}
|
||||
}
|
||||
|
||||
void handleDeleteFile(AsyncWebServerRequest *request) {
|
||||
String filename = request->arg("filename");
|
||||
|
||||
if (SD.exists(filename)) {
|
||||
SD.remove(filename.c_str());
|
||||
Serial.println("Deleted file: " + filename);
|
||||
request->send(200, "text/plain", "File deleted successfully.");
|
||||
} else {
|
||||
Serial.println("File not found: " + filename);
|
||||
request->send(404, "text/plain", "File not found.");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getBatteryVoltageMv() {
|
||||
uint32_t voltage = analogReadMilliVolts(BAT_VOLTAGE_PIN);
|
||||
voltage *= 2;//*2 because of the voltage divider.
|
||||
@@ -680,6 +707,9 @@ void setup()
|
||||
request->send(200);
|
||||
}, handleUpload);
|
||||
|
||||
server.on("/move_file", HTTP_GET, handleMoveFile);
|
||||
server.on("/delete_file", HTTP_GET, handleDeleteFile);
|
||||
|
||||
server.begin();
|
||||
Serial.println("Wifi initialized.");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user