Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

revert to v1/instagram/post, fallback to view_count if play_count undefined

Steven Tey511d7e61d6e8
diff --git a/apps/web/lib/api/scrape-creators/get-social-content.ts b/apps/web/lib/api/scrape-creators/get-social-content.ts
index 8edff4b90d..d457141ebd 100644
--- a/apps/web/lib/api/scrape-creators/get-social-content.ts
+++ b/apps/web/lib/api/scrape-creators/get-social-content.ts
@@ -60,7 +60,7 @@ export async function getSocialContent({
}
const contentType = PLATFORM_CONTENT_TYPE[platform];
- const version = ["tiktok", "instagram"].includes(platform) ? "v2" : "v1";
+ const version = platform === "tiktok" ? "v2" : "v1";
const { data, error } = await scrapeCreatorsFetch(
"/:version/:platform/:contentType",
@@ -91,6 +91,8 @@ export async function getSocialContent({
return EMPTY_SOCIAL_CONTENT;
}
+ console.log(`Response from ScrapeCreators: ${JSON.stringify(data, null, 2)}`);
+
let result: SocialContent;
switch (data.platform) {
@@ -134,7 +136,10 @@ export async function getSocialContent({
mediaType = "carousel";
} else if (data.__typename === "GraphImage") {
mediaType = "image";
- } else if (thumbnailUrls === undefined && data.video_play_count > 0) {
+ } else if (
+ thumbnailUrls === undefined &&
+ (data.video_play_count || data.video_view_count) > 0
+ ) {
mediaType = "video";
}
@@ -142,7 +147,7 @@ export async function getSocialContent({
publishedAt: new Date(data.taken_at_timestamp * 1000),
handle: data.owner.username,
platformId: null,
- views: data.video_play_count,
+ views: data.video_play_count ?? data.video_view_count,
likes: data.edge_media_preview_like.count,
title: null,
description: data.edge_media_to_caption?.edges?.[0]?.node?.text ?? null,
diff --git a/apps/web/lib/api/scrape-creators/schema.ts b/apps/web/lib/api/scrape-creators/schema.ts
index 6bfe441fd7..8125409d02 100644
--- a/apps/web/lib/api/scrape-creators/schema.ts
+++ b/apps/web/lib/api/scrape-creators/schema.ts
@@ -234,6 +234,10 @@ export const socialContentSchema = z.preprocess(
.number()
.nullish()
.transform((val) => val ?? 0),
+ video_view_count: z
+ .number()
+ .nullish()
+ .transform((val) => val ?? 0),
edge_media_preview_like: z.object({
count: z
.number()