Prechádzať zdrojové kódy

Fixing another legacy path + path problem

TC pushbot 5 4 rokov pred
rodič
commit
aee766eb6c
3 zmenil súbory, kde vykonal 57 pridanie a 26 odobranie
  1. 3 3
      desktop.go
  2. 28 20
      mod/share/share.go
  3. 26 3
      system/share/downloadPageFolder.html

+ 3 - 3
desktop.go

@@ -75,7 +75,7 @@ func desktop_initUserFolderStructure(username string) {
 		log.Println(err)
 	}
 
-	if !fileExists(homedir + "Desktop") {
+	if !fileExists(filepath.Join(homedir, "Desktop")) {
 		//Desktop directory not exists. Create one and copy a template desktop
 		os.MkdirAll(homedir+"Desktop", 0755)
 		templateFolder := "./system/desktop/template/"
@@ -301,7 +301,7 @@ func setDesktopLocationFromPath(filename string, username string, x int, y int)
 	//You cannot directly set path of others people's deskop. Hence, fullpath needed to be parsed from auth username
 	userinfo, _ := userHandler.GetUserInfoFromUsername(username)
 	desktoppath, _ := userinfo.VirtualPathToRealPath("user:/Desktop/")
-	path := desktoppath + filename
+	path := filepath.Join(desktoppath, filename)
 	type iconLocation struct {
 		X int
 		Y int
@@ -625,7 +625,7 @@ func desktop_shortcutHandler(w http.ResponseWriter, r *http.Request) {
 
 	//Check if there are desktop icon. If yes, override icon on module
 	if shortcutType == "module" && fileExists("./web/"+filepath.ToSlash(filepath.Dir(shortcutIcon)+"/desktop_icon.png")) {
-		shortcutIcon = filepath.ToSlash(filepath.Dir(shortcutIcon) + "/desktop_icon.png")
+		shortcutIcon = filepath.ToSlash(filepath.Join(filepath.Dir(shortcutIcon), "/desktop_icon.png"))
 	}
 
 	shortcutText = strings.ReplaceAll(shortcutText, "/", "")

+ 28 - 20
mod/share/share.go

@@ -103,6 +103,8 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
 		directServe = true
 	}
 
+	relpath, _ := mv(r, "rel", false)
+
 	//Check if id exists
 	val, ok := s.urlToFileMap.Load(id)
 	if ok {
@@ -242,29 +244,35 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
 				IsDir    bool
 			}
 			if directDownload == true {
-				//Download this folder as zip
-				//Build the filelist to download
+				if relpath != "" {
+					//User specified a specific file within the directory. Escape the relpath
+					log.Println(shareOption.FileRealPath, relpath)
+					sendOK(w)
+				} else {
+					//Download this folder as zip
+					//Build the filelist to download
 
-				//Create a zip using ArOZ Zipper, tmp zip files are located under tmp/share-cache/*.zip
-				tmpFolder := s.options.TmpFolder
-				tmpFolder = filepath.Join(tmpFolder, "share-cache")
-				os.MkdirAll(tmpFolder, 0755)
-				targetZipFilename := filepath.Join(tmpFolder, filepath.Base(shareOption.FileRealPath)) + ".zip"
+					//Create a zip using ArOZ Zipper, tmp zip files are located under tmp/share-cache/*.zip
+					tmpFolder := s.options.TmpFolder
+					tmpFolder = filepath.Join(tmpFolder, "share-cache")
+					os.MkdirAll(tmpFolder, 0755)
+					targetZipFilename := filepath.Join(tmpFolder, filepath.Base(shareOption.FileRealPath)) + ".zip"
 
-				//Build a filelist
-				err := filesystem.ArozZipFile([]string{shareOption.FileRealPath}, targetZipFilename, false)
-				if err != nil {
-					//Failed to create zip file
-					w.WriteHeader(http.StatusInternalServerError)
-					w.Write([]byte("500 - Internal Server Error: Zip file creation failed"))
-					log.Println("Failed to create zip file for share download: " + err.Error())
-					return
-				}
+					//Build a filelist
+					err := filesystem.ArozZipFile([]string{shareOption.FileRealPath}, targetZipFilename, false)
+					if err != nil {
+						//Failed to create zip file
+						w.WriteHeader(http.StatusInternalServerError)
+						w.Write([]byte("500 - Internal Server Error: Zip file creation failed"))
+						log.Println("Failed to create zip file for share download: " + err.Error())
+						return
+					}
 
-				//Serve thje zip file
-				w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+strings.ReplaceAll(url.QueryEscape(filepath.Base(shareOption.FileRealPath)), "+", "%20")+".zip")
-				w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
-				http.ServeFile(w, r, targetZipFilename)
+					//Serve thje zip file
+					w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+strings.ReplaceAll(url.QueryEscape(filepath.Base(shareOption.FileRealPath)), "+", "%20")+".zip")
+					w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
+					http.ServeFile(w, r, targetZipFilename)
+				}
 
 			} else {
 				//Show download page. Do not allow serving

+ 26 - 3
system/share/downloadPageFolder.html

@@ -35,6 +35,19 @@
         .fileobject:hover{
           background-color: #f5f5f5;
         }
+
+        .fileobject.active{
+          background-color: #f5f5f5ee;
+        }
+
+        .noselect{
+          -webkit-touch-callout: none; /* iOS Safari */
+          -webkit-user-select: none; /* Safari */
+          -khtml-user-select: none; /* Konqueror HTML */
+          -moz-user-select: none; /* Old versions of Firefox */
+          -ms-user-select: none; /* Internet Explorer/Edge */
+          user-select: none;
+        }
     </style>
     </head>
     <body>
@@ -102,6 +115,7 @@
     <script>
       var treeFileList = {{treelist}};
       var currentViewingRoot = ".";
+      var selectedFile = null;
       renderFileList(treeFileList["."]);
 
       console.log(treeFileList);
@@ -109,7 +123,7 @@
       function renderFileList(filelist){
         $("#folderList").html("");
         if (currentViewingRoot != "."){
-          $("#folderList").append(`<tr class="fileobject" ondblclick="event.preventDefault(); parentdir();">
+          $("#folderList").append(`<tr class="fileobject noselect" ondblclick="event.preventDefault(); parentdir();">
               <td style="padding-left: 8px;" colspan="3" > ↩ Back</td>
             </tr>`);
           
@@ -124,7 +138,7 @@
           }else{
             displayName = "📄 " + file.Filename;
           }
-          $("#folderList").append(`<tr class="fileobject" filename="${file.Filename}" relpath="${file.RelPath}" type="${filetype.toLocaleLowerCase()}" ondblclick="event.preventDefault(); openThis(this);">
+          $("#folderList").append(`<tr class="fileobject noselect" onclick="highlightThis(this);" filename="${file.Filename}" relpath="${file.RelPath}" type="${filetype.toLocaleLowerCase()}" ondblclick="event.preventDefault(); openThis(this);">
               <td style="padding-left: 8px;">${displayName}</td>
               <td>${filetype}</td>
               <td>${file.Filesize}</td>
@@ -177,7 +191,7 @@
           
         }else{
           //File. Download it
-
+          
         }
       }
 
@@ -188,6 +202,15 @@
         })
       }
 
+      function highlightThis(object){
+          $(".fileobject.active").removeClass("active");
+          $(object).addClass("active");
+          $("#activeFilename").text(" (" + $(object).attr("filename") +")");
+
+          //Update the properties values
+          selectedFile = $(object);
+      }
+
       $(window).on("resize", function(){
         resizeDOMElement();
       })