feat: add TikTok follower integration and reduce cache revalidation interval to one hour
This commit is contained in:
@@ -8,7 +8,7 @@ export async function getDiscordMemberCount(): Promise<number | null> {
|
||||
`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;
|
||||
|
||||
@@ -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<FollowerCounts> {
|
||||
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 };
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ export async function getRobloxFollowerCount(): Promise<number | null> {
|
||||
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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ export async function getYoutubeSubscriberCount(): Promise<number | null> {
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user