feat: add TikTok follower integration and reduce cache revalidation interval to one hour

This commit is contained in:
2026-06-21 23:58:57 +07:00 Unverified
parent a25f778f57
commit 4010cd1df4
5 changed files with 28 additions and 7 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ export async function getDiscordMemberCount(): Promise<number | null> {
`https://discord.com/api/v10/guilds/${encodeURIComponent(guildId)}?with_counts=true`, `https://discord.com/api/v10/guilds/${encodeURIComponent(guildId)}?with_counts=true`,
{ {
headers: { Authorization: `Bot ${token}` }, headers: { Authorization: `Bot ${token}` },
next: { revalidate: 86400 }, next: { revalidate: 3600 },
} }
); );
if (!res.ok) return null; if (!res.ok) return null;
+3 -4
View File
@@ -1,6 +1,7 @@
import { getYoutubeSubscriberCount } from "./youtube"; import { getYoutubeSubscriberCount } from "./youtube";
import { getRobloxFollowerCount } from "./roblox"; import { getRobloxFollowerCount } from "./roblox";
import { getDiscordMemberCount } from "./discord"; import { getDiscordMemberCount } from "./discord";
import { getTiktokFollowerCount } from "./tiktok";
export interface FollowerCounts { export interface FollowerCounts {
youtube: number | null; youtube: number | null;
@@ -15,15 +16,13 @@ export interface FollowerInfo {
} }
export async function getFollowerCounts(): Promise<FollowerCounts> { export async function getFollowerCounts(): Promise<FollowerCounts> {
const [youtube, roblox, discord] = await Promise.all([ const [youtube, roblox, discord, tiktok] = await Promise.all([
getYoutubeSubscriberCount(), getYoutubeSubscriberCount(),
getRobloxFollowerCount(), getRobloxFollowerCount(),
getDiscordMemberCount(), getDiscordMemberCount(),
getTiktokFollowerCount(),
]); ]);
const tiktokEnv = process.env.TIKTOK_FOLLOWERS;
const tiktok = tiktokEnv ? Number(tiktokEnv) : null;
return { youtube, roblox, discord, tiktok }; return { youtube, roblox, discord, tiktok };
} }
+1 -1
View File
@@ -5,7 +5,7 @@ export async function getRobloxFollowerCount(): Promise<number | null> {
try { try {
const res = await fetch( const res = await fetch(
`https://friends.roblox.com/v1/users/${encodeURIComponent(userId)}/followers/count`, `https://friends.roblox.com/v1/users/${encodeURIComponent(userId)}/followers/count`,
{ next: { revalidate: 86400 } } { next: { revalidate: 3600 } }
); );
if (!res.ok) return null; if (!res.ok) return null;
+22
View File
@@ -0,0 +1,22 @@
export async function getTiktokFollowerCount(): Promise<number | null> {
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;
}
}
+1 -1
View File
@@ -6,7 +6,7 @@ export async function getYoutubeSubscriberCount(): Promise<number | null> {
try { try {
const res = await fetch( const res = await fetch(
`https://www.googleapis.com/youtube/v3/channels?part=statistics&id=${encodeURIComponent(channelId)}&key=${encodeURIComponent(apiKey)}`, `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; if (!res.ok) return null;