listPhoto.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. List Photos
  3. This script list all the photos within the user selected save target folder
  4. sorted by the time where the photo is taken (Latest first)
  5. */
  6. requirelib("filelib");
  7. function generatePhotoList(){
  8. //Check if savetarget is empty
  9. if (typeof savetarget == 'undefined' || savetarget == ""){
  10. sendJSONResp(JSON.stringify({
  11. error: "savetarget not defined"
  12. }));
  13. return
  14. }
  15. //Check if save target exists
  16. if (!filelib.fileExists(savetarget)){
  17. sendJSONResp(JSON.stringify({
  18. error: "savetarget not exists"
  19. }));
  20. return
  21. }
  22. //Glob it
  23. if (savetarget.substring(savetarget.length - 1,1) != "/"){
  24. savetarget = savetarget + "/";
  25. }
  26. var files = filelib.aglob(savetarget + "*.*", "mostRecent");
  27. var results = [];
  28. //Filter out only the png and jpg files
  29. for (var i = 0; i < files.length; i++){
  30. var thisFile = files[i];
  31. if (!filelib.isDir(thisFile)){
  32. var ext = thisFile.split(".").pop();
  33. if (ext == "jpg" || ext == "png"){
  34. results.push(thisFile);
  35. }
  36. }
  37. }
  38. //Send the results
  39. sendJSONResp(JSON.stringify(results));
  40. }
  41. generatePhotoList();