From d66d12e7daf41799bb33502f4ea8b6c00bda2b62 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 17 Apr 2020 01:15:21 +1200 Subject: [PATCH] Fix for Instagram's changed N1 data --- src/lib/structures/TimelineEntry.js | 8 ++++++-- src/lib/types.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/lib/structures/TimelineEntry.js b/src/lib/structures/TimelineEntry.js index 9c426d9..3a5a7c3 100644 --- a/src/lib/structures/TimelineEntry.js +++ b/src/lib/structures/TimelineEntry.js @@ -166,8 +166,12 @@ class TimelineEntry extends TimelineBaseMethods { if (this.getType() !== constants.symbols.TYPE_GALLERY) { return this.children = [new TimelineChild(this.data)] } - // Fetch children if needed - if (!this.data.edge_sidecar_to_children) { + /** @type {import("../types").Edges|import("../types").Edges} */ + // @ts-ignore + const children = this.data.edge_sidecar_to_children + // It's a gallery, so we may need to fetch its children + // We need to fetch children if one of them is a video, because N1 has no video_url. + if (!children || !children.edges.length || children.edges.some(edge => edge.node.is_video && !edge.node.video_url)) { await this.update() } // Create children diff --git a/src/lib/types.js b/src/lib/types.js index cd72491..0a3b5e3 100644 --- a/src/lib/types.js +++ b/src/lib/types.js @@ -194,9 +194,26 @@ * @typedef {TimelineEntryN1 & GraphSidecarN1Diff} GraphSidecarN1 * * @typedef GraphSidecarN1Diff + * @property {Edges} edge_sidecar_to_children * @property {"GraphSidecar"} __typename */ +/** + * @typedef GraphChildN1 + * @property {string} __typename + * @property {string} id + * @property {string} shortcode interestingly, each child of a post has a different shortcode. + * @property {Dimensions} dimensions + * @property {string} display_url + * @property {any} gating_info todo: discover + * @property {any} fact_check_overall_rating todo: discover + * @property {any} fact_check_information todo: discover + * @property {string} media_preview base64 of something + * @property {BasicOwner} owner + * @property {boolean} is_video + * @property {string} accessibility_caption + */ + /** * @typedef TimelineEntryN2 * @property {string} __typename