webshot.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const log4js = require("log4js");
  4. const webshot = require("webshot");
  5. const read = require("read-all-stream");
  6. const logger = log4js.getLogger('webshot');
  7. logger.level = 'info';
  8. function renderWebshot(url, height) {
  9. let promise = new Promise(resolve => {
  10. const options = {
  11. windowSize: {
  12. width: 1080,
  13. height: height,
  14. },
  15. userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
  16. renderDelay: 5000,
  17. quality: 100,
  18. customCSS: 'html{zoom:2}header{display:none!important}',
  19. };
  20. const renderStream = webshot(url, options);
  21. read(renderStream, 'base64').then(data => {
  22. resolve(data);
  23. });
  24. });
  25. return promise.then(data => {
  26. if (height < 2048)
  27. return renderWebshot(url, height * 2);
  28. else
  29. return data;
  30. });
  31. }
  32. /*function fetchImage(): Promise<string> {
  33. }*/
  34. function default_1(twitter, callback) {
  35. twitter.forEach(twi => {
  36. const url = `https://mobile.twitter.com/${twi.user.screen_name}/status/${twi.id_str}`;
  37. renderWebshot(url, 1920)
  38. .then(base64Webshot => {
  39. console.log(base64Webshot);
  40. });
  41. });
  42. }
  43. exports.default = default_1;