11import { ONLINE_PRESENCE_PROVIDERS } from "@/lib/api/partner-profile/online-presence-providers" ;
2+ import { fetchSocialProfile } from "@/lib/api/scrape-creators/fetch-social-profile" ;
23import { getSession } from "@/lib/auth/utils" ;
34import { redis } from "@/lib/upstash/redis" ;
45import { prisma } from "@dub/prisma" ;
5- import { PlatformType } from "@dub/prisma/client" ;
6+ import { PartnerPlatform , PlatformType } from "@dub/prisma/client" ;
67import {
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
0 commit comments