Pārlūkot izejas kodu

fix layout, fix caption parsing, add debug msgs

Mike L 3 gadi atpakaļ
vecāks
revīzija
2d337028fe
4 mainītis faili ar 25 papildinājumiem un 9 dzēšanām
  1. 9 2
      dist/twitter.js
  2. 2 2
      dist/webshot.js
  3. 12 3
      src/twitter.ts
  4. 2 2
      src/webshot.ts

+ 9 - 2
dist/twitter.js

@@ -164,7 +164,10 @@ let sendPost = (segmentId, receiver) => {
     throw Error();
 };
 exports.sendPost = sendPost;
-const graphNodeToMediaItem = (node) => (Object.assign({ taken_at: node.taken_at_timestamp, code: node.shortcode, caption: (caption => (caption ? caption.edges[0].node : {}))(node.edge_media_to_caption), user: {
+const graphNodeToMediaItem = (node) => (Object.assign({ taken_at: node.taken_at_timestamp, code: (code => {
+        logger.debug(`converting post ${linkBuilder({ postUrlSegment: code })} into mobile api format...`);
+        return code;
+    })(node.shortcode), caption: (caption => (caption && caption.edges.length ? caption.edges[0].node : {}))(node.edge_media_to_caption), user: {
         pk: node.owner.id,
         username: node.owner.username,
     } }, graphBaseNodeToCarouselMediaItem(node)));
@@ -233,7 +236,11 @@ class default_1 {
                                 if (res.status() !== 200) {
                                     throw (0, utils_1.customError)('ResponseError')(`error navigating to user page, error was: ${res.status()} ${res.statusText()}`);
                                 }
-                                return res.json()
+                                return res.text()
+                                    .then(text => {
+                                    logger.debug(`api returned ${text} while pulling for ${userName}`);
+                                    return JSON.parse(text);
+                                })
                                     .catch(redirectionHandler)
                                     .then((json) => {
                                     var _a;

+ 2 - 2
dist/webshot.js

@@ -112,8 +112,8 @@ class Webshot extends CallableInstance {
                         if (a) {
                             time = a.querySelector('time');
                             time.innerHTML = time.title + ' ' + new Date(time.dateTime).toLocaleTimeString().slice(0, -3);
-                            a.parentElement.style.margin = '-24px 2px 12px';
-                            const element = a.parentElement.nextElementSibling;
+                            a.parentElement.parentElement.style.margin = '-24px 2px 12px';
+                            const element = a.parentElement.parentElement.nextElementSibling;
                             if (element)
                                 element.style.display = 'none';
                         }

+ 12 - 3
src/twitter.ts

@@ -245,8 +245,13 @@ export type IgGraphQLUser = {
 
 const graphNodeToMediaItem = (node: IgGraphQLTimelineMediaNode) => ({
   taken_at: node.taken_at_timestamp,
-  code: node.shortcode,
-  caption: (caption => (caption ? caption.edges[0].node : {}) as MediaItem['caption'])(node.edge_media_to_caption),
+  code: (code => {
+    logger.debug(`converting post ${linkBuilder({postUrlSegment: code})} into mobile api format...`);
+    return code;
+  })(node.shortcode),
+  caption: (caption =>
+    (caption && caption.edges.length ? caption.edges[0].node : {}) as MediaItem['caption']
+  )(node.edge_media_to_caption),
   user: {
     pk: node.owner.id,
     username: node.owner.username,
@@ -479,7 +484,11 @@ export default class {
                       `error navigating to user page, error was: ${res.status()} ${res.statusText()}`
                     );
                   }
-                  return res.json()
+                  return res.text()
+                    .then(text => {
+                      logger.debug(`api returned ${text} while pulling for ${userName}`);
+                      return JSON.parse(text);
+                    })
                     .catch(redirectionHandler)
                     .then((json: {[key: string]: {user: IgGraphQLUser}}) => {
                       if (!json || !(json.graphql || json.data)?.user) {

+ 2 - 2
src/webshot.ts

@@ -151,8 +151,8 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
               if (a) {
                 time = a.querySelector('time');
                 time.innerHTML = time.title + ' ' + new Date(time.dateTime).toLocaleTimeString().slice(0, -3);
-                a.parentElement.style.margin = '-24px 2px 12px';
-                const element = a.parentElement.nextElementSibling as HTMLElement;
+                a.parentElement.parentElement.style.margin = '-24px 2px 12px';
+                const element = a.parentElement.parentElement.nextElementSibling as HTMLElement;
                 if (element) element.style.display = 'none';
               }
             }))