فهرست منبع

fix webshot trimming with playwright

Mike L 4 سال پیش
والد
کامیت
3fe8b4e332
5فایلهای تغییر یافته به همراه28 افزوده شده و 25 حذف شده
  1. 5 3
      dist/twitter.js
  2. 2 1
      dist/utils.js
  3. 10 10
      dist/webshot.js
  4. 1 1
      src/twitter.ts
  5. 10 10
      src/webshot.ts

+ 5 - 3
dist/twitter.js

@@ -35,12 +35,14 @@ class ScreenNameNormalizer {
 }
 exports.ScreenNameNormalizer = ScreenNameNormalizer;
 ScreenNameNormalizer.normalize = (username) => username.toLowerCase().replace(/^@/, '');
-exports.sendTweet = (id, receiver) => {
+let sendTweet = (id, receiver) => {
     throw Error();
 };
-exports.sendTimeline = (conf, receiver) => {
+exports.sendTweet = sendTweet;
+let sendTimeline = (conf, receiver) => {
     throw Error();
 };
+exports.sendTimeline = sendTimeline;
 const TWITTER_EPOCH = 1288834974657;
 const snowflake = (epoch) => Number.isNaN(epoch) ? undefined :
     utils_1.BigNumOps.lShift(String(epoch - 1 - TWITTER_EPOCH), 22);
@@ -241,7 +243,7 @@ class default_1 {
                             else {
                                 logger.error(`unhandled error on fetching tweets for ${currentFeed}: ${JSON.stringify(error)}`);
                             }
-                            resolve();
+                            resolve([]);
                         }
                         else
                             resolve(tweets);

+ 2 - 1
dist/utils.js

@@ -1,7 +1,8 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.BigNumOps = exports.chainPromises = void 0;
-exports.chainPromises = (promises, reducer = (p1, p2) => p1.then(() => p2), initialValue) => promises.reduce(reducer, Promise.resolve(initialValue));
+const chainPromises = (promises, reducer = (p1, p2) => p1.then(() => p2), initialValue) => promises.reduce(reducer, Promise.resolve(initialValue));
+exports.chainPromises = chainPromises;
 const splitBigNumAt = (num, at) => num.replace(RegExp(String.raw `^([+-]?)(\d+)(\d{${at}})$`), '$1$2,$1$3')
     .replace(/^([^,]*)$/, '0,$1').split(',')
     .map(Number);

+ 10 - 10
dist/webshot.js

@@ -154,7 +154,7 @@ class Webshot extends CallableInstance {
                             const idx = (x, y) => (this.width * y + x) << 2;
                             let boundary = null;
                             let x = zoomFactor * 2;
-                            for (let y = 0; y < this.height; y++) {
+                            for (let y = 0; y < this.height; y += zoomFactor) {
                                 if (this.data[idx(x, y)] !== 255 &&
                                     this.data[idx(x, y)] === this.data[idx(x + zoomFactor * 10, y)]) {
                                     if (this.data[idx(x, y + 18 * zoomFactor)] !== 255) {
@@ -175,7 +175,7 @@ class Webshot extends CallableInstance {
                                 x = Math.floor(16 * zoomFactor);
                                 let flag = false;
                                 let cnt = 0;
-                                for (let y = this.height - 1; y >= 0; y--) {
+                                for (let y = this.height - 1 - zoomFactor; y >= 0; y -= zoomFactor) {
                                     if ((this.data[idx(x, y)] === 255) === flag) {
                                         cnt++;
                                         flag = !flag;
@@ -189,15 +189,15 @@ class Webshot extends CallableInstance {
                                     // if there are a "retweet" count and "like" count row, this will be the line above it
                                     if (cnt === 4) {
                                         const b = y + 1;
-                                        if (this.height - boundary - (boundary - b) <= 1) {
+                                        if (Math.abs(this.height - boundary - (boundary - b)) <= 3 * zoomFactor) {
                                             boundary = b;
-                                            //   }
-                                            // }
-                                            // // if "retweet" count and "like" count are two rows, this will be the line above the first
-                                            // if (cnt === 6) {
-                                            //   const c = y + 1;
-                                            //   if (this.height - boundary - 2 * (boundary - c) <= 2) {
-                                            //     boundary = c;
+                                        }
+                                    }
+                                    // if "retweet" count and "like" count are two rows, this will be the line above the first
+                                    if (cnt === 6) {
+                                        const c = y + 1;
+                                        if (Math.abs(this.height - boundary - 2 * (boundary - c)) <= 3 * zoomFactor) {
+                                            boundary = c;
                                             break;
                                         }
                                     }

+ 1 - 1
src/twitter.ts

@@ -382,7 +382,7 @@ export default class {
             } else {
               logger.error(`unhandled error on fetching tweets for ${currentFeed}: ${JSON.stringify(error)}`);
             }
-            resolve();
+            resolve([]);
           } else resolve(tweets);
         });
       }

+ 10 - 10
src/webshot.ts

@@ -165,7 +165,7 @@ extends CallableInstance<
                 const idx = (x: number, y: number) => (this.width * y + x) << 2;
                 let boundary = null;
                 let x = zoomFactor * 2;
-                for (let y = 0; y < this.height; y++) {
+                for (let y = 0; y < this.height; y += zoomFactor) {
                   if (
                     this.data[idx(x, y)] !== 255 &&
                     this.data[idx(x, y)] === this.data[idx(x + zoomFactor * 10, y)]
@@ -188,7 +188,7 @@ extends CallableInstance<
                   x = Math.floor(16 * zoomFactor);
                   let flag = false;
                   let cnt = 0;
-                  for (let y = this.height - 1; y >= 0; y--) {
+                  for (let y = this.height - 1 - zoomFactor; y >= 0; y -= zoomFactor) {
                     if ((this.data[idx(x, y)] === 255) === flag) {
                       cnt++;
                       flag = !flag;
@@ -202,16 +202,16 @@ extends CallableInstance<
                     // if there are a "retweet" count and "like" count row, this will be the line above it
                     if (cnt === 4) {
                       const b = y + 1;
-                      if (this.height - boundary - (boundary - b) <= 1) {
+                      if (Math.abs(this.height - boundary - (boundary - b)) <= 3 * zoomFactor) {
                         boundary = b;
-                    //   }
-                    // }
+                      }
+                    }
 
-                    // // if "retweet" count and "like" count are two rows, this will be the line above the first
-                    // if (cnt === 6) {
-                    //   const c = y + 1;
-                    //   if (this.height - boundary - 2 * (boundary - c) <= 2) {
-                    //     boundary = c;
+                    // if "retweet" count and "like" count are two rows, this will be the line above the first
+                    if (cnt === 6) {
+                      const c = y + 1;
+                      if (Math.abs(this.height - boundary - 2 * (boundary - c)) <= 3 * zoomFactor) {
+                        boundary = c;
                         break;
                       }
                     }