Desktop markdown wiki app. Built with node, Electron Framework and AngularJS.

thumbnail-service.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. angular.module('codexApp')
  2. .service('ThumbnailService', [ '$rootScope', '$http', function($rootScope, $http) {
  3. var createThumbnail = function(file_path) {
  4. // //console.log("-> Creating Thumbnail for " + file_path);
  5. // var webshot = require('webshot');
  6. // var fs = require('fs');
  7. // var marked = require('marked');
  8. //
  9. // var options = {
  10. // screenSize: {
  11. // width: 220
  12. // , height: 170
  13. // }
  14. // , shotSize: {
  15. // width: 220
  16. // , height: '170'
  17. // }
  18. // , userAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us)'
  19. // + ' AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g'
  20. // , siteType:'html'
  21. // };
  22. //
  23. // var data = fs.readFileSync(file_path);
  24. // var page_data = String.fromCharCode.apply(null, data);
  25. //
  26. // var thumbnail_path = getThumbnailName(file_path);
  27. // var page = '<html><head><style>body {width: 210px;} body, h1, h2, h3, h4, h5, p, span, table, code, ul, ol { font-family: helvetica; overflow-wrap: break-word; font-weight: 300; } p, ul, ol, code { font-size: 11px;} h1 {font-size: 16px;} h2 {font-size: 14px;} h3 { font-size: 12px; font-weight: 400} code { font-family: monospace; }</style></head><body>' + marked(page_data); + '</body></html>';
  28. // var renderStream = webshot(page, thumbnail_path, options, function(err) {
  29. // // screenshot now saved to hello_world.png
  30. // });
  31. // //var file = fs.createWriteStream('google.png', {encoding: 'binary'});
  32. //
  33. //
  34. //
  35. // console.log("-> Created thumbnail " + thumbnail_path);
  36. // return thumbnail_path;
  37. }
  38. var getThumbnailName = function(file_path) {
  39. var filename = file_path.split('\\').pop().split('/').pop();
  40. var name = filename.split('.');
  41. //if (lastIndex < 1) return "";
  42. var path = file_path.split('/');
  43. path.pop();
  44. var thumb_path = path.join('/');
  45. return thumb_path + "/" + name[0] + ".thumb.png";
  46. }
  47. var thumbnailExists = function(file_path) {
  48. var url = getThumbnailName(file_path);
  49. //console.log(url);
  50. // var http = new XMLHttpRequest();
  51. // http.open('HEAD', url, false);
  52. // http.send();
  53. // console.log(http.status==200);
  54. // return http.status==200;
  55. var fs = require('fs');
  56. return fs.existsSync(url);
  57. }
  58. this.createNoteThumbnail = function(file_path) {
  59. if(thumbnailExists(file_path) == false){
  60. return createThumbnail(file_path);
  61. }
  62. return getThumbnailName(file_path);
  63. }
  64. }])