Преглед на файлове

Fixed scheduler crashing issues

Toby Chui преди 3 години
родител
ревизия
a1b5944e3f
променени са 5 файла, в които са добавени 114 реда и са изтрити 8 реда
  1. 8 4
      scheduler.go
  2. 4 3
      startup.go
  3. 45 0
      web/Photo/backend/classify.js
  4. 53 0
      web/Photo/backend/imagedb.js
  5. 4 1
      web/desktop.system

+ 8 - 4
scheduler.go

@@ -24,7 +24,7 @@ var (
 	systemScheduler *scheduler.Scheduler
 )
 
-func SchedulerInit() {
+func NightlyTasksInit() {
 	/*
 		Nighty Task Manager
 
@@ -32,6 +32,10 @@ func SchedulerInit() {
 	*/
 	nightlyManager = nightly.NewNightlyTaskManager(*nightlyTaskRunTime)
 
+}
+
+func SchedulerInit() {
+
 	/*
 		System Scheudler
 
@@ -78,9 +82,9 @@ func SchedulerInit() {
 			errorHandlePermissionDenied(w, r)
 		}
 	})
-	router.HandleFunc("/system/arsm/aecron/add", newScheduler.HandleAddJob)
-	router.HandleFunc("/system/arsm/aecron/remove", newScheduler.HandleJobRemoval)
-	router.HandleFunc("/system/arsm/aecron/listlog", newScheduler.HandleShowLog)
+	router.HandleFunc("/system/arsm/aecron/add", systemScheduler.HandleAddJob)
+	router.HandleFunc("/system/arsm/aecron/remove", systemScheduler.HandleJobRemoval)
+	router.HandleFunc("/system/arsm/aecron/listlog", systemScheduler.HandleShowLog)
 
 	//Register settings
 	registerSetting(settingModule{

+ 4 - 3
startup.go

@@ -51,14 +51,15 @@ func RunStartup() {
 	PackagManagerInit() //Start APT service agent
 
 	//7. Kickstart the File System and Desktop
-	SchedulerInit()  //Start System Scheudler
-	FileSystemInit() //Start FileSystem
-	DesktopInit()    //Start Desktop
+	NightlyTasksInit() //Start Nightly task scheduler
+	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)
 	AGIInit()        //ArOZ Javascript Gateway Interface, must start after fs
+	SchedulerInit()  //Start System Scheudler
 	SubserviceInit() //Subservice Handler
 
 	//9. Initiate System Settings Handlers

+ 45 - 0
web/Photo/backend/classify.js

@@ -8,3 +8,48 @@
     imagepath (string)
 */
 
+
+requirelib("filelib");
+requirelib("imagelib");
+includes("imagedb.js");
+
+function returnError(msg){
+    sendJSONResp(JSON.stringify({"error": msg}));
+}
+
+function main(){
+    //Check if the imagepath exists
+    if (!filelib.fileExists(imagepath)){
+        returnError("file not exists");
+        return
+    }
+
+    //Check if it is a supported image format
+    var fileExt = imagepath.split(".").pop();
+    if (fileExt == "jpg" || fileExt == "png" || fileExt == "jpeg"){
+        //Get image classification, will take a bit time
+        var results = imagelib.classify(imagepath, "darknet19"); 
+        var responses = [];
+        for (var i = 0; i < results.length; i++){
+            responses.push({
+                "object": results[i].Name,
+                "confidence": results[i].Percentage,
+                "position_x": results[i].Positions[0],
+                "position_y": results[i].Positions[1],
+                "width": results[i].Positions[2],
+                "height": results[i].Positions[3]
+            });
+        }
+
+        sendJSONResp(JSON.stringify(responses));
+    }else{
+        //Not supported format
+        returnError("format not supported");
+        return
+    }
+
+   
+}
+
+main();
+

+ 53 - 0
web/Photo/backend/imagedb.js

@@ -0,0 +1,53 @@
+/*
+    Image DB
+    The get and put function for image classification database
+    and its utilities
+*/
+
+requirelib("filelib");
+
+//Get all possible roots, return array of [name, path and photo root]
+function getAllPossibleRoots(){
+    function folderContainSubFiles(filepath){
+        var results = filelib.aglob(filepath + "/*", "default");
+        if (results.length > 0){
+            return true;
+        }
+        return false;
+    }
+    var possibleRoots = [];
+    for ( var i = 0; i < USER_VROOTS.length; i++){
+        var thisRoot = USER_VROOTS[i];
+        if (thisRoot.Filesystem != "virtual" && filelib.fileExists(thisRoot.UUID + ":/Photo") && folderContainSubFiles(thisRoot.UUID + ":/Photo/")){
+            possibleRoots.push([thisRoot.Name, thisRoot.UUID + ":/", thisRoot.UUID + ":/Photo"]);
+        }
+    }
+
+    return possibleRoots;
+}
+
+function isSupportedImage(filename){
+    if (fileExt == "jpg" || fileExt == "png" || fileExt == "jpeg"){
+        return true;
+    }else{
+        return false
+    }
+}
+
+//Get all the image files exists in *:/Photo/*
+function getAllImageFiles(){
+    var results = [];
+    var possibleRoots = getAllPossibleRoots();
+    for ( var i = 0; i < possibleRoots.length; i++){
+        var thisRootInfo = possibleRoots[i];
+        var allFilesInThisPhotoRoot = filelib.walk(thisRootInfo[2]);
+        for ( var j = 0; j < allFilesInThisPhotoRoot.length; j++){
+            var thisFile = allFilesInThisPhotoRoot[j];
+            if (!filelib.isDir(thisFile) && isSupportedImage(thisFile)){
+                results.push(thisFile);
+            }
+        }
+    }
+
+    return results;
+}

+ 4 - 1
web/desktop.system

@@ -3346,7 +3346,10 @@
                                 data: {path: filedata.Filepath},
                                 success: function(data){
                                     $('#fileDescriptor').html(`<p>${filedata.Filename}<br><i class="file outline icon"></i> ${formatBytes(data.Filesize)} (${data.MimeType})<br><i class="time icon"></i> ${data.LastModTime}</p>`);
-                                    $('#fileDescriptor').show();
+                                    if (!(data.MimeType == undefined)){
+                                        $('#fileDescriptor').show();
+                                    }
+                                    
                                 }
                             })