Browse Source

Fixed thumbnail and share interface, added AGI support to new fs abstraction

Toby Chui 3 years ago
parent
commit
21f823c80c

+ 0 - 4
autorelease.bat

@@ -1,4 +0,0 @@
-@echo off
-set /p id="Enter a release version (e.g. v0.0.1) :"
-git tag "%id%"
-git push origin "%id%"

+ 30 - 17
file_system.go

@@ -1609,7 +1609,7 @@ func system_fs_handleWebSocketOpr(w http.ResponseWriter, r *http.Request) {
 				}
 
 				//Remove the cache for the original file
-				metadata.RemoveCache(rsrcFile)
+				metadata.RemoveCache(thisSrcFsh, rsrcFile)
 
 			} else if operation == "copy" {
 				err := fs.FileCopy(thisSrcFsh, rsrcFile, destFsh, rdestFile, existsOpr, func(progress int, currentFile string) {
@@ -1836,7 +1836,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 				}
 
 				//Remove the cache for the original file
-				metadata.RemoveCache(rsrcFile)
+				metadata.RemoveCache(srcFsh, rsrcFile)
 
 			} else if operation == "move" {
 				//File move operation. Check if the source file / dir and target directory exists
@@ -1903,7 +1903,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 				userinfo.SetOwnerOfFile(filepath.ToSlash(filepath.Clean(rdestFile)) + "/" + filepath.Base(rsrcFile))
 
 				//Remove cache for the original file
-				metadata.RemoveCache(rsrcFile)
+				metadata.RemoveCache(srcFsh, rsrcFile)
 			} else if operation == "copy" {
 				//Copy file. See move example and change 'opr' to 'copy'
 				if !srcFshAbs.FileExists(rsrcFile) {
@@ -1966,7 +1966,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 				}
 
 				//Check if this file has any cached files. If yes, remove it
-				metadata.RemoveCache(rsrcFile)
+				metadata.RemoveCache(srcFsh, rsrcFile)
 
 				//Clear the cache folder if there is no files inside
 				fc, err := srcFshAbs.Glob(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.metadata/.cache/*")
@@ -1996,7 +1996,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 				}
 
 				//Check if this file has any cached files. If yes, remove it
-				metadata.RemoveCache(rsrcFile)
+				metadata.RemoveCache(srcFsh, rsrcFile)
 
 				//Clear the cache folder if there is no files inside
 				fc, err := srcFshAbs.Glob(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.metadata/.cache/*")
@@ -2796,9 +2796,18 @@ func system_fs_FileVersionHistory(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
+	fsh, subpath, err := GetFSHandlerSubpathFromVpath(path)
+	if err != nil {
+		if err != nil {
+			common.SendErrorResponse(w, "Invalid path given")
+			return
+		}
+	}
+	fshAbs := fsh.FileSystemAbstraction
+
 	opr, _ := common.Mv(r, "opr", true)
 
-	rpath, err := userinfo.VirtualPathToRealPath(path)
+	rpath, err := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
 	if err != nil {
 		common.SendErrorResponse(w, "Unable to translate virtual path")
 		return
@@ -2919,12 +2928,12 @@ func system_fs_handleCacheRender(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	//Convert vpath to realpath
-	rpath, err := userinfo.VirtualPathToRealPath(vpath)
+	fsh, subpath, err := GetFSHandlerSubpathFromVpath(vpath)
 	if err != nil {
-		common.SendErrorResponse(w, err.Error())
+		common.SendErrorResponse(w, "Unable to resolve target directory")
 		return
 	}
+	rpath, _ := fsh.FileSystemAbstraction.RealPathToVirtualPath(subpath, userinfo.Username)
 
 	//Get folder sort mode
 	sortMode := "default"
@@ -2934,7 +2943,7 @@ func system_fs_handleCacheRender(w http.ResponseWriter, r *http.Request) {
 	}
 
 	//Perform cache rendering
-	thumbRenderHandler.HandleLoadCache(w, r, rpath, sortMode)
+	thumbRenderHandler.HandleLoadCache(w, r, fsh, rpath, sortMode)
 }
 
 //Handle loading of one thumbnail
@@ -2945,8 +2954,12 @@ func system_fs_handleThumbnailLoad(w http.ResponseWriter, r *http.Request) {
 		common.SendErrorResponse(w, "vpath not defined")
 		return
 	}
-
-	rpath, err := userinfo.VirtualPathToRealPath(vpath)
+	fsh, subpath, err := GetFSHandlerSubpathFromVpath(vpath)
+	if err != nil {
+		common.SendErrorResponse(w, "Unable to resolve target directory")
+		return
+	}
+	rpath, err := fsh.FileSystemAbstraction.VirtualPathToRealPath(subpath, userinfo.Username)
 	if err != nil {
 		common.SendErrorResponse(w, err.Error())
 		return
@@ -2954,7 +2967,7 @@ func system_fs_handleThumbnailLoad(w http.ResponseWriter, r *http.Request) {
 
 	byteMode, _ := common.Mv(r, "bytes", false)
 	if byteMode == "true" {
-		thumbnailBytes, err := thumbRenderHandler.LoadCacheAsBytes(rpath, false)
+		thumbnailBytes, err := thumbRenderHandler.LoadCacheAsBytes(fsh, vpath, userinfo.Username, false)
 		if err != nil {
 			common.SendErrorResponse(w, err.Error())
 			return
@@ -2963,7 +2976,7 @@ func system_fs_handleThumbnailLoad(w http.ResponseWriter, r *http.Request) {
 		w.Header().Add("Content-Type", filetype)
 		w.Write(thumbnailBytes)
 	} else {
-		thumbnailPath, err := thumbRenderHandler.LoadCache(rpath, false)
+		thumbnailPath, err := thumbRenderHandler.LoadCache(fsh, rpath, false)
 		if err != nil {
 			common.SendErrorResponse(w, err.Error())
 			return
@@ -2983,13 +2996,13 @@ func system_fs_handleFolderCache(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	rpath, err := userinfo.VirtualPathToRealPath(vfolderpath)
+	fsh, _, err := GetFSHandlerSubpathFromVpath(vfolderpath)
 	if err != nil {
-		common.SendErrorResponse(w, err.Error())
+		common.SendErrorResponse(w, "unable to resolve path")
 		return
 	}
 
-	thumbRenderHandler.BuildCacheForFolder(rpath)
+	thumbRenderHandler.BuildCacheForFolder(fsh, vfolderpath, userinfo.Username)
 	common.SendOK(w)
 }
 

+ 46 - 38
mod/agi/agi.file.go

@@ -2,13 +2,11 @@ package agi
 
 import (
 	"errors"
-	"io/ioutil"
 	"log"
 	"os"
 	"path/filepath"
 
 	"github.com/robertkrimen/otto"
-	fs "imuslab.com/arozos/mod/filesystem"
 	"imuslab.com/arozos/mod/filesystem/fssort"
 	"imuslab.com/arozos/mod/filesystem/hidden"
 	user "imuslab.com/arozos/mod/user"
@@ -63,7 +61,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Translate the virtual path to realpath
-		rpath, err := virtualPathToRealPath(vpath, u)
+		fsh, rpath, err := virtualPathToRealPath(vpath, u)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
@@ -71,7 +69,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Check if file already exists.
-		if fileExists(rpath) {
+		if fsh.FileSystemAbstraction.FileExists(rpath) {
 			//Check if this user own this file
 			isOwner := u.IsOwnerOfFile(rpath)
 			if isOwner {
@@ -81,7 +79,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Create and write to file using ioutil
-		err = ioutil.WriteFile(rpath, []byte(content), 0755)
+		err = fsh.FileSystemAbstraction.WriteFile(rpath, []byte(content), 0755)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
@@ -109,7 +107,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Translate the virtual path to realpath
-		rpath, err := virtualPathToRealPath(vpath, u)
+		fsh, rpath, err := virtualPathToRealPath(vpath, u)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
@@ -117,7 +115,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Check if file already exists.
-		if fileExists(rpath) {
+		if fsh.FileSystemAbstraction.FileExists(rpath) {
 			//Check if this user own this file
 			isOwner := u.IsOwnerOfFile(rpath)
 			if isOwner {
@@ -131,7 +129,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Remove the file
-		os.Remove(rpath)
+		fsh.FileSystemAbstraction.Remove(rpath)
 
 		reply, _ := vm.ToValue(true)
 		return reply
@@ -152,7 +150,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Translate the virtual path to realpath
-		rpath, err := virtualPathToRealPath(vpath, u)
+		fsh, rpath, err := virtualPathToRealPath(vpath, u)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
@@ -160,7 +158,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Create and write to file using ioUtil
-		content, err := ioutil.ReadFile(rpath)
+		content, err := fsh.FileSystemAbstraction.ReadFile(rpath)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
@@ -181,16 +179,16 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Translate the virtual path to realpath
-		rpath, err := virtualPathToRealPath(vpath, u)
+		fsh, rpath, err := virtualPathToRealPath(vpath, u)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
 			return reply
 		}
+		fshAbs := fsh.FileSystemAbstraction
 
 		rpath = filepath.ToSlash(filepath.Clean(rpath)) + "/*"
-
-		fileList, err := specialGlob(rpath)
+		fileList, err := fshAbs.Glob(rpath)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
@@ -200,14 +198,11 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		//Translate all paths to virtual paths
 		results := []string{}
 		for _, file := range fileList {
-			//if IsDir(file) {
 			isHidden, _ := hidden.IsHidden(file, true)
 			if !isHidden {
-				thisRpath, _ := realpathToVirtualpath(file, u)
+				thisRpath, _ := fshAbs.RealPathToVirtualPath(file, u.Username)
 				results = append(results, thisRpath)
 			}
-
-			//}
 		}
 
 		reply, _ := vm.ToValue(results)
@@ -230,7 +225,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 			mode = "all"
 		}
 
-		rpath, err := virtualPathToRealPath(vpath, u)
+		fsh, rpath, err := virtualPathToRealPath(vpath, u)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
@@ -242,7 +237,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 				//Ignore this error file and continue
 				return nil
 			}
-			thisVpath, err := realpathToVirtualpath(path, u)
+			thisVpath, err := realpathToVirtualpath(fsh, path, u)
 			if err != nil {
 				return nil
 			}
@@ -323,14 +318,14 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 			}
 
 			//Translate the virtual path to realpath
-			rrootPath, err := virtualPathToRealPath(vrootPath, u)
+			fsh, rrootPath, err := virtualPathToRealPath(vrootPath, u)
 			if err != nil {
 				g.raiseError(err)
 				reply, _ := vm.ToValue(false)
 				return reply
 			}
 
-			suitableFiles, err := filepath.Glob(filepath.Join(rrootPath, regexFilename))
+			suitableFiles, err := fsh.FileSystemAbstraction.Glob(filepath.Join(rrootPath, regexFilename))
 			if err != nil {
 				g.raiseError(err)
 				reply, _ := vm.ToValue(false)
@@ -348,7 +343,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 					//Hidden file. Skip this
 					continue
 				}
-				thisRpath, _ := realpathToVirtualpath(filepath.ToSlash(file), u)
+				thisRpath, _ := realpathToVirtualpath(fsh, filepath.ToSlash(file), u)
 				results = append(results, thisRpath)
 			}
 			reply, _ := vm.ToValue(results)
@@ -394,14 +389,15 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Translate the virtual path to realpath
-		rrootPath, err := virtualPathToRealPath(vrootPath, u)
+		fsh, err := u.GetFileSystemHandlerFromVirtualPath(vrootPath)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
 			return reply
 		}
-
-		suitableFiles, err := specialGlob(filepath.Join(rrootPath, regexFilename))
+		fshAbs := fsh.FileSystemAbstraction
+		rrootPath, _ := fshAbs.VirtualPathToRealPath(vrootPath, u.Username)
+		suitableFiles, err := fshAbs.Glob(filepath.Join(rrootPath, regexFilename))
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
@@ -441,8 +437,14 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 			panic(vm.MakeCustomError("PermissionDenied", "Path access denied"))
 		}
 
-		//Translate the virtual path to realpath
-		rpath, err := virtualPathToRealPath(vpath, u)
+		fsh, err := u.GetFileSystemHandlerFromVirtualPath(vpath)
+		if err != nil {
+			g.raiseError(err)
+			reply, _ := vm.ToValue(false)
+			return reply
+		}
+		fshAbs := fsh.FileSystemAbstraction
+		rpath, err := fshAbs.VirtualPathToRealPath(vpath, u.Username)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
@@ -450,7 +452,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Get filesize of file
-		rawsize := fs.GetFileSize(rpath)
+		rawsize := fshAbs.GetFileSize(rpath)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
@@ -475,15 +477,21 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 			panic(vm.MakeCustomError("PermissionDenied", "Path access denied"))
 		}
 
-		//Translate the virtual path to realpath
-		rpath, err := virtualPathToRealPath(vpath, u)
+		fsh, err := u.GetFileSystemHandlerFromVirtualPath(vpath)
+		if err != nil {
+			g.raiseError(err)
+			reply, _ := vm.ToValue(false)
+			return reply
+		}
+		fshAbs := fsh.FileSystemAbstraction
+		rpath, err := fshAbs.VirtualPathToRealPath(vpath, u.Username)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
 			return reply
 		}
 
-		if fileExists(rpath) {
+		if fshAbs.FileExists(rpath) {
 			reply, _ := vm.ToValue(true)
 			return reply
 		} else {
@@ -507,19 +515,19 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Translate the virtual path to realpath
-		rpath, err := virtualPathToRealPath(vpath, u)
+		fsh, rpath, err := virtualPathToRealPath(vpath, u)
 		if err != nil {
 			g.raiseError(err)
 			reply, _ := vm.ToValue(false)
 			return reply
 		}
 
-		if _, err := os.Stat(rpath); os.IsNotExist(err) {
+		if _, err := fsh.FileSystemAbstraction.Stat(rpath); os.IsNotExist(err) {
 			//File not exists
 			panic(vm.MakeCustomError("File Not Exists", "Required path not exists"))
 		}
 
-		if IsDir(rpath) {
+		if fsh.FileSystemAbstraction.IsDir(rpath) {
 			reply, _ := vm.ToValue(true)
 			return reply
 		} else {
@@ -541,14 +549,14 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Translate the path to realpath
-		rdir, err := virtualPathToRealPath(vdir, u)
+		fsh, rdir, err := virtualPathToRealPath(vdir, u)
 		if err != nil {
 			log.Println(err.Error())
 			return otto.FalseValue()
 		}
 
 		//Create the directory at rdir location
-		err = os.MkdirAll(rdir, 0755)
+		err = fsh.FileSystemAbstraction.MkdirAll(rdir, 0755)
 		if err != nil {
 			log.Println(err.Error())
 			return otto.FalseValue()
@@ -603,13 +611,13 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 			parseToUnix = false
 		}
 
-		rpath, err := virtualPathToRealPath(vpath, u)
+		fsh, rpath, err := virtualPathToRealPath(vpath, u)
 		if err != nil {
 			log.Println(err.Error())
 			return otto.FalseValue()
 		}
 
-		info, err := os.Stat(rpath)
+		info, err := fsh.FileSystemAbstraction.Stat(rpath)
 		if err != nil {
 			log.Println(err.Error())
 			return otto.FalseValue()

+ 19 - 14
mod/agi/agi.image.go

@@ -3,12 +3,12 @@ package agi
 import (
 	"bytes"
 	"errors"
+	"fmt"
 	"image"
 	"image/jpeg"
 	_ "image/jpeg"
 	"image/png"
 	_ "image/png"
-	"io/ioutil"
 	"log"
 	"os"
 	"path/filepath"
@@ -46,17 +46,19 @@ func (g *Gateway) injectImageLibFunctions(vm *otto.Otto, u *user.User) {
 			return otto.FalseValue()
 		}
 
-		imagePath, err := virtualPathToRealPath(imageFileVpath, u)
+		fsh, imagePath, err := virtualPathToRealPath(imageFileVpath, u)
 		if err != nil {
 			g.raiseError(err)
 			return otto.FalseValue()
 		}
 
-		if !fileExists(imagePath) {
+		if !fsh.FileSystemAbstraction.FileExists(imagePath) {
 			g.raiseError(errors.New("File not exists! Given " + imagePath))
 			return otto.FalseValue()
 		}
 
+		panic("fix point 1")
+
 		file, err := os.Open(imagePath)
 		if err != nil {
 			g.raiseError(err)
@@ -101,12 +103,12 @@ func (g *Gateway) injectImageLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Convert the virtual paths to real paths
-		rsrc, err := virtualPathToRealPath(vsrc, u)
+		_, rsrc, err := virtualPathToRealPath(vsrc, u)
 		if err != nil {
 			g.raiseError(err)
 			return otto.FalseValue()
 		}
-		rdest, err := virtualPathToRealPath(vdest, u)
+		destfsh, rdest, err := virtualPathToRealPath(vdest, u)
 		if err != nil {
 			g.raiseError(err)
 			return otto.FalseValue()
@@ -118,8 +120,8 @@ func (g *Gateway) injectImageLibFunctions(vm *otto.Otto, u *user.User) {
 			return otto.FalseValue()
 		}
 
-		if fileExists(rdest) {
-			err := os.Remove(rdest)
+		if destfsh.FileSystemAbstraction.FileExists(rdest) {
+			err := destfsh.FileSystemAbstraction.Remove(rdest)
 			if err != nil {
 				g.raiseError(err)
 				return otto.FalseValue()
@@ -179,19 +181,22 @@ func (g *Gateway) injectImageLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Convert the virtual paths to realpaths
-		rsrc, err := virtualPathToRealPath(vsrc, u)
+		srcFsh, rsrc, err := virtualPathToRealPath(vsrc, u)
 		if err != nil {
 			g.raiseError(err)
 			return otto.FalseValue()
 		}
-		rdest, err := virtualPathToRealPath(vdest, u)
+		srcFshAbs := srcFsh.FileSystemAbstraction
+		destFsh, rdest, err := virtualPathToRealPath(vdest, u)
 		if err != nil {
 			g.raiseError(err)
 			return otto.FalseValue()
 		}
+		destFshAbs := destFsh.FileSystemAbstraction
+		fmt.Println("WIP", destFshAbs)
 
 		//Try to read the source image
-		imageBytes, err := ioutil.ReadFile(rsrc)
+		imageBytes, err := srcFshAbs.ReadFile(rsrc)
 		if err != nil {
 			g.raiseError(err)
 			return otto.FalseValue()
@@ -240,15 +245,15 @@ func (g *Gateway) injectImageLibFunctions(vm *otto.Otto, u *user.User) {
 			return otto.FalseValue()
 		}
 
-		//Convert the vsrc to real path
-		rsrc, err := virtualPathToRealPath(vsrc, u)
+		fsh, err := u.GetFileSystemHandlerFromVirtualPath(vsrc)
 		if err != nil {
 			g.raiseError(err)
 			return otto.FalseValue()
 		}
+		rpath, _ := fsh.FileSystemAbstraction.VirtualPathToRealPath(vsrc, u.Username)
 
 		//Get the files' thumb base64 string
-		base64String, err := g.Option.FileSystemRender.LoadCache(rsrc, false)
+		base64String, err := g.Option.FileSystemRender.LoadCache(fsh, rpath, false)
 		if err != nil {
 			return otto.FalseValue()
 		} else {
@@ -274,7 +279,7 @@ func (g *Gateway) injectImageLibFunctions(vm *otto.Otto, u *user.User) {
 		}
 
 		//Convert the vsrc to real path
-		rsrc, err := virtualPathToRealPath(vsrc, u)
+		_, rsrc, err := virtualPathToRealPath(vsrc, u)
 		if err != nil {
 			g.raiseError(err)
 			return otto.FalseValue()

+ 30 - 15
mod/agi/userFunc.go

@@ -9,16 +9,25 @@ import (
 	"path/filepath"
 
 	"github.com/robertkrimen/otto"
+	"imuslab.com/arozos/mod/filesystem"
 	user "imuslab.com/arozos/mod/user"
 )
 
 //Define path translation function
-func virtualPathToRealPath(path string, u *user.User) (string, error) {
-	return u.VirtualPathToRealPath(path)
+func virtualPathToRealPath(vpath string, u *user.User) (*filesystem.FileSystemHandler, string, error) {
+	fsh, err := u.GetFileSystemHandlerFromVirtualPath(vpath)
+	if err != nil {
+		return nil, "", err
+	}
+	rpath, err := fsh.FileSystemAbstraction.VirtualPathToRealPath(vpath, u.Username)
+	if err != nil {
+		return nil, "", err
+	}
+	return fsh, rpath, nil
 }
 
-func realpathToVirtualpath(path string, u *user.User) (string, error) {
-	return u.RealPathToVirtualPath(path)
+func realpathToVirtualpath(fsh *filesystem.FileSystemHandler, path string, u *user.User) (string, error) {
+	return fsh.FileSystemAbstraction.RealPathToVirtualPath(path, u.Username)
 }
 
 //Inject user based functions into the virtual machine
@@ -33,8 +42,9 @@ func (g *Gateway) injectUserFunctions(vm *otto.Otto, scriptFile string, scriptSc
 
 	//File system and path related
 	vm.Set("decodeVirtualPath", func(call otto.FunctionCall) otto.Value {
+		log.Println("Call to deprecated function decodeVirtualPath")
 		path, _ := call.Argument(0).ToString()
-		realpath, err := virtualPathToRealPath(path, u)
+		_, realpath, err := virtualPathToRealPath(path, u)
 		if err != nil {
 			reply, _ := vm.ToValue(false)
 			return reply
@@ -45,8 +55,9 @@ func (g *Gateway) injectUserFunctions(vm *otto.Otto, scriptFile string, scriptSc
 	})
 
 	vm.Set("decodeAbsoluteVirtualPath", func(call otto.FunctionCall) otto.Value {
+		log.Println("Call to deprecated function decodeAbsoluteVirtualPath")
 		path, _ := call.Argument(0).ToString()
-		realpath, err := virtualPathToRealPath(path, u)
+		_, realpath, err := virtualPathToRealPath(path, u)
 		if err != nil {
 			reply, _ := vm.ToValue(false)
 			return reply
@@ -63,15 +74,19 @@ func (g *Gateway) injectUserFunctions(vm *otto.Otto, scriptFile string, scriptSc
 	})
 
 	vm.Set("encodeRealPath", func(call otto.FunctionCall) otto.Value {
-		path, _ := call.Argument(0).ToString()
-		realpath, err := realpathToVirtualpath(path, u)
-		if err != nil {
-			reply, _ := vm.ToValue(false)
-			return reply
-		} else {
-			reply, _ := vm.ToValue(realpath)
-			return reply
-		}
+		log.Println("Call to deprecated function encodeRealPath")
+		/*
+			path, _ := call.Argument(0).ToString()
+			_, realpath, err := realpathToVirtualpath(path, u)
+			if err != nil {
+				reply, _ := vm.ToValue(false)
+				return reply
+			} else {
+				reply, _ := vm.ToValue(realpath)
+				return reply
+			}
+		*/
+		return otto.FalseValue()
 	})
 
 	//Check if a given virtual path is readonly

+ 7 - 3
mod/filesystem/metadata/audio.go

@@ -10,10 +10,13 @@ import (
 	"github.com/dhowden/tag"
 	"github.com/nfnt/resize"
 	"github.com/oliamb/cutter"
+	"imuslab.com/arozos/mod/filesystem"
 )
 
-func generateThumbnailForAudio(cacheFolder string, file string, generateOnly bool) (string, error) {
-
+func generateThumbnailForAudio(fsh *filesystem.FileSystemHandler, cacheFolder string, file string, generateOnly bool) (string, error) {
+	if fsh.RequireBuffer {
+		return "", nil
+	}
 	//This extension is supported by id4. Call to library
 	f, err := os.Open(file)
 	defer f.Close()
@@ -57,11 +60,12 @@ func generateThumbnailForAudio(cacheFolder string, file string, generateOnly boo
 		})
 
 		//Write the cache image to disk
+
 		jpeg.Encode(out, croppedImg, nil)
 
 		if !generateOnly {
 			//return the image as well
-			ctx, err := getImageAsBase64(cacheFolder + filepath.Base(file) + ".jpg")
+			ctx, err := getImageAsBase64(fsh, cacheFolder+filepath.Base(file)+".jpg")
 			return ctx, err
 		}
 

+ 6 - 2
mod/filesystem/metadata/folder.go

@@ -12,6 +12,7 @@ import (
 	"strings"
 
 	"github.com/nfnt/resize"
+	"imuslab.com/arozos/mod/filesystem"
 )
 
 /*
@@ -19,7 +20,10 @@ import (
 	The preview is generated by overlapping 2 - 3 layers of images
 */
 
-func generateThumbnailForFolder(cacheFolder string, file string, generateOnly bool) (string, error) {
+func generateThumbnailForFolder(fsh *filesystem.FileSystemHandler, cacheFolder string, file string, generateOnly bool) (string, error) {
+	if fsh.RequireBuffer {
+		return "", nil
+	}
 	//Check if this folder has cache image folder
 	cacheFolderInsideThisFolder := filepath.Join(file, "/.metadata/.cache")
 	if !fileExists(cacheFolderInsideThisFolder) {
@@ -98,7 +102,7 @@ func generateThumbnailForFolder(cacheFolder string, file string, generateOnly bo
 	png.Encode(outfile, resultThumbnail)
 	outfile.Close()
 
-	ctx, err := getImageAsBase64(cacheFolder + filepath.Base(file) + ".png")
+	ctx, err := getImageAsBase64(fsh, cacheFolder+filepath.Base(file)+".png")
 	return ctx, err
 }
 

+ 5 - 4
mod/filesystem/metadata/image.go

@@ -4,16 +4,17 @@ import (
 	"bytes"
 	"image"
 	"image/jpeg"
-	"io/ioutil"
 	"os"
 	"path/filepath"
 
 	"github.com/nfnt/resize"
 	"github.com/oliamb/cutter"
+	"imuslab.com/arozos/mod/filesystem"
 )
 
-func generateThumbnailForImage(cacheFolder string, file string, generateOnly bool) (string, error) {
-	imageBytes, err := ioutil.ReadFile(file)
+func generateThumbnailForImage(fsh *filesystem.FileSystemHandler, cacheFolder string, file string, generateOnly bool) (string, error) {
+	fshAbs := fsh.FileSystemAbstraction
+	imageBytes, err := fshAbs.ReadFile(file)
 	if err != nil {
 		return "", err
 	}
@@ -54,7 +55,7 @@ func generateThumbnailForImage(cacheFolder string, file string, generateOnly boo
 
 	if !generateOnly {
 		//return the image as well
-		ctx, err := getImageAsBase64(cacheFolder + filepath.Base(file) + ".jpg")
+		ctx, err := getImageAsBase64(fsh, cacheFolder+filepath.Base(file)+".jpg")
 		return ctx, err
 	} else {
 		return "", nil

+ 71 - 71
mod/filesystem/metadata/metadata.go

@@ -1,11 +1,9 @@
 package metadata
 
 import (
-	"bufio"
 	"encoding/base64"
 	"encoding/json"
 	"errors"
-	"io/ioutil"
 	"log"
 	"net/http"
 	"os"
@@ -16,6 +14,7 @@ import (
 
 	"github.com/gorilla/websocket"
 
+	"imuslab.com/arozos/mod/filesystem"
 	"imuslab.com/arozos/mod/filesystem/fssort"
 	hidden "imuslab.com/arozos/mod/filesystem/hidden"
 )
@@ -40,27 +39,32 @@ func NewRenderHandler() *RenderHandler {
 }
 
 //Build cache for all files (non recursive) for the given filepath
-func (rh *RenderHandler) BuildCacheForFolder(path string) error {
+func (rh *RenderHandler) BuildCacheForFolder(fsh *filesystem.FileSystemHandler, vpath string, username string) error {
+	fshAbs := fsh.FileSystemAbstraction
+	rpath, _ := fshAbs.RealPathToVirtualPath(vpath, username)
+
 	//Get a list of all files inside this path
-	files, err := filepath.Glob(filepath.ToSlash(filepath.Clean(path)) + "/*")
+	files, err := fshAbs.Glob(filepath.ToSlash(filepath.Clean(rpath)) + "/*")
 	if err != nil {
 		return err
 	}
 	for _, file := range files {
 		//Load Cache in generate mode
-		rh.LoadCache(file, true)
+		rh.LoadCache(fsh, file, true)
 	}
 
 	//Check if the cache folder has file. If not, remove it
-	cachedFiles, _ := filepath.Glob(filepath.ToSlash(filepath.Join(filepath.Clean(path), "/.metadata/.cache/*")))
+	cachedFiles, _ := fshAbs.Glob(filepath.ToSlash(filepath.Join(filepath.Clean(rpath), "/.metadata/.cache/*")))
 	if len(cachedFiles) == 0 {
-		os.RemoveAll(filepath.ToSlash(filepath.Join(filepath.Clean(path), "/.metadata/.cache/")) + "/")
+		fshAbs.RemoveAll(filepath.ToSlash(filepath.Join(filepath.Clean(rpath), "/.metadata/.cache/")) + "/")
 	}
 	return nil
 }
 
-func (rh *RenderHandler) LoadCacheAsBytes(file string, generateOnly bool) ([]byte, error) {
-	b64, err := rh.LoadCache(file, generateOnly)
+func (rh *RenderHandler) LoadCacheAsBytes(fsh *filesystem.FileSystemHandler, vpath string, username string, generateOnly bool) ([]byte, error) {
+	fshAbs := fsh.FileSystemAbstraction
+	rpath, _ := fshAbs.VirtualPathToRealPath(vpath, username)
+	b64, err := rh.LoadCache(fsh, rpath, generateOnly)
 	if err != nil {
 		return []byte{}, err
 	}
@@ -70,15 +74,16 @@ func (rh *RenderHandler) LoadCacheAsBytes(file string, generateOnly bool) ([]byt
 }
 
 //Try to load a cache from file. If not exists, generate it now
-func (rh *RenderHandler) LoadCache(file string, generateOnly bool) (string, error) {
+func (rh *RenderHandler) LoadCache(fsh *filesystem.FileSystemHandler, rpath string, generateOnly bool) (string, error) {
 	//Create a cache folder
-	cacheFolder := filepath.ToSlash(filepath.Join(filepath.Clean(filepath.Dir(file)), "/.metadata/.cache/") + "/")
-	os.MkdirAll(cacheFolder, 0755)
+	fshAbs := fsh.FileSystemAbstraction
+	cacheFolder := filepath.ToSlash(filepath.Join(filepath.Clean(filepath.Dir(rpath)), "/.metadata/.cache/") + "/")
+	fshAbs.MkdirAll(cacheFolder, 0755)
 	hidden.HideFile(filepath.Dir(filepath.Clean(cacheFolder)))
 	hidden.HideFile(cacheFolder)
 
 	//Check if cache already exists. If yes, return the image from the cache folder
-	if CacheExists(file) {
+	if CacheExists(fsh, rpath) {
 		if generateOnly {
 			//Only generate, do not return image
 			return "", nil
@@ -86,93 +91,95 @@ func (rh *RenderHandler) LoadCache(file string, generateOnly bool) (string, erro
 
 		//Allow thumbnail to be either jpg or png file
 		ext := ".jpg"
-		if !fileExists(cacheFolder + filepath.Base(file) + ".jpg") {
+		if !fshAbs.FileExists(cacheFolder + filepath.Base(rpath) + ".jpg") {
 			ext = ".png"
 		}
 
 		//Updates 02/10/2021: Check if the source file is newer than the cache. Update the cache if true
-		if mtime(file) > mtime(cacheFolder+filepath.Base(file)+ext) {
+		folderModeTime, _ := fshAbs.GetModTime(rpath)
+		cacheImageModeTime, _ := fshAbs.GetModTime(cacheFolder + filepath.Base(rpath) + ext)
+		if folderModeTime > cacheImageModeTime {
 			//File is newer than cache. Delete the cache
-			os.Remove(cacheFolder + filepath.Base(file) + ext)
+			fshAbs.Remove(cacheFolder + filepath.Base(rpath) + ext)
 		} else {
 			//Check if the file is being writting by another process. If yes, wait for it
 			counter := 0
-			for rh.fileIsBusy(file) && counter < 15 {
+			for rh.fileIsBusy(rpath) && counter < 15 {
 				counter += 1
 				time.Sleep(1 * time.Second)
 			}
 
 			//Time out and the file is still busy
-			if rh.fileIsBusy(file) {
-				log.Println("Process racing for cache file. Skipping", file)
+			if rh.fileIsBusy(rpath) {
+				log.Println("Process racing for cache file. Skipping", filepath.Base(rpath))
 				return "", errors.New("Process racing for cache file. Skipping")
 			}
 
 			//Read and return the image
-			ctx, err := getImageAsBase64(cacheFolder + filepath.Base(file) + ext)
+			ctx, err := getImageAsBase64(fsh, cacheFolder+filepath.Base(rpath)+ext)
 			return ctx, err
 		}
 
 	} else {
 		//This file not exists yet. Check if it is being hold by another process already
-		if rh.fileIsBusy(file) {
-			log.Println("Process racing for cache file. Skipping", file)
+		if rh.fileIsBusy(rpath) {
+			log.Println("Process racing for cache file. Skipping", filepath.Base(rpath))
 			return "", errors.New("Process racing for cache file. Skipping")
 		}
 	}
 
 	//Cache image not exists. Set this file to busy
-	rh.renderingFiles.Store(file, "busy")
+	rh.renderingFiles.Store(rpath, "busy")
 
 	//That object not exists. Generate cache image
 	//Audio formats that might contains id4 thumbnail
 	id4Formats := []string{".mp3", ".ogg", ".flac"}
-	if inArray(id4Formats, strings.ToLower(filepath.Ext(file))) {
-		img, err := generateThumbnailForAudio(cacheFolder, file, generateOnly)
-		rh.renderingFiles.Delete(file)
+	if inArray(id4Formats, strings.ToLower(filepath.Ext(rpath))) {
+		img, err := generateThumbnailForAudio(fsh, cacheFolder, rpath, generateOnly)
+		rh.renderingFiles.Delete(rpath)
 		return img, err
 	}
 
 	//Generate resized image for images
 	imageFormats := []string{".png", ".jpeg", ".jpg"}
-	if inArray(imageFormats, strings.ToLower(filepath.Ext(file))) {
-		img, err := generateThumbnailForImage(cacheFolder, file, generateOnly)
-		rh.renderingFiles.Delete(file)
+	if inArray(imageFormats, strings.ToLower(filepath.Ext(rpath))) {
+		img, err := generateThumbnailForImage(fsh, cacheFolder, rpath, generateOnly)
+		rh.renderingFiles.Delete(rpath)
 		return img, err
 	}
 
 	//Video formats, extract from the 5 sec mark
 	vidFormats := []string{".mkv", ".mp4", ".webm", ".ogv", ".avi", ".rmvb"}
-	if inArray(vidFormats, strings.ToLower(filepath.Ext(file))) {
-		img, err := generateThumbnailForVideo(cacheFolder, file, generateOnly)
-		rh.renderingFiles.Delete(file)
+	if inArray(vidFormats, strings.ToLower(filepath.Ext(rpath))) {
+		img, err := generateThumbnailForVideo(fsh, cacheFolder, rpath, generateOnly)
+		rh.renderingFiles.Delete(rpath)
 		return img, err
 	}
 
 	//3D Model Formats
 	modelFormats := []string{".stl", ".obj"}
-	if inArray(modelFormats, strings.ToLower(filepath.Ext(file))) {
-		img, err := generateThumbnailForModel(cacheFolder, file, generateOnly)
-		rh.renderingFiles.Delete(file)
+	if inArray(modelFormats, strings.ToLower(filepath.Ext(rpath))) {
+		img, err := generateThumbnailForModel(fsh, cacheFolder, rpath, generateOnly)
+		rh.renderingFiles.Delete(rpath)
 		return img, err
 	}
 
 	//Photoshop file
-	if strings.ToLower(filepath.Ext(file)) == ".psd" {
-		img, err := generateThumbnailForPSD(cacheFolder, file, generateOnly)
-		rh.renderingFiles.Delete(file)
+	if strings.ToLower(filepath.Ext(rpath)) == ".psd" {
+		img, err := generateThumbnailForPSD(fsh, cacheFolder, rpath, generateOnly)
+		rh.renderingFiles.Delete(rpath)
 		return img, err
 	}
 
 	//Folder preview renderer
-	if isDir(file) && len(filepath.Base(file)) > 0 && filepath.Base(file)[:1] != "." {
-		img, err := generateThumbnailForFolder(cacheFolder, file, generateOnly)
-		rh.renderingFiles.Delete(file)
+	if fshAbs.IsDir(rpath) && len(filepath.Base(rpath)) > 0 && filepath.Base(rpath)[:1] != "." {
+		img, err := generateThumbnailForFolder(fsh, cacheFolder, rpath, generateOnly)
+		rh.renderingFiles.Delete(rpath)
 		return img, err
 	}
 
 	//Other filters
-	rh.renderingFiles.Delete(file)
+	rh.renderingFiles.Delete(rpath)
 	return "", errors.New("No supported format")
 }
 
@@ -190,27 +197,18 @@ func (rh *RenderHandler) fileIsBusy(path string) bool {
 	}
 }
 
-func getImageAsBase64(path string) (string, error) {
-	f, err := os.Open(path)
-	if err != nil {
-		return "", err
-	}
-
-	//Added Seek to 0,0 function to prevent failed to decode: Unexpected EOF error
-	f.Seek(0, 0)
-
-	reader := bufio.NewReader(f)
-	content, err := ioutil.ReadAll(reader)
+func getImageAsBase64(fsh *filesystem.FileSystemHandler, rpath string) (string, error) {
+	fshAbs := fsh.FileSystemAbstraction
+	content, err := fshAbs.ReadFile(rpath)
 	if err != nil {
 		return "", err
 	}
 	encoded := base64.StdEncoding.EncodeToString(content)
-	f.Close()
 	return string(encoded), nil
 }
 
 //Load a list of folder cache from websocket, pass in "" (empty string) for default sorting method
-func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request, rpath string, sortmode string) {
+func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request, fsh *filesystem.FileSystemHandler, rpath string, sortmode string) {
 	//Get a list of files pending to be cached and sent
 	targetPath := filepath.ToSlash(filepath.Clean(rpath))
 
@@ -222,7 +220,7 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
 		oldc.(*websocket.Conn).Close()
 	}
 
-	files, err := specialGlob(targetPath + "/*")
+	files, err := specialGlob(fsh, targetPath+"/*")
 	if err != nil {
 		w.WriteHeader(http.StatusInternalServerError)
 		w.Write([]byte("500 - Internal Server Error"))
@@ -267,12 +265,12 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
 
 	//Updated implementation 24/12/2020: Load image with cache first before rendering those without
 	for _, file := range files {
-		if !CacheExists(file) {
+		if !CacheExists(fsh, file) {
 			//Cache not exists. Render this later
 			filesWithoutCache = append(filesWithoutCache, file)
 		} else {
 			//Cache exists. Send it out first
-			cachedImage, err := rh.LoadCache(file, false)
+			cachedImage, err := rh.LoadCache(fsh, file, false)
 			if err != nil {
 
 			} else {
@@ -292,7 +290,7 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
 	//Render the remaining cache files
 	for _, file := range filesWithoutCache {
 		//Load the image cache
-		cachedImage, err := rh.LoadCache(file, false)
+		cachedImage, err := rh.LoadCache(fsh, file, false)
 		if err != nil {
 			//Unable to load this file's cache. Push it to retry list
 			retryList = append(retryList, file)
@@ -312,7 +310,7 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
 		time.Sleep(1000 * time.Millisecond)
 		for _, file := range retryList {
 			//Load the image cache
-			cachedImage, err := rh.LoadCache(file, false)
+			cachedImage, err := rh.LoadCache(fsh, file, false)
 			if err != nil {
 
 			} else {
@@ -337,18 +335,19 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
 }
 
 //Check if the cache for a file exists
-func CacheExists(file string) bool {
+func CacheExists(fsh *filesystem.FileSystemHandler, file string) bool {
 	cacheFolder := filepath.ToSlash(filepath.Join(filepath.Clean(filepath.Dir(file)), "/.metadata/.cache/") + "/")
-	return fileExists(cacheFolder+filepath.Base(file)+".jpg") || fileExists(cacheFolder+filepath.Base(file)+".png")
+	return fsh.FileSystemAbstraction.FileExists(cacheFolder+filepath.Base(file)+".jpg") || fileExists(cacheFolder+filepath.Base(file)+".png")
 }
 
 //Get cache path for this file, given realpath
-func GetCacheFilePath(file string) (string, error) {
-	if CacheExists(file) {
+func GetCacheFilePath(fsh *filesystem.FileSystemHandler, file string) (string, error) {
+	if CacheExists(fsh, file) {
+		fshAbs := fsh.FileSystemAbstraction
 		cacheFolder := filepath.ToSlash(filepath.Join(filepath.Clean(filepath.Dir(file)), "/.metadata/.cache/") + "/")
-		if fileExists(cacheFolder + filepath.Base(file) + ".jpg") {
+		if fshAbs.FileExists(cacheFolder + filepath.Base(file) + ".jpg") {
 			return cacheFolder + filepath.Base(file) + ".jpg", nil
-		} else if fileExists(cacheFolder + filepath.Base(file) + ".png") {
+		} else if fshAbs.FileExists(cacheFolder + filepath.Base(file) + ".png") {
 			return cacheFolder + filepath.Base(file) + ".png", nil
 		} else {
 			return "", errors.New("Unable to resolve thumbnail cache location")
@@ -359,9 +358,9 @@ func GetCacheFilePath(file string) (string, error) {
 }
 
 //Remove cache if exists, given realpath
-func RemoveCache(file string) error {
-	if CacheExists(file) {
-		cachePath, err := GetCacheFilePath(file)
+func RemoveCache(fsh *filesystem.FileSystemHandler, file string) error {
+	if CacheExists(fsh, file) {
+		cachePath, err := GetCacheFilePath(fsh, file)
 		//log.Println("Removing ", cachePath, err)
 		if err != nil {
 			return err
@@ -376,8 +375,9 @@ func RemoveCache(file string) error {
 	}
 }
 
-func specialGlob(path string) ([]string, error) {
-	files, err := filepath.Glob(path)
+func specialGlob(fsh *filesystem.FileSystemHandler, path string) ([]string, error) {
+	fshAbs := fsh.FileSystemAbstraction
+	files, err := fshAbs.Glob(path)
 	if err != nil {
 		return []string{}, err
 	}

+ 6 - 2
mod/filesystem/metadata/model.go

@@ -6,10 +6,14 @@ import (
 	"os"
 	"path/filepath"
 
+	"imuslab.com/arozos/mod/filesystem"
 	"imuslab.com/arozos/mod/filesystem/renderer"
 )
 
-func generateThumbnailForModel(cacheFolder string, file string, generateOnly bool) (string, error) {
+func generateThumbnailForModel(fsh *filesystem.FileSystemHandler, cacheFolder string, file string, generateOnly bool) (string, error) {
+	if fsh.RequireBuffer {
+		return "", nil
+	}
 	if !fileExists(file) {
 		//The user removed this file before the thumbnail is finished
 		return "", errors.New("Source not exists")
@@ -39,7 +43,7 @@ func generateThumbnailForModel(cacheFolder string, file string, generateOnly boo
 
 	if !generateOnly && fileExists(outputFile) {
 		//return the image as well
-		ctx, err := getImageAsBase64(outputFile)
+		ctx, err := getImageAsBase64(fsh, outputFile)
 		return ctx, err
 	} else if !fileExists(outputFile) {
 		return "", errors.New("Image generation failed")

+ 6 - 2
mod/filesystem/metadata/psd.go

@@ -10,9 +10,13 @@ import (
 	"github.com/nfnt/resize"
 	"github.com/oliamb/cutter"
 	_ "github.com/oov/psd"
+	"imuslab.com/arozos/mod/filesystem"
 )
 
-func generateThumbnailForPSD(cacheFolder string, file string, generateOnly bool) (string, error) {
+func generateThumbnailForPSD(fsh *filesystem.FileSystemHandler, cacheFolder string, file string, generateOnly bool) (string, error) {
+	if fsh.RequireBuffer {
+		return "", nil
+	}
 	if !fileExists(file) {
 		//The user removed this file before the thumbnail is finished
 		return "", errors.New("Source not exists")
@@ -67,7 +71,7 @@ func generateThumbnailForPSD(cacheFolder string, file string, generateOnly bool)
 
 	if !generateOnly && fileExists(outputFile) {
 		//return the image as well
-		ctx, err := getImageAsBase64(outputFile)
+		ctx, err := getImageAsBase64(fsh, outputFile)
 		return ctx, err
 	} else if !fileExists(outputFile) {
 		return "", errors.New("Image generation failed")

+ 8 - 3
mod/filesystem/metadata/video.go

@@ -12,10 +12,15 @@ import (
 
 	"github.com/oliamb/cutter"
 	"imuslab.com/arozos/mod/apt"
+	"imuslab.com/arozos/mod/filesystem"
 )
 
-func generateThumbnailForVideo(cacheFolder string, file string, generateOnly bool) (string, error) {
-	if !fileExists(file) {
+func generateThumbnailForVideo(fsh *filesystem.FileSystemHandler, cacheFolder string, file string, generateOnly bool) (string, error) {
+	if fsh.RequireBuffer {
+		return "", nil
+	}
+	fshAbs := fsh.FileSystemAbstraction
+	if !fshAbs.FileExists(file) {
 		//The user removed this file before the thumbnail is finished
 		return "", errors.New("Source not exists")
 	}
@@ -63,7 +68,7 @@ func generateThumbnailForVideo(cacheFolder string, file string, generateOnly boo
 		//Finished
 		if !generateOnly && fileExists(outputFile) {
 			//return the image as well
-			ctx, err := getImageAsBase64(outputFile)
+			ctx, err := getImageAsBase64(fsh, outputFile)
 			return ctx, err
 		} else if !fileExists(outputFile) {
 			return "", errors.New("Image generation failed")

+ 0 - 53
mod/filesystem/webdavClient/webdavFsAbstraction.go.disabled

@@ -1,53 +0,0 @@
-package webdavclient
-
-import (
-	"os"
-	"time"
-)
-
-type WebDAVFileSystemAbstraction struct {
-}
-
-func NewWebDAVFileSystemAbstraction() WebDAVFileSystemAbstraction {
-	return WebDAVFileSystemAbstraction{}
-}
-
-func (l WebDAVFileSystemAbstraction) Chmod(filename string, mode os.FileMode) error {
-	return os.Chmod(filename, mode)
-}
-func (l WebDAVFileSystemAbstraction) Chown(filename string, uid int, gid int) error {
-	return os.Chown(filename, uid, gid)
-}
-func (l WebDAVFileSystemAbstraction) Chtimes(filename string, atime time.Time, mtime time.Time) error {
-	return os.Chtimes(filename, atime, mtime)
-}
-func (l WebDAVFileSystemAbstraction) Create(filename string) (*os.File, error) {
-	return os.Create(filename)
-}
-func (l WebDAVFileSystemAbstraction) Mkdir(filename string, mode os.FileMode) error {
-	return os.Mkdir(filename, mode)
-}
-func (l WebDAVFileSystemAbstraction) MkdirAll(filename string, mode os.FileMode) error {
-	return os.MkdirAll(filename, mode)
-}
-func (l WebDAVFileSystemAbstraction) Name() string {
-	return ""
-}
-func (l WebDAVFileSystemAbstraction) Open(filename string) (*os.File, error) {
-	return os.Open(filename)
-}
-func (l WebDAVFileSystemAbstraction) OpenFile(filename string, flag int, perm os.FileMode) (*os.File, error) {
-	return os.OpenFile(filename, flag, perm)
-}
-func (l WebDAVFileSystemAbstraction) Remove(filename string) error {
-	return os.Remove(filename)
-}
-func (l WebDAVFileSystemAbstraction) RemoveAll(path string) error {
-	return os.RemoveAll(path)
-}
-func (l WebDAVFileSystemAbstraction) Rename(oldname, newname string) error {
-	return os.Rename(oldname, newname)
-}
-func (l WebDAVFileSystemAbstraction) Stat(filename string) (os.FileInfo, error) {
-	return os.Stat(filename)
-}

+ 6 - 5
mod/network/webdav/webdav.go

@@ -13,7 +13,6 @@ import (
 	"net/url"
 	"os"
 	"path"
-	"path/filepath"
 	"strings"
 	"time"
 )
@@ -540,10 +539,12 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status
 		}
 
 		//Arozos custom properties
-		if len(reqPath) > 1 && filepath.Base(reqPath)[:1] == "." {
-			//Hidden file. Do not show
-			return nil
-		}
+		/*
+			if len(reqPath) > 1 && filepath.Base(reqPath)[:1] == "." {
+				//Hidden file. Do not show
+				return nil
+			}
+		*/
 
 		var pstats []Propstat
 		if pf.Propname != nil {

+ 15 - 1
mod/share/share.go

@@ -173,7 +173,21 @@ func (s *Manager) HandleOPGServing(w http.ResponseWriter, r *http.Request, share
 	}
 
 	//Get thumbnail
-	cacheFileImagePath, err := metadata.GetCacheFilePath(shareEntry.FileRealPath)
+	ownerinfo, err := s.options.UserHandler.GetUserInfoFromUsername(shareEntry.Owner)
+	if err != nil {
+		fmt.Println("[share/opg] " + err.Error())
+		http.NotFound(w, r)
+		return
+	}
+	fsh, err := ownerinfo.GetFileSystemHandlerFromVirtualPath(shareEntry.FileVirtualPath)
+	if err != nil {
+		fmt.Println("[share/opg] " + err.Error())
+		http.NotFound(w, r)
+		return
+	}
+
+	rpath, _ := fsh.FileSystemAbstraction.VirtualPathToRealPath(shareEntry.FileVirtualPath, shareEntry.Owner)
+	cacheFileImagePath, err := metadata.GetCacheFilePath(fsh, rpath)
 	if err == nil {
 		//We got a thumbnail for this file. Render it as well
 		thumbnailFile, err := os.Open(cacheFileImagePath)

+ 11 - 19
storage.go

@@ -102,34 +102,22 @@ func LoadBaseStoragePool() error {
 
 	*/
 	webdh, err := fs.NewFileSystemHandler(fs.FileSystemOption{
-		Name:       "IXTW",
-		Uuid:       "ixtw",
-		Path:       "http://192.168.1.120:8082/webdav/tmp",
-		Access:     "readwrite",
-		Hierarchy:  "public",
-		Automount:  false,
-		Filesystem: "webdav",
-	})
-	if err != nil {
-		log.Println(err.Error())
-		return err
-	}
-	fsHandlers = append(fsHandlers, webdh)
-
-	webdh2, err := fs.NewFileSystemHandler(fs.FileSystemOption{
-		Name:       "CCNS",
-		Uuid:       "ccns",
-		Path:       "https://ccns.arozos.com:443/webdav/tmp",
+		Name:       "Loopback",
+		Uuid:       "loopback",
+		Path:       "http://192.168.1.214:8081/webdav/tmp",
 		Access:     "readwrite",
 		Hierarchy:  "public",
 		Automount:  false,
 		Filesystem: "webdav",
+		Username:   "TC",
+		Password:   "password",
 	})
 	if err != nil {
 		log.Println(err.Error())
 		return err
+	} else {
+		fsHandlers = append(fsHandlers, webdh)
 	}
-	fsHandlers = append(fsHandlers, webdh2)
 
 	//Load all the storage config from file
 	rawConfig, err := ioutil.ReadFile(*storage_config_file)
@@ -271,6 +259,10 @@ func GetFSHandlerSubpathFromVpath(vpath string) (*fs.FileSystemHandler, string,
 		return nil, "", errors.New("Unable to resolve requested path: " + err.Error())
 	}
 
+	if fsh == nil || fsh.FileSystemAbstraction == nil {
+		return nil, "", errors.New("Unable to resolve requested path: " + err.Error())
+	}
+
 	return fsh, subpath, nil
 }
 

+ 2 - 1
web/Music/functions/getMeta.js

@@ -23,6 +23,7 @@ if (requirelib("filelib") == true){
     dirname = dirname.join("/");
 
     //Scan nearby files
+    
     var nearbyFiles = filelib.aglob(dirname + "/*", "user") //aglob must be used here to prevent errors for non-unicode filename
     var audioFiles = [];
     var supportedFormats = [".mp3",".flac",".wav",".ogg",".aac",".webm",".mp4"];
@@ -33,7 +34,7 @@ if (requirelib("filelib") == true){
         ext = "." + ext;
         //Check if the file extension is in the supported extension list
         for (var k = 0; k < supportedFormats.length; k++){
-            if (filelib.isDir(nearbyFiles[i]) == false && supportedFormats[k] == ext){
+            if (nearbyFiles[i] != "" && filelib.isDir(nearbyFiles[i]) == false && supportedFormats[k] == ext){
                 var fileExt = ext.substr(1);
                 var fileName = thisFile.split("/").pop();
                 var fileSize = filelib.filesize(thisFile);