瀏覽代碼

Moved all cache, trash and versioning to metadata folder

Toby Chui 3 年之前
父節點
當前提交
a40b38cf4f

二進制
documents/publication/icon.png


+ 1 - 0
documents/setup-scripts/userconf.txt

@@ -0,0 +1 @@
+pi:$6$/4.VdYgDm7RJ0qM1$FwXCeQgDKkqrOU3RIRuDSKpauAbBvP11msq9X58c8Que2l1Dwq3vdJMgiZlQSbEXGaY5esVHGBNbCxKLVNqZW1

+ 1 - 1
documents/systemd service config example.txt

@@ -1,5 +1,5 @@
 [Unit]
-Description=ArozOS Cloud Service
+Description=arozos service
 After=systemd-networkd-wait-online.service
 Wants=systemd-networkd-wait-online.service
 

+ 7 - 16
file_system.go

@@ -1801,9 +1801,9 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 				metadata.RemoveCache(rsrcFile)
 
 				//Clear the cache folder if there is no files inside
-				fc, _ := filepath.Glob(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.cache/*")
+				fc, _ := filepath.Glob(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.metadata/.cache/*")
 				if len(fc) == 0 {
-					os.Remove(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.cache/")
+					os.Remove(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.metadata/.cache/")
 				}
 
 				os.RemoveAll(rsrcFile)
@@ -1818,16 +1818,6 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 				}
 
 				//Check if the upload target is read only.
-				//Updates 20 Jan 2021: Replace with CanWrite handler
-				/*
-					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
@@ -1837,21 +1827,22 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 				metadata.RemoveCache(rsrcFile)
 
 				//Clear the cache folder if there is no files inside
-				fc, _ := filepath.Glob(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.cache/*")
+				fc, _ := filepath.Glob(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.metadata/.cache/*")
 				if len(fc) == 0 {
-					os.Remove(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.cache/")
+					os.Remove(filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.metadata/.cache/")
 				}
 
 				//Create a trash directory for this folder
-				trashDir := filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.trash/"
+				trashDir := filepath.ToSlash(filepath.Dir(rsrcFile)) + "/.metadata/.trash/"
 				os.MkdirAll(trashDir, 0755)
+				hidden.HideFile(filepath.Dir(trashDir))
 				hidden.HideFile(trashDir)
 				os.Rename(rsrcFile, trashDir+filepath.Base(rsrcFile)+"."+Int64ToString(GetUnixTime()))
 			} else if operation == "unzip" {
 				//Unzip the file to destination
 
 				//Check if the user can write to the target dest file
-				if userinfo.CanWrite(string(vdestFile)) == false {
+				if !userinfo.CanWrite(string(vdestFile)) {
 					sendErrorResponse(w, "Access Denied")
 					return
 				}

+ 1 - 2
go.mod

@@ -10,8 +10,6 @@ require (
 	github.com/boltdb/bolt v1.3.1
 	github.com/dhowden/tag v0.0.0-20201120070457-d52dcb253c63
 	github.com/disintegration/imaging v1.6.2
-	github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac
-	github.com/emersion/go-smtp v0.15.0
 	github.com/emirpasic/gods v1.18.1 // indirect
 	github.com/fclairamb/ftpserverlib v0.18.0
 	github.com/fogleman/fauxgl v0.0.0-20200818143847-27cddc103802
@@ -51,4 +49,5 @@ require (
 	golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a // indirect
 	golang.org/x/tools v0.1.10 // indirect
 	gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
+	gopkg.in/yaml.v3 v3.0.1 // indirect
 )

+ 2 - 6
go.sum

@@ -116,11 +116,6 @@ github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44am
 github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 h1:iFaUwBSo5Svw6L7HYpRu/0lE3e0BaElwnNO1qkNQxBY=
 github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj60/X5sZFNxpG4HBPDHVqxNm4DfnCKgrbZOT+s=
 github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
-github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
-github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac h1:tn/OQ2PmwQ0XFVgAHfjlLyqMewry25Rz7jWnVoh4Ggs=
-github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
-github.com/emersion/go-smtp v0.15.0 h1:3+hMGMGrqP/lqd7qoxZc1hTU8LY8gHV9RFGWlqSDmP8=
-github.com/emersion/go-smtp v0.15.0/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ=
 github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
 github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
 github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
@@ -942,8 +937,9 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

+ 11 - 9
mod/filesystem/localversion/localversion.go

@@ -42,7 +42,7 @@ func GetFileVersionData(realFilepath string) (*VersionList, error) {
 		Versions:      []*FileSnapshot{},
 	}
 	//Example folder structure: ./.localver/{date_time}/{file}
-	expectedVersionFiles := filepath.Join(filepath.Dir(realFilepath), ".localver", "*", filepath.Base(realFilepath))
+	expectedVersionFiles := filepath.Join(filepath.Dir(realFilepath), ".metadata/.localver", "*", filepath.Base(realFilepath))
 	versions, err := filepath.Glob(filepath.ToSlash(expectedVersionFiles))
 	if err != nil {
 		return &versionList, err
@@ -61,7 +61,7 @@ func GetFileVersionData(realFilepath string) (*VersionList, error) {
 			ModTime:       mtime,
 			OverwriteTime: overwriteDisplayTime,
 			Filesize:      filesystem.GetFileSize(version),
-			Relpath:       ".localver/" + historyID + "/" + filepath.Base(version),
+			Relpath:       ".metadata/.localver/" + historyID + "/" + filepath.Base(version),
 		})
 	}
 
@@ -69,7 +69,7 @@ func GetFileVersionData(realFilepath string) (*VersionList, error) {
 }
 
 func RestoreFileHistory(originalFilepath string, histroyID string) error {
-	expectedVersionFile := filepath.Join(filepath.Dir(originalFilepath), ".localver", filepath.Base(histroyID), filepath.Base(originalFilepath))
+	expectedVersionFile := filepath.Join(filepath.Dir(originalFilepath), ".metadata/.localver", filepath.Base(histroyID), filepath.Base(originalFilepath))
 	if !filesystem.FileExists(expectedVersionFile) {
 		return errors.New("File version not exists")
 	}
@@ -91,7 +91,7 @@ func RestoreFileHistory(originalFilepath string, histroyID string) error {
 	os.Remove(originalFilepath + ".backup")
 
 	//Delete all history versions that is after the restored versions
-	expectedVersionFiles := filepath.Join(filepath.Dir(originalFilepath), ".localver", "*", filepath.Base(originalFilepath))
+	expectedVersionFiles := filepath.Join(filepath.Dir(originalFilepath), ".metadata/.localver", "*", filepath.Base(originalFilepath))
 	versions, err := filepath.Glob(filepath.ToSlash(expectedVersionFiles))
 	if err != nil {
 		return err
@@ -119,7 +119,7 @@ func RestoreFileHistory(originalFilepath string, histroyID string) error {
 }
 
 func RemoveFileHistory(originalFilepath string, histroyID string) error {
-	expectedVersionFile := filepath.Join(filepath.Dir(originalFilepath), ".localver", filepath.Base(histroyID), filepath.Base(originalFilepath))
+	expectedVersionFile := filepath.Join(filepath.Dir(originalFilepath), ".metadata/.localver", filepath.Base(histroyID), filepath.Base(originalFilepath))
 	if !filesystem.FileExists(expectedVersionFile) {
 		return errors.New("File version not exists")
 	}
@@ -128,7 +128,7 @@ func RemoveFileHistory(originalFilepath string, histroyID string) error {
 }
 
 func RemoveAllRelatedFileHistory(originalFilepath string) error {
-	expectedVersionFiles, err := filepath.Glob(filepath.Join(filepath.Dir(originalFilepath), ".localver", "*", filepath.Base(originalFilepath)))
+	expectedVersionFiles, err := filepath.Glob(filepath.Join(filepath.Dir(originalFilepath), ".metadata/.localver", "*", filepath.Base(originalFilepath)))
 	if err != nil {
 		return err
 	}
@@ -144,9 +144,11 @@ func CreateFileSnapshot(realFilepath string) error {
 	}
 	//Create the snapshot folder for this file
 	snapshotID := time.Now().Format("2006-01-02_15-04-05")
-	expectedSnapshotFolder := filepath.Join(filepath.Dir(realFilepath), ".localver", snapshotID)
-	os.MkdirAll(expectedSnapshotFolder, 0775)
-
+	expectedSnapshotFolder := filepath.Join(filepath.Dir(realFilepath), ".metadata/.localver", snapshotID)
+	err := os.MkdirAll(expectedSnapshotFolder, 0775)
+	if err != nil {
+		return err
+	}
 	//Copy the target file to snapshot dir
 	targetVersionFilepath := filepath.Join(expectedSnapshotFolder, filepath.Base(realFilepath))
 	return filesystem.BasicFileCopy(realFilepath, targetVersionFilepath)

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

@@ -21,7 +21,7 @@ import (
 
 func generateThumbnailForFolder(cacheFolder string, file string, generateOnly bool) (string, error) {
 	//Check if this folder has cache image folder
-	cacheFolderInsideThisFolder := filepath.Join(file, "/.cache")
+	cacheFolderInsideThisFolder := filepath.Join(file, "/.metadata/.cache")
 	if !fileExists(cacheFolderInsideThisFolder) {
 		//This folder do not have a cache folder
 		return "", errors.New("No previewable files")

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

@@ -52,9 +52,9 @@ func (rh *RenderHandler) BuildCacheForFolder(path string) error {
 	}
 
 	//Check if the cache folder has file. If not, remove it
-	cachedFiles, _ := filepath.Glob(filepath.ToSlash(filepath.Clean(path)) + "/.cache/*")
+	cachedFiles, _ := filepath.Glob(filepath.ToSlash(filepath.Join(filepath.Clean(path), "/.metadata/.cache/*")))
 	if len(cachedFiles) == 0 {
-		os.RemoveAll(filepath.ToSlash(filepath.Clean(path)) + "/.cache/")
+		os.RemoveAll(filepath.ToSlash(filepath.Join(filepath.Clean(path), "/.metadata/.cache/")) + "/")
 	}
 	return nil
 }
@@ -72,9 +72,9 @@ 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) {
 	//Create a cache folder
-	cacheFolder := filepath.ToSlash(filepath.Clean(filepath.Dir(file))) + "/.cache/"
-	os.Mkdir(cacheFolder, 0755)
-
+	cacheFolder := filepath.ToSlash(filepath.Join(filepath.Clean(filepath.Dir(file)), "/.metadata/.cache/") + "/")
+	os.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
@@ -338,14 +338,14 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
 
 //Check if the cache for a file exists
 func CacheExists(file string) bool {
-	cacheFolder := filepath.ToSlash(filepath.Clean(filepath.Dir(file))) + "/.cache/"
+	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")
 }
 
 //Get cache path for this file, given realpath
 func GetCacheFilePath(file string) (string, error) {
 	if CacheExists(file) {
-		cacheFolder := filepath.ToSlash(filepath.Clean(filepath.Dir(file))) + "/.cache/"
+		cacheFolder := filepath.ToSlash(filepath.Join(filepath.Clean(filepath.Dir(file)), "/.metadata/.cache/") + "/")
 		if fileExists(cacheFolder + filepath.Base(file) + ".jpg") {
 			return cacheFolder + filepath.Base(file) + ".jpg", nil
 		} else if fileExists(cacheFolder + filepath.Base(file) + ".png") {

+ 4 - 4
mod/storage/ftp/aofs.go

@@ -167,8 +167,8 @@ func (a aofs) Remove(name string) error {
 	}
 
 	log.Println(a.userinfo.Username + " removed " + rewritePath + " via FTP endpoint")
-	os.MkdirAll(filepath.Dir(rewritePath)+"/.trash/", 0755)
-	os.Rename(rewritePath, filepath.Dir(rewritePath)+"/.trash/"+filepath.Base(rewritePath)+"."+strconv.Itoa(int(time.Now().Unix())))
+	os.MkdirAll(filepath.Dir(rewritePath)+"/.metadata/.trash/", 0755)
+	os.Rename(rewritePath, filepath.Dir(rewritePath)+"/.metadata/.trash/"+filepath.Base(rewritePath)+"."+strconv.Itoa(int(time.Now().Unix())))
 	return nil
 }
 
@@ -185,8 +185,8 @@ func (a aofs) RemoveAll(path string) error {
 	if !a.checkAllowAccess(rewritePath, "write") {
 		return errors.New("Permission Denied")
 	}
-	os.MkdirAll(filepath.Dir(rewritePath)+"/.trash/", 0755)
-	os.Rename(rewritePath, filepath.Dir(rewritePath)+"/.trash/"+filepath.Base(rewritePath)+"."+strconv.Itoa(int(time.Now().Unix())))
+	os.MkdirAll(filepath.Dir(rewritePath)+"/.metadata/.trash/", 0755)
+	os.Rename(rewritePath, filepath.Dir(rewritePath)+"/.metadata/.trash/"+filepath.Base(rewritePath)+"."+strconv.Itoa(int(time.Now().Unix())))
 	return nil
 }
 

+ 4 - 1
notification.go

@@ -17,7 +17,10 @@ func notificationInit() {
 
 	//Register the notification agents
 
-	//SMTP Mail Sender
+	/*
+		SMTP Notification Agent
+		For handling notification sending via Mail
+	*/
 
 	//Load username and their email from authAgent
 	userEmailmap := map[string]string{}

+ 8 - 0
web/SystemAO/utilities/audio.html

@@ -25,6 +25,14 @@ body {
 	background: rgba(255,255,255,1);
 }
 
+#songname{
+	clear: both;
+    display: inline-block;
+    overflow: hidden;
+    white-space: nowrap;
+	text-overflow: ellipsis;
+}
+
 </style>
 </head>
 <body>