Skip to content

Commit 55941e1

Browse files
committed
nullish stats to guard against broken API
1 parent fdc16ea commit 55941e1

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

apps/web/lib/api/scrape-creators/schema.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,22 @@ export const profileResponseSchema = z.preprocess(
5050
platform: z.literal("youtube"),
5151
description: z.string(),
5252
channelId: z.string(),
53-
videoCount: z.number(),
54-
subscriberCount: z.number(),
55-
viewCount: z.number(),
53+
videoCount: z.number().nullish().default(0),
54+
subscriberCount: z.number().nullish().default(0),
55+
viewCount: z.number().nullish().default(0),
5656
}),
5757

5858
z.object({
5959
platform: z.literal("instagram"),
6060
data: z.object({
6161
user: z.object({
6262
biography: z.string(),
63-
edge_followed_by: z.object({ count: z.number() }),
64-
edge_owner_to_timeline_media: z.object({ count: z.number() }),
63+
edge_followed_by: z.object({
64+
count: z.number().nullish().default(0),
65+
}),
66+
edge_owner_to_timeline_media: z.object({
67+
count: z.number().nullish().default(0),
68+
}),
6569
}),
6670
}),
6771
}),
@@ -74,9 +78,9 @@ export const profileResponseSchema = z.preprocess(
7478
uniqueId: z.string(),
7579
}),
7680
stats: z.object({
77-
followerCount: z.number(),
78-
videoCount: z.number(),
79-
heartCount: z.number(),
81+
followerCount: z.number().nullish().default(0),
82+
videoCount: z.number().nullish().default(0),
83+
heartCount: z.number().nullish().default(0),
8084
}),
8185
}),
8286

@@ -85,8 +89,8 @@ export const profileResponseSchema = z.preprocess(
8589
rest_id: z.string(),
8690
legacy: z.object({
8791
description: z.string(),
88-
followers_count: z.number(),
89-
statuses_count: z.number(),
92+
followers_count: z.number().nullish().default(0),
93+
statuses_count: z.number().nullish().default(0),
9094
}),
9195
}),
9296
]),

0 commit comments

Comments
 (0)