|
@@ -177,6 +177,50 @@ void HandleShareAccess(AsyncWebServerRequest *r) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//Clear the shares that no longer exists
|
|
|
+void HandleShareListCleaning(AsyncWebServerRequest *r) {
|
|
|
+ if (!HandleAuth(r)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ File root = SD.open(DB_root + "shln/");
|
|
|
+ bool firstObject = true;
|
|
|
+ if (root) {
|
|
|
+ while (true) {
|
|
|
+ File entry = root.openNextFile();
|
|
|
+ if (!entry) {
|
|
|
+ // No more files
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ //Filter out all the directory if any
|
|
|
+ if (entry.isDirectory()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //Read the filename from file
|
|
|
+ String filename = "";
|
|
|
+ while (entry.available()) {
|
|
|
+ filename = filename + entry.readString();
|
|
|
+ }
|
|
|
+
|
|
|
+ //Check if the target file still exists
|
|
|
+ File targetFile = SD.open("/www" + filename);
|
|
|
+ if (!targetFile) {
|
|
|
+ //File no longer exists. Remove this share entry
|
|
|
+ DBRemove("shln", entry.name());
|
|
|
+ DBRemove("shfn", filename);
|
|
|
+ } else {
|
|
|
+ //File still exists.
|
|
|
+ targetFile.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ SendOK(r);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
//Get the file share ID from filename, return empty string if not shared
|
|
|
String GetFileShareIDByFilename(String filepath) {
|
|
|
return DBRead("shfn", filepath);
|