Skip to content

Commit d435ba1

Browse files
committed
Add social statistics synchronization for TikTok and Twitter after verification
1 parent 6f288b6 commit d435ba1

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

apps/web/app/(ee)/api/partners/online-presence/callback/route.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ONLINE_PRESENCE_PROVIDERS } from "@/lib/api/partner-profile/online-presence-providers";
2+
import { fetchSocialProfile } from "@/lib/api/scrape-creators/fetch-social-profile";
23
import { getSession } from "@/lib/auth/utils";
34
import { redis } from "@/lib/upstash/redis";
45
import { prisma } from "@dub/prisma";
5-
import { PlatformType } from "@dub/prisma/client";
6+
import { PartnerPlatform, PlatformType } from "@dub/prisma/client";
67
import {
78
getSearchParams,
89
PARTNERS_DOMAIN,
@@ -148,6 +149,33 @@ export async function GET(req: Request) {
148149
return NextResponse.redirect(redirectUrl);
149150
}
150151

152+
// Sync social stats for platforms
153+
let socialStats: Pick<PartnerPlatform, "subscribers" | "posts" | "views"> = {
154+
subscribers: BigInt(0),
155+
posts: BigInt(0),
156+
views: BigInt(0),
157+
};
158+
159+
if (["tiktok", "twitter"].includes(platform)) {
160+
try {
161+
const socialProfile = await fetchSocialProfile({
162+
platform,
163+
handle: partnerPlatform.identifier,
164+
});
165+
166+
socialStats = {
167+
subscribers: socialProfile.subscribers,
168+
posts: socialProfile.posts,
169+
views: socialProfile.views,
170+
};
171+
} catch (error) {
172+
console.error(
173+
`Failed to fetch social stats for ${platform} handle @${partnerPlatform.identifier}:`,
174+
error,
175+
);
176+
}
177+
}
178+
151179
await prisma.partnerPlatform.update({
152180
where: {
153181
partnerId_type: {
@@ -157,7 +185,8 @@ export async function GET(req: Request) {
157185
},
158186
data: {
159187
verifiedAt: new Date(),
160-
metadata: metadata || undefined,
188+
...(metadata && { metadata }),
189+
...socialStats,
161190
},
162191
});
163192

apps/web/lib/api/partner-profile/online-presence-providers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const ONLINE_PRESENCE_PROVIDERS: Record<string, OnlinePresenceProvider> =
117117
},
118118
},
119119

120+
// We don't support LinkedIn verification yet
120121
linkedin: {
121122
authUrl: "https://www.linkedin.com/oauth/v2/authorization",
122123
tokenUrl: "https://www.linkedin.com/oauth/v2/accessToken",

0 commit comments

Comments
 (0)