Sfoglia il codice sorgente

Added fallback thumbnail loader for file manager

TC pushbot 5 4 anni fa
parent
commit
52c968cf3a

+ 26 - 0
file_system.go

@@ -92,6 +92,7 @@ func FileSystemInit() {
 	//Thumbnail caching functions
 	router.HandleFunc("/system/file_system/handleFolderCache", system_fs_handleFolderCache)
 	router.HandleFunc("/system/file_system/handleCacheRender", system_fs_handleCacheRender)
+	router.HandleFunc("/system/file_system/loadThumbnail", system_fs_handleThumbnailLoad)
 
 	//Directory specific config
 	router.HandleFunc("/system/file_system/sortMode", system_fs_handleFolderSortModePreference)
@@ -2377,6 +2378,31 @@ func system_fs_handleCacheRender(w http.ResponseWriter, r *http.Request) {
 
 	//Perform cache rendering
 	thumbRenderHandler.HandleLoadCache(w, r, rpath)
+}
+
+//Handle loading of one thumbnail
+func system_fs_handleThumbnailLoad(w http.ResponseWriter, r *http.Request) {
+	userinfo, _ := userHandler.GetUserInfoFromRequest(w, r)
+	vpath, err := mv(r, "vpath", false)
+	if err != nil {
+		sendErrorResponse(w, "vpath not defined")
+		return
+	}
+
+	rpath, err := userinfo.VirtualPathToRealPath(vpath)
+	if err != nil {
+		sendErrorResponse(w, err.Error())
+		return
+	}
+
+	thumbnailPath, err := thumbRenderHandler.LoadCache(rpath, false)
+	if err != nil {
+		sendErrorResponse(w, err.Error())
+		return
+	}
+
+	js, _ := json.Marshal(thumbnailPath)
+	sendJSONResponse(w, string(js))
 
 }
 

+ 10 - 0
hardware.power.go

@@ -13,6 +13,16 @@ func HardwarePowerInit() {
 		//Only register these paths when hardware management is enabled
 		http.HandleFunc("/system/power/shutdown", hardware_power_poweroff)
 		http.HandleFunc("/system/power/restart", hardware_power_restart)
+
+		//Register a power handler in system setting menu
+		registerSetting(settingModule{
+			Name:         "Power",
+			Desc:         "Set the power state of the host device",
+			IconPath:     "SystemAO/boot/img/boot.png",
+			Group:        "Info",
+			StartDir:     "SystemAO/boot/poweroff.html",
+			RequireAdmin: true,
+		})
 	}
 
 	http.HandleFunc("/system/power/accessCheck", hardware_power_checkIfHardware)

+ 0 - 10
startup.flags.go

@@ -36,16 +36,6 @@ func StartupFlagsInit() {
 		},
 	})
 
-	//Register a power handler in system setting menu
-	registerSetting(settingModule{
-		Name:         "Power",
-		Desc:         "Set the power state of the host device",
-		IconPath:     "SystemAO/boot/img/boot.png",
-		Group:        "Info",
-		StartDir:     "SystemAO/boot/poweroff.html",
-		RequireAdmin: true,
-	})
-
 	adminRouter.HandleFunc("/system/bootflags", handleBootFlagsFunction)
 }
 

+ 5 - 4
startup.go

@@ -51,10 +51,10 @@ func RunStartup() {
 	PackagManagerInit() //Start APT service agent
 
 	//7. Kickstart the File System and Desktop
-	SchedulerInit()     //Start System Scheudler
-	FileSystemInit()    //Start FileSystem
-	DesktopInit()       //Start Desktop
-	HardwarePowerInit() //Start host power manager
+	SchedulerInit()  //Start System Scheudler
+	FileSystemInit() //Start FileSystem
+	DesktopInit()    //Start Desktop
+
 	//StorageDaemonInit() //Start File System handler daemon (for backup and other sync process)
 
 	//8 Start AGI and Subservice modules (Must start after module)
@@ -72,6 +72,7 @@ func RunStartup() {
 	AuthSettingsInit()        //Authentication Settings Handler, must be start after user Handler
 	AdvanceSettingInit()      //System Advance Settings
 	StartupFlagsInit()        //System BootFlag settibg
+	HardwarePowerInit()       //Start host power manager
 	RegisterStorageSettings() //Storage Settings
 
 	//10. Startup network services and schedule services

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

@@ -1842,10 +1842,33 @@
                 };
 
                 thumbRenderWebSocket.onerror = function(error) {
-                    console.log(error);
+                    //Cache render on websocket failed. Fallback to AJAX request
+                    console.log("Cannot connect to WebSocket cache renderer. Falling back to AJAX request");
+                    startFallbackThumbnailLoader();
                 };
             }
 
+            function startFallbackThumbnailLoader(){
+                let startingCurrentDir = currentPath;
+                $(".fileObject").each(function(){
+                    let filepath = $(this).attr("filepath");
+                    let targetDOM = $(this);
+                    $.ajax({
+                        url: "../../system/file_system/loadThumbnail",
+                        data: {vpath: filepath},
+                        success: function(data){
+                            if (startingCurrentDir == currentPath){
+                                //User still not changed page
+                                if (data.error == undefined && typeof data != "undefined" && data != ""){
+                                    $(targetDOM).find("img").attr("src","data:image/jpg;base64," + data);
+                                }
+                            }
+                            
+                        }
+                    })
+                });
+            }
+
             //Make an div not draggable
             function disableDrag(event){
                 event.preventDefault();

BIN
web/SystemAO/reverse_proxy/img/small_icon.png


BIN
web/SystemAO/reverse_proxy/img/small_icon.psd