Эх сурвалжийг харах

Fixed bug in thumbnail auto delete logic

tobychui 4 жил өмнө
parent
commit
d9342012eb

+ 11 - 17
file_system.go

@@ -1348,6 +1348,10 @@ func system_fs_handleWebSocketOpr(w http.ResponseWriter, r *http.Request) {
 					c.Close()
 					return
 				}
+
+				//Remove the cache for the original file
+				metadata.RemoveCache(rsrcFile)
+
 			} else if operation == "copy" {
 				err := fs.FileCopy(rsrcFile, rdestFile, existsOpr, func(progress int, currentFile string) {
 					//Multply child progress to parent progress
@@ -1538,6 +1542,9 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 					return
 				}
 
+				//Remove the cache for the original file
+				metadata.RemoveCache(rsrcFile)
+
 			} else if operation == "move" {
 				//File move operation. Check if the source file / dir and target directory exists
 				/*
@@ -1614,6 +1621,8 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 				//Set user to own the new file
 				userinfo.SetOwnerOfFile(filepath.ToSlash(filepath.Clean(rdestFile)) + "/" + filepath.Base(rsrcFile))
 
+				//Remove cache for the original file
+				metadata.RemoveCache(rsrcFile)
 			} else if operation == "copy" {
 				//Copy file. See move example and change 'opr' to 'copy'
 				if !fileExists(rsrcFile) {
@@ -1663,17 +1672,6 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 
 				}
 
-				//Check if the desintation is read only.
-				/*
-					accmode := userinfo.GetPathAccessPermission(string(vsrcFile))
-					if accmode == "readonly" {
-						sendErrorResponse(w, "This directory is Read Only.")
-						return
-					} else if accmode == "denied" {
-						sendErrorResponse(w, "Access Denied")
-						return
-					}
-				*/
 				if !userinfo.CanWrite(vsrcFile) {
 					sendErrorResponse(w, "Access Denied.")
 					return
@@ -1687,9 +1685,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 				}
 
 				//Check if this file has any cached files. If yes, remove it
-				if fileExists(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.cache/" + filepath.Base(rsrcFile) + ".jpg") {
-					os.Remove(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.cache/" + filepath.Base(rsrcFile) + ".jpg")
-				}
+				metadata.RemoveCache(rsrcFile)
 
 				//Clear the cache folder if there is no files inside
 				fc, _ := filepath.Glob(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.cache/*")
@@ -1725,9 +1721,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 				}
 
 				//Check if this file has any cached files. If yes, remove it
-				if fileExists(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.cache/" + filepath.Base(rsrcFile) + ".jpg") {
-					os.Remove(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.cache/" + filepath.Base(rsrcFile) + ".jpg")
-				}
+				metadata.RemoveCache(rsrcFile)
 
 				//Clear the cache folder if there is no files inside
 				fc, _ := filepath.Glob(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.cache/*")

+ 0 - 4
mod/filesystem/fileOpr.go

@@ -25,7 +25,6 @@ import (
 	"time"
 
 	"imuslab.com/arozos/mod/filesystem/hidden"
-	"imuslab.com/arozos/mod/filesystem/metadata"
 
 	archiver "github.com/mholt/archiver/v3"
 )
@@ -588,9 +587,6 @@ func FileMove(src string, dest string, mode string, fastMove bool, progressUpdat
 		}
 	}
 
-	//Remove the source cache as it no longer exists in this folder
-	metadata.RemoveCache(src)
-
 	return nil
 }
 

+ 3 - 1
mod/filesystem/metadata/metadata.go

@@ -68,7 +68,7 @@ func (rh *RenderHandler) LoadCache(file string, generateOnly bool) (string, erro
 	hidden.HideFile(cacheFolder)
 
 	//Check if cache already exists. If yes, return the image from the cache folder
-	if fileExists(cacheFolder+filepath.Base(file)+".jpg") || fileExists(cacheFolder+filepath.Base(file)+".png") {
+	if CacheExists(file) {
 		if generateOnly {
 			//Only generate, do not return image
 			return "", nil
@@ -315,6 +315,7 @@ func GetCacheFilePath(file string) (string, error) {
 func RemoveCache(file string) error {
 	if CacheExists(file) {
 		cachePath, err := GetCacheFilePath(file)
+		//log.Println("Removing ", cachePath, err)
 		if err != nil {
 			return err
 		}
@@ -323,6 +324,7 @@ func RemoveCache(file string) error {
 		os.Remove(cachePath)
 		return nil
 	} else {
+		//log.Println("Cache not exists: ", file)
 		return errors.New("Thumbnail cache not exists for this file")
 	}
 }