|
@@ -74,7 +74,10 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
|
logger.info('not working on a tweet');
|
|
|
};
|
|
|
|
|
|
- private renderWebshot = (url: string, height: number, webshotDelay: number): Promise<string> => {
|
|
|
+ private renderWebshot = (
|
|
|
+ url: string, height: number, webshotDelay: number,
|
|
|
+ ...morePostProcessings: ((page: puppeteer.Page) => Promise<any>)[]
|
|
|
+ ): Promise<string> => {
|
|
|
temp.track();
|
|
|
const jpeg = (data: Readable) => data.pipe(sharp()).jpeg({quality: 90, trellisQuantisation: true});
|
|
|
const sharpToFile = (pic: sharp.Sharp) => new Promise<string>(resolve => {
|
|
@@ -155,6 +158,7 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
|
.then(() => page.addScriptTag({
|
|
|
content: 'document.documentElement.scrollTop=0;',
|
|
|
}))
|
|
|
+ .then(() => chainPromises(morePostProcessings.map(func => () => func(page))))
|
|
|
.then(() => promisify(setTimeout)(getTimeout()))
|
|
|
.then(() => page.screenshot())
|
|
|
.then(screenshot => {
|
|
@@ -212,10 +216,11 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
|
.catch(reject);
|
|
|
});
|
|
|
return promise.then(data => {
|
|
|
- if (data.boundary === null) return this.renderWebshot(url, height + 1920, webshotDelay);
|
|
|
- else return data.path;
|
|
|
+ if (data.boundary === null) {
|
|
|
+ return this.renderWebshot(url, height + 1920, webshotDelay, ...morePostProcessings);
|
|
|
+ } else return data.path;
|
|
|
}).catch(error => this.reconnect(error)
|
|
|
- .then(() => this.renderWebshot(url, height, webshotDelay))
|
|
|
+ .then(() => this.renderWebshot(url, height, webshotDelay, ...morePostProcessings))
|
|
|
);
|
|
|
};
|
|
|
|
|
@@ -316,7 +321,7 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
|
// eslint-disable-next-line curly
|
|
|
if (1 - this.mode % 2) promise = promise.then(() => {
|
|
|
if (originTwi.extended_entities) {
|
|
|
- return chainPromises(originTwi.extended_entities.media.map(media => {
|
|
|
+ return chainPromises(originTwi.extended_entities.media.map(media => () => {
|
|
|
let url: string;
|
|
|
if (media.type === 'photo') {
|
|
|
url = media.media_url_https.replace(/\.([a-z]+)$/, '?format=$1') + '&name=orig';
|