getThumbnail.js 883 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. Music Module Thumbnail Getter
  3. author: tobychui
  4. This script handle thumbnail loading from the local filesystem
  5. Require paramter: file
  6. Return: base64 of the image content
  7. */
  8. function main(){
  9. if (!requirelib("filelib")){
  10. return;
  11. }
  12. if (!requirelib("imagelib")){
  13. return;
  14. }
  15. //Check for source file exists
  16. if (filelib.fileExists(file)){
  17. //File exists. Load thumb
  18. var thumbImageBase64 = imagelib.loadThumbString(file);
  19. if (thumbImageBase64 != false){
  20. //Set the respond header to image
  21. sendResp(thumbImageBase64)
  22. }else{
  23. sendJSONResp(JSON.stringify({
  24. error: "Thumb load failed",
  25. }))
  26. }
  27. }else{
  28. sendJSONResp(JSON.stringify({
  29. error: "File not exists, given: " + file,
  30. }))
  31. }
  32. }
  33. main();