imagedb.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Image DB
  3. The get and put function for image classification database
  4. and its utilities
  5. */
  6. requirelib("filelib");
  7. //Get all possible roots, return array of [name, path and photo root]
  8. function getAllPossibleRoots(){
  9. function folderContainSubFiles(filepath){
  10. var results = filelib.aglob(filepath + "/*", "default");
  11. if (results.length > 0){
  12. return true;
  13. }
  14. return false;
  15. }
  16. var possibleRoots = [];
  17. for ( var i = 0; i < USER_VROOTS.length; i++){
  18. var thisRoot = USER_VROOTS[i];
  19. if (thisRoot.Filesystem != "virtual" && filelib.fileExists(thisRoot.UUID + ":/Photo") && folderContainSubFiles(thisRoot.UUID + ":/Photo/")){
  20. possibleRoots.push([thisRoot.Name, thisRoot.UUID + ":/", thisRoot.UUID + ":/Photo"]);
  21. }
  22. }
  23. return possibleRoots;
  24. }
  25. function isSupportedImage(filename){
  26. if (fileExt == "jpg" || fileExt == "png" || fileExt == "jpeg"){
  27. return true;
  28. }else{
  29. return false
  30. }
  31. }
  32. //Get all the image files exists in *:/Photo/*
  33. function getAllImageFiles(){
  34. var results = [];
  35. var possibleRoots = getAllPossibleRoots();
  36. for ( var i = 0; i < possibleRoots.length; i++){
  37. var thisRootInfo = possibleRoots[i];
  38. var allFilesInThisPhotoRoot = filelib.walk(thisRootInfo[2]);
  39. for ( var j = 0; j < allFilesInThisPhotoRoot.length; j++){
  40. var thisFile = allFilesInThisPhotoRoot[j];
  41. if (!filelib.isDir(thisFile) && isSupportedImage(thisFile)){
  42. results.push(thisFile);
  43. }
  44. }
  45. }
  46. return results;
  47. }