瀏覽代碼

Fixed File Manager remove share issue

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

+ 1 - 1
go.mod

@@ -23,7 +23,7 @@ require (
 	github.com/gorilla/sessions v1.2.1
 	github.com/gorilla/websocket v1.5.0
 	github.com/grandcat/zeroconf v1.0.0
-	github.com/hirochachacha/go-smb2 v1.1.0 // indirect
+	github.com/hirochachacha/go-smb2 v1.1.0
 	github.com/kevinburke/ssh_config v1.2.0 // indirect
 	github.com/klauspost/compress v1.15.4 // indirect
 	github.com/koron/go-ssdp v0.0.3

+ 0 - 2
go.sum

@@ -481,8 +481,6 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y
 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
-golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9 h1:NUzdAbFtCJSXU20AOXgeqaUwg8Ypg4MPYmL+d+rsB5c=
-golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c=
 golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=

+ 23 - 1
mod/filesystem/fsdef/fsdef.go

@@ -6,7 +6,29 @@ package fsdef
 	This package handle error related to file systems.
 	See comments below for usage.
 */
-import "errors"
+import (
+	"errors"
+	"io"
+	"os"
+)
+
+type File interface {
+	Chdir() error
+	Chmod(mode os.FileMode) error
+	Chown(uid, gid int) error
+	Close() error
+	Name() string
+	Read(b []byte) (n int, err error)
+	ReadAt(b []byte, off int64) (n int, err error)
+	ReadDir(n int) ([]os.DirEntry, error)
+	ReadFrom(r io.Reader) (n int64, err error)
+	Readdir(n int) ([]os.FileInfo, error)
+	Seek(offset int64, whence int) (ret int64, err error)
+	Stat() (os.FileInfo, error)
+	Truncate(size int64) error
+	Write(b []byte) (n int, err error)
+	WriteString(s string) (n int, err error)
+}
 
 var (
 	/*

+ 23 - 9
mod/share/share.go

@@ -966,13 +966,6 @@ func (s *Manager) HandleEditShare(w http.ResponseWriter, r *http.Request) {
 }
 
 func (s *Manager) HandleDeleteShare(w http.ResponseWriter, r *http.Request) {
-	//Get the vpath from paramters
-	uuid, err := mv(r, "uuid", true)
-	if err != nil {
-		sendErrorResponse(w, "Invalid uuid given")
-		return
-	}
-
 	//Get userinfo
 	userinfo, err := s.options.UserHandler.GetUserInfoFromRequest(w, r)
 	if err != nil {
@@ -980,6 +973,24 @@ func (s *Manager) HandleDeleteShare(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
+	//Get the vpath from paramters
+	uuid, err := mv(r, "uuid", true)
+	if err != nil {
+		//Try to get it from vpath
+		vpath, err := mv(r, "vpath", true)
+		if err != nil {
+			sendErrorResponse(w, "Invalid uuid or vpath given")
+			return
+		}
+
+		targetSa := s.GetShareObjectFromUserAndVpath(userinfo, vpath)
+		if targetSa == nil {
+			sendErrorResponse(w, "Invalid uuid or vpath given")
+			return
+		}
+		uuid = targetSa.UUID
+	}
+
 	//Delete the share setting
 	err = s.DeleteShareByUUID(userinfo, uuid)
 
@@ -1209,8 +1220,11 @@ func (s *Manager) ValidateAndClearShares() {
 		}
 		if !s.ShareIsValid(thisShareOption) {
 			//This share source file don't exists anymore. Remove it
-			s.options.ShareEntryTable.RemoveShareByPathHash(pathHash)
-			log.Println("*Share* Removing share to file: " + thisShareOption.FileRealPath + " as it no longer exists")
+			err = s.options.ShareEntryTable.RemoveShareByPathHash(pathHash)
+			if err != nil {
+				log.Println("[Share] Failed to remove share", err)
+			}
+			log.Println("[Share] Removing share to file: " + thisShareOption.FileRealPath + " as it no longer exists")
 		}
 		return true
 	})

+ 1 - 1
mod/share/shareEntry/shareEntry.go

@@ -221,7 +221,7 @@ func (s *ShareEntryTable) RemoveShareByPathHash(pathhash string) error {
 		s.FileToUrlMap.Delete(pathhash)
 		s.Database.Delete("share", shareUUID)
 	} else {
-		return errors.New("Share with given realpath not exists")
+		return errors.New("Share with given pathhash not exists. Given: " + pathhash)
 	}
 	return nil
 }

+ 1 - 1
web/SystemAO/file_system/file_explorer.html

@@ -3925,7 +3925,7 @@
                 $("#shareFileEmbedded").attr("src", "");
                 $.ajax({
                     url: "../../system/file_system/share/delete",
-                    data: {path: selectedFile},
+                    data: {vpath: selectedFile},
                     success: function(data){
                         console.log(data);
                         $("#qrcode").html(`<img src="img/private.png">`);

+ 7 - 7
web/SystemAO/file_system/file_share.html

@@ -204,7 +204,7 @@
                 }
 
             */
-            var sharCurrentEditingUUID = "";
+            var shareCurrentEditingUUID = "";
             var shareingFileData = {};
             var darkTheme = false;
             var initialized = false;
@@ -272,7 +272,7 @@
                             });
                             $.ajax({
                                 url: relpath + "../system/file_system/share/edit",
-                                data: {uuid: sharCurrentEditingUUID, mode: shareingFileData.shareMode},
+                                data: {uuid: shareCurrentEditingUUID, mode: shareingFileData.shareMode},
                                 success: function(data){
                                     if (data.error !== undefined){
                                         alert(data.error);
@@ -359,7 +359,7 @@
                         }else{
                             console.log(data);
                             updateShareLinkInfo(data.UUID);
-                            sharCurrentEditingUUID = data.UUID;
+                            shareCurrentEditingUUID = data.UUID;
                             $(".shareoption").each(function(){
                                 if ($(this)[0].value != data.Permission){
                                     $(this)[0].checked = false;
@@ -414,14 +414,14 @@
             }
 
             function removeSharing(){
-                if (sharCurrentEditingUUID == ""){
+                if (shareCurrentEditingUUID == ""){
                     return
                 }
 
                 //The target file to remove
                 $.ajax({
                     url: relpath + "../system/file_system/share/delete",
-                    data: {path: shareingFileData.filepath},
+                    data: {uuid: shareCurrentEditingUUID},
                     success: function(data){
                         if (data.error !== undefined){
                             alert(data.error);
@@ -488,7 +488,7 @@
 
                 $.ajax({
                     url: relpath + "../system/file_system/share/edit",
-                    data: {uuid: sharCurrentEditingUUID, mode: newPermission},
+                    data: {uuid: shareCurrentEditingUUID, mode: newPermission},
                     success: function(data){
                         if (data.error !== undefined){
                             alert(data.error);
@@ -511,7 +511,7 @@
                     port = "";
                 }
                 var shareURL = protocol + window.location.hostname + port + "/share/" + uuid;
-                sharCurrentEditingUUID = uuid;
+                shareCurrentEditingUUID = uuid;
                 fileSharingURL = shareURL;
                 new QRCode(document.getElementById("qrcode"), shareURL);
                 $("#sharelink").text(shareURL);