diff --git a/lib/followers/discord.ts b/lib/followers/discord.ts index 1ed1beb..e1077d8 100644 --- a/lib/followers/discord.ts +++ b/lib/followers/discord.ts @@ -8,7 +8,7 @@ export async function getDiscordMemberCount(): Promise { `https://discord.com/api/v10/guilds/${encodeURIComponent(guildId)}?with_counts=true`, { headers: { Authorization: `Bot ${token}` }, - next: { revalidate: 86400 }, + next: { revalidate: 3600 }, } ); if (!res.ok) return null; diff --git a/lib/followers/index.ts b/lib/followers/index.ts index 6a14c43..a131e3d 100644 --- a/lib/followers/index.ts +++ b/lib/followers/index.ts @@ -1,6 +1,7 @@ import { getYoutubeSubscriberCount } from "./youtube"; import { getRobloxFollowerCount } from "./roblox"; import { getDiscordMemberCount } from "./discord"; +import { getTiktokFollowerCount } from "./tiktok"; export interface FollowerCounts { youtube: number | null; @@ -15,15 +16,13 @@ export interface FollowerInfo { } export async function getFollowerCounts(): Promise { - const [youtube, roblox, discord] = await Promise.all([ + const [youtube, roblox, discord, tiktok] = await Promise.all([ getYoutubeSubscriberCount(), getRobloxFollowerCount(), getDiscordMemberCount(), + getTiktokFollowerCount(), ]); - const tiktokEnv = process.env.TIKTOK_FOLLOWERS; - const tiktok = tiktokEnv ? Number(tiktokEnv) : null; - return { youtube, roblox, discord, tiktok }; } diff --git a/lib/followers/roblox.ts b/lib/followers/roblox.ts index e98ddab..d6094c1 100644 --- a/lib/followers/roblox.ts +++ b/lib/followers/roblox.ts @@ -5,7 +5,7 @@ export async function getRobloxFollowerCount(): Promise { try { const res = await fetch( `https://friends.roblox.com/v1/users/${encodeURIComponent(userId)}/followers/count`, - { next: { revalidate: 86400 } } + { next: { revalidate: 3600 } } ); if (!res.ok) return null; diff --git a/lib/followers/tiktok.ts b/lib/followers/tiktok.ts new file mode 100644 index 0000000..81f2400 --- /dev/null +++ b/lib/followers/tiktok.ts @@ -0,0 +1,22 @@ +export async function getTiktokFollowerCount(): Promise { + const apiKey = process.env.TIKTOK_API_KEY; + const userId = process.env.TIKTOK_USER_ID; + if (!apiKey || !userId) return null; + + try { + const res = await fetch( + `https://api.scrapecreators.com/v1/tiktok/profile?user_id=${encodeURIComponent(userId)}`, + { + headers: { 'x-api-key': apiKey }, + next: { revalidate: 86400 } + } + ); + if (!res.ok) return null; + + const data = await res.json(); + const count = data.statsV2?.followerCount; + return count != null ? Number(count) : null; + } catch { + return null; + } +} diff --git a/lib/followers/youtube.ts b/lib/followers/youtube.ts index d239895..9080b79 100644 --- a/lib/followers/youtube.ts +++ b/lib/followers/youtube.ts @@ -6,7 +6,7 @@ export async function getYoutubeSubscriberCount(): Promise { try { const res = await fetch( `https://www.googleapis.com/youtube/v3/channels?part=statistics&id=${encodeURIComponent(channelId)}&key=${encodeURIComponent(apiKey)}`, - { next: { revalidate: 86400 } } + { next: { revalidate: 3600 } } ); if (!res.ok) return null;