listNearbyImage.js 945 B

12345678910111213141516171819202122232425262728293031323334
  1. var loadedfile = requirelib("filelib");
  2. if (!loadedfile) {
  3. console.log("Failed to load lib filelib, terminated.");
  4. }
  5. function listNearby(){
  6. var result = [];
  7. //Extract the path from the filepath
  8. var dirpath = path.split("\\").join("/");
  9. dirpath = dirpath.split("/");
  10. dirpath.pop();
  11. dirpath = dirpath.join("/");
  12. //Get nearby files and filter out the one that is web supported photo format
  13. var nearbyFiles = filelib.aglob(dirpath + "/*")
  14. for (var i = 0; i < nearbyFiles.length; i++){
  15. var ext = nearbyFiles[i].split(".").pop();
  16. ext = ext.toLowerCase();
  17. if (ext == "png" || ext == "jpg" || ext == "jpeg" || ext == "gif" || ext == "webp"){
  18. result.push(nearbyFiles[i]);
  19. }
  20. }
  21. sendJSONResp(JSON.stringify(result))
  22. }
  23. if (typeof(path) == "undefined"){
  24. sendJSONResp(JSON.stringify({
  25. "error": "Invalid path given"
  26. }));
  27. }else{
  28. listNearby();
  29. }