浏览代码

Fixed desktop account switch windows presists and large file scanner bug

Toby Chui 1 年之前
父节点
当前提交
795e6e3c26
共有 5 个文件被更改,包括 240 次插入249 次删除
  1. 11 19
      mod/disk/sortfile/sortfile.go
  2. 98 91
      mod/user/quota.go
  3. 124 139
      web/SystemAO/disk/space/finder.html
  4. 1 0
      web/SystemAO/info/gomod-license.csv
  5. 6 0
      web/desktop.system

+ 11 - 19
mod/disk/sortfile/sortfile.go

@@ -10,6 +10,7 @@ import (
 	"strconv"
 
 	"imuslab.com/arozos/mod/filesystem"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 	user "imuslab.com/arozos/mod/user"
 	"imuslab.com/arozos/mod/utils"
 )
@@ -50,7 +51,6 @@ func (s *LargeFileScanner) HandleLargeFileList(w http.ResponseWriter, r *http.Re
 		Filename string
 		Filepath string
 		Size     int64
-		IsOwner  bool
 
 		realpath string
 		thisfsh  *filesystem.FileSystemHandler
@@ -58,7 +58,16 @@ func (s *LargeFileScanner) HandleLargeFileList(w http.ResponseWriter, r *http.Re
 	//Walk all filesystem handlers and buffer all files and their sizes
 	fileList := []*FileObject{}
 	for _, fsh := range fsHandlers {
-		fsh.FileSystemAbstraction.Walk(fsh.Path, func(path string, info os.FileInfo, err error) error {
+		if fsh.IsNetworkDrive() {
+			//Skip network drive
+			continue
+		}
+
+		walkRoot := fsh.Path
+		if fsh.Hierarchy == "user" {
+			walkRoot = arozfs.ToSlash(filepath.Join(fsh.Path, "users", userinfo.Username))
+		}
+		fsh.FileSystemAbstraction.Walk(walkRoot, func(path string, info os.FileInfo, err error) error {
 			if info == nil || err != nil {
 				//Disk IO Error
 				return errors.New("Disk IO Error: " + err.Error())
@@ -77,19 +86,11 @@ func (s *LargeFileScanner) HandleLargeFileList(w http.ResponseWriter, r *http.Re
 					realpath: path,
 					thisfsh:  fsh,
 					Size:     info.Size(),
-					IsOwner:  false,
 				})
 			}
 
 			return nil
 		})
-
-		/*
-			if err != nil {
-				sendErrorResponse(w, "Failed to scan emulated storage device: "+fsh.Name)
-				return
-			}
-		*/
 	}
 
 	//Sort the fileList
@@ -102,15 +103,6 @@ func (s *LargeFileScanner) HandleLargeFileList(w http.ResponseWriter, r *http.Re
 		limitInt = len(fileList)
 	}
 
-	//Only check ownership of those requested
-	for _, file := range fileList[:limitInt] {
-		if userinfo.IsOwnerOfFile(file.thisfsh, file.Filepath) {
-			file.IsOwner = true
-		} else {
-			file.IsOwner = false
-		}
-	}
-
 	//Format the results and return
 	jsonString, _ := json.Marshal(fileList[:limitInt])
 	utils.SendJSONResponse(w, string(jsonString))

+ 98 - 91
mod/user/quota.go

@@ -1,91 +1,98 @@
-package user
-
-import (
-	//"path/filepath"
-	//"log"
-
-	fs "imuslab.com/arozos/mod/filesystem"
-)
-
-/*
-	Quota Handler
-	author: tobychui
-
-	This module handle the user storage quota and its related functions
-
-*/
-
-//Return the user quota information, returning used / total
-func (u *User) HaveSpaceFor(fsh *fs.FileSystemHandler, vpath string) bool {
-	realpath, err := fsh.FileSystemAbstraction.VirtualPathToRealPath(vpath, u.Username)
-	if err != nil {
-		return false
-	}
-	if u.StorageQuota.HaveSpace(fsh.FileSystemAbstraction.GetFileSize(realpath)) {
-		return true
-	} else {
-		return false
-	}
-}
-
-func (u *User) SetOwnerOfFile(fsh *fs.FileSystemHandler, vpath string) error {
-	rpath, err := fsh.FileSystemAbstraction.VirtualPathToRealPath(vpath, u.Username)
-	if err != nil {
-		return err
-	}
-	//Check if it is user structured. If yes, add the filesize to user's quota
-	if fsh.Hierarchy == "user" {
-		//log.Println("Setting user ownership on: " + realpath)
-		u.StorageQuota.AllocateSpace(fsh.FileSystemAbstraction.GetFileSize(rpath))
-	}
-
-	//Add to the fshandler database of this file owner
-	err = fsh.CreateFileRecord(rpath, u.Username)
-	return err
-}
-
-func (u *User) RemoveOwnershipFromFile(fsh *fs.FileSystemHandler, vpath string) error {
-	realpath, err := fsh.FileSystemAbstraction.VirtualPathToRealPath(vpath, u.Username)
-	if err != nil {
-		return err
-	}
-
-	//Check if it is user structured. If yes, add the filesize to user's quota
-	if fsh.Hierarchy == "user" {
-		//log.Println("Removing user ownership on: " + realpath)
-		u.StorageQuota.ReclaimSpace(fsh.FileSystemAbstraction.GetFileSize(realpath))
-	}
-
-	err = fsh.DeleteFileRecord(realpath)
-	return err
-}
-
-func (u *User) IsOwnerOfFile(fsh *fs.FileSystemHandler, vpath string) bool {
-	owner := u.GetFileOwner(fsh, vpath)
-	if owner == u.Username {
-		//This file is owned by this user
-		return true
-	} else {
-		return false
-	}
-}
-
-func (u *User) GetFileOwner(fsh *fs.FileSystemHandler, vpath string) string {
-	realpath, err := fsh.FileSystemAbstraction.VirtualPathToRealPath(vpath, u.Username)
-	if err != nil {
-		return ""
-	}
-
-	if fsh.UUID == "user" {
-		//This file is inside user's root. It must be this user's file
-		return u.Username
-	}
-
-	owner, err := fsh.GetFileRecord(realpath)
-	if err != nil {
-		//Error occured. Either this file is not tracked or this file has no owner
-		return ""
-	}
-
-	return owner
-}
+package user
+
+import (
+	//"path/filepath"
+	//"log"
+
+	"fmt"
+
+	fs "imuslab.com/arozos/mod/filesystem"
+)
+
+/*
+	Quota Handler
+	author: tobychui
+
+	This module handle the user storage quota and its related functions
+
+*/
+
+// Return the user quota information, returning used / total
+func (u *User) HaveSpaceFor(fsh *fs.FileSystemHandler, vpath string) bool {
+	realpath, err := fsh.FileSystemAbstraction.VirtualPathToRealPath(vpath, u.Username)
+	if err != nil {
+		return false
+	}
+	if u.StorageQuota.HaveSpace(fsh.FileSystemAbstraction.GetFileSize(realpath)) {
+		return true
+	} else {
+		return false
+	}
+}
+
+func (u *User) SetOwnerOfFile(fsh *fs.FileSystemHandler, vpath string) error {
+	rpath, err := fsh.FileSystemAbstraction.VirtualPathToRealPath(vpath, u.Username)
+	if err != nil {
+		return err
+	}
+	//Check if it is user structured. If yes, add the filesize to user's quota
+	if fsh.Hierarchy == "user" {
+		//log.Println("Setting user ownership on: " + realpath)
+		u.StorageQuota.AllocateSpace(fsh.FileSystemAbstraction.GetFileSize(rpath))
+	}
+
+	//Add to the fshandler database of this file owner
+	err = fsh.CreateFileRecord(rpath, u.Username)
+	return err
+}
+
+func (u *User) RemoveOwnershipFromFile(fsh *fs.FileSystemHandler, vpath string) error {
+	realpath, err := fsh.FileSystemAbstraction.VirtualPathToRealPath(vpath, u.Username)
+	if err != nil {
+		return err
+	}
+
+	//Check if it is user structured. If yes, add the filesize to user's quota
+	if fsh.Hierarchy == "user" {
+		//log.Println("Removing user ownership on: " + realpath)
+		u.StorageQuota.ReclaimSpace(fsh.FileSystemAbstraction.GetFileSize(realpath))
+	}
+
+	err = fsh.DeleteFileRecord(realpath)
+	return err
+}
+
+func (u *User) IsOwnerOfFile(fsh *fs.FileSystemHandler, vpath string) bool {
+	owner := u.GetFileOwner(fsh, vpath)
+	if owner == u.Username {
+		//This file is owned by this user
+		return true
+	} else {
+		return false
+	}
+}
+
+func (u *User) GetFileOwner(fsh *fs.FileSystemHandler, vpath string) string {
+	realpath, err := fsh.FileSystemAbstraction.VirtualPathToRealPath(vpath, u.Username)
+	if err != nil {
+		return ""
+	}
+
+	if fsh.Hierarchy == "user" {
+		fmt.Println(realpath, vpath)
+		return ""
+	}
+
+	if fsh.UUID == "user" {
+		//This file is inside user's root. It must be this user's file
+		return u.Username
+	}
+
+	owner, err := fsh.GetFileRecord(realpath)
+	if err != nil {
+		//Error occured. Either this file is not tracked or this file has no owner
+		return ""
+	}
+
+	return owner
+}

+ 124 - 139
web/SystemAO/disk/space/finder.html

@@ -1,140 +1,125 @@
-<html>
-    <head>
-        <title>Space Finder</title>
-        <meta charset="UTF-8">
-        <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
-        <link rel="stylesheet" href="../../../script/semantic/semantic.min.css">
-        <script type="text/javascript" src="../../../script/jquery.min.js"></script>
-        <script type="text/javascript" src="../../../script/semantic/semantic.min.js"></script>
-        <script type="text/javascript" src="../../../script/ao_module.js"></script>
-        <style>
-           .owner.header{
-               color: #346eeb !important;
-           }
-
-           .owner.section{
-               color: #1d51c2 !important;
-           }
-
-           i.owner{
-            color: #346eeb !important;
-           }
-        </style>
-    </head>
-    <body>
-        <div class="ui container">
-            <p>Reclaim storage space by removing large files (Files owned by you will be in blue)</p>
-            <div class="ui small buttons">
-                <button class="ui primary basic button" onclick="initFileList(20);">20 Results (Fast)</button>
-                <button class="ui secondary basic button" onclick="initFileList(50);">50 Results</button>
-                <button class="ui secondary basic button" onclick="initFileList(100);">100 Results</button>
-                <button class="ui red basic button" onclick="initFileList(300);">300 Results (Slow)</button>
-            </div>
-            <div class="ui divider"></div>
-            <div id="filelist" class="ui list">
-                <div class="item">
-                    <div class="content">
-                        <div class="header"><i class="loading spinner icon"></i> Loading...</div>
-                        <div class="description">
-                            <div class="ui breadcrumb" style="margin-top:8px;">
-                                <div class="active section">Scanning Local Filesystem. This will take a while.</div>
-                            </div>
-                        </div>
-                    </div>
-                </div>
-            </div>
-        </div>
-       <br><br><br>
-            
-        </div>
-        <script>
-            initFileList();
-            function initFileList(number=20){
-                $("#filelist").html(`<div class="item">
-                    <div class="content">
-                        <div class="header"><i class="loading spinner icon"></i> Loading...</div>
-                        <div class="description">
-                            <div class="ui breadcrumb" style="margin-top:8px;">
-                                <div class="active section">Scanning Local Filesystem. This will take a while.</div>
-                            </div>
-                        </div>
-                    </div>
-                </div>`);
-                $.get("../../system/disk/space/largeFiles?number=" + number, function(data){
-                    $("#filelist").html("");
-                    data.forEach(file => {
-                        var filepath = file.Filepath.split("/");
-                        filepath.pop();
-                        filepath = filepath.join("/");
-
-                        var colorClass = "";
-                        if (file.IsOwner == true){
-                            colorClass = "owner"
-                        }
-                        $("#filelist").append(`<div class="item">
-                            <i class="file icon ${colorClass}"></i>
-                            <div class="content">
-                                <div class="header ${colorClass}">${file.Filename} (${bytesToSize(file.Size)})</div>
-                                <div class="description">
-                                    <div class="ui breadcrumb">
-                                        <div class="active section ${colorClass}">${filepath}/</div>
-                                        <div class="divider"> ( </div>
-                                        <a class="section" filepath="${filepath}" onclick="openFileLocation(this);">Open File Location</a>
-                                        <div class="divider"> / </div>
-                                        <a class="section" filepath="${file.Filepath}" onclick="deleteThisFile(this);">Delete</a>
-                                        <div class="divider"> ) </div>
-                                    </div>
-                                </div>
-                            </div>
-                        </div>`);
-                    });
-                });
-            }
-
-            function openFileLocation(object){
-                var filepath = $(object).attr("filepath");
-                ao_module_openPath(filepath);
-            }
-
-            function deleteThisFile(object){
-                var filepath = $(object).attr("filepath");
-                var filename = filepath.split("/").pop();
-                if (confirm("Confirm remove: " + filename + " ?")){
-                    //Request file system api to remove the file
-                    requestCSRFToken(function(token){
-                        $.ajax({
-                            url: "../../system/file_system/fileOpr",
-                            data: {opr: "delete", src: JSON.stringify([filepath]), csrft: token},
-                            success: function(data){
-                                if (data.error !== undefined){
-                                    alert(data.error);
-                                }else{
-                                    //DONE
-                                    initFileList();
-                                }   
-                            }
-
-                        });
-                    });
-                }
-            }
-
-            function requestCSRFToken(callback){
-                $.ajax({
-                    url: "../../system/csrf/new",
-                    success: function(token){
-                        callback(token);
-                    }
-                })
-            }
-
-            function bytesToSize(bytes) {
-                var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
-                if (bytes == 0) return '0 Byte';
-                var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
-                return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i];
-            }
-         
-        </script>
-    </body>
+<html>
+    <head>
+        <title>Space Finder</title>
+        <meta charset="UTF-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
+        <link rel="stylesheet" href="../../../script/semantic/semantic.min.css">
+        <script type="text/javascript" src="../../../script/jquery.min.js"></script>
+        <script type="text/javascript" src="../../../script/semantic/semantic.min.js"></script>
+        <script type="text/javascript" src="../../../script/ao_module.js"></script>
+        <style>
+
+        </style>
+    </head>
+    <body>
+        <div class="ui container">
+            <p>Reclaim storage space by removing large files</p>
+            <div class="ui small buttons">
+                <button class="ui primary basic button" onclick="initFileList(20);">20 Results (Fast)</button>
+                <button class="ui secondary basic button" onclick="initFileList(50);">50 Results</button>
+                <button class="ui secondary basic button" onclick="initFileList(100);">100 Results</button>
+                <button class="ui red basic button" onclick="initFileList(300);">300 Results (Slow)</button>
+            </div>
+            <div class="ui divider"></div>
+            <div id="filelist" class="ui list">
+                <div class="item">
+                    <div class="content">
+                        <div class="header"><i class="loading spinner icon"></i> Loading...</div>
+                        <div class="description">
+                            <div class="ui breadcrumb" style="margin-top:8px;">
+                                <div class="active section">Scanning Local Filesystem. This will take a while.</div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+       <br><br><br>
+            
+        </div>
+        <script>
+            initFileList();
+            function initFileList(number=20){
+                $("#filelist").html(`<div class="item">
+                    <div class="content">
+                        <div class="header"><i class="loading spinner icon"></i> Loading...</div>
+                        <div class="description">
+                            <div class="ui breadcrumb" style="margin-top:8px;">
+                                <div class="active section">Scanning Local Filesystem. This will take a while.</div>
+                            </div>
+                        </div>
+                    </div>
+                </div>`);
+                $.get("../../system/disk/space/largeFiles?number=" + number, function(data){
+                    $("#filelist").html("");
+                    data.forEach(file => {
+                        var filepath = file.Filepath.split("/");
+                        filepath.pop();
+                        filepath = filepath.join("/");
+                        $("#filelist").append(`<div class="item">
+                            <i class="file icon"></i>
+                            <div class="content">
+                                <div class="header">${file.Filename} (${bytesToSize(file.Size)})</div>
+                                <div class="description">
+                                    <div class="ui breadcrumb">
+                                        <div class="active section" style="color: #202020 !important;">${filepath}/</div>
+                                        <div class="divider"> ( </div>
+                                        <a class="section" filepath="${filepath}" onclick="openFileLocation(this);">Open File Location</a>
+                                        <div class="divider"> / </div>
+                                        <a class="section" filepath="${file.Filepath}" onclick="deleteThisFile(this);">Delete</a>
+                                        <div class="divider"> ) </div>
+                                    </div>
+                                </div>
+                            </div>
+                        </div>`);
+                    });
+                });
+            }
+
+            function openFileLocation(object){
+                var filepath = $(object).attr("filepath");
+                ao_module_openPath(filepath);
+            }
+
+            function deleteThisFile(object){
+                var filepath = $(object).attr("filepath");
+                var filename = filepath.split("/").pop();
+                if (confirm("Confirm remove: " + filename + " ?")){
+                    //Request file system api to remove the file
+                    requestCSRFToken(function(token){
+                        $.ajax({
+                            url: "../../system/file_system/fileOpr",
+                            data: {opr: "delete", src: JSON.stringify([filepath]), csrft: token},
+                            success: function(data){
+                                if (data.error !== undefined){
+                                    alert(data.error);
+                                }else{
+                                    //DONE
+                                    initFileList();
+                                }   
+                            }
+
+                        });
+                    });
+                }
+            }
+
+            function requestCSRFToken(callback){
+                $.ajax({
+                    url: "../../system/csrf/new",
+                    success: function(token){
+                        callback(token);
+                    }
+                })
+            }
+
+            function bytesToSize(bytes) {
+                var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
+                if (bytes == 0) return '0 Byte';
+                var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
+                return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i];
+            }
+         
+        </script>
+    </body>
 </html>

+ 1 - 0
web/SystemAO/info/gomod-license.csv

@@ -76,6 +76,7 @@ gopkg.in/warnings.v0,https://github.com/go-warnings/warnings/blob/v0.1.2/LICENSE
 imuslab.com/arozos,Unknown,Unknown
 imuslab.com/arozos/mod/agi,Unknown,Unknown
 imuslab.com/arozos/mod/agi/static,Unknown,Unknown
+imuslab.com/arozos/mod/agi/static/ffmpegutil,Unknown,Unknown
 imuslab.com/arozos/mod/apt,Unknown,Unknown
 imuslab.com/arozos/mod/auth,Unknown,Unknown
 imuslab.com/arozos/mod/auth/accesscontrol,Unknown,Unknown

+ 6 - 0
web/desktop.system

@@ -7294,6 +7294,12 @@
                 return;
             }
 
+            //Close all floatWindows
+            $(".floatWindow").each(function(){
+                let thisFloatWindowID = $(this).attr("windowid");
+                closeFloatWindowViaID(thisFloatWindowID);
+            })
+
             $.ajax({
                 url: "system/auth/u/switch",
                 data: {