|
@@ -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;
|
|
|
+}
|