feat: remove TikTok auto-feed integration

This commit is contained in:
2026-07-06 19:30:11 +07:00 Unverified
parent 48c4dae218
commit 6a4f06f5aa
4 changed files with 2 additions and 102 deletions
+2 -2
View File
@@ -88,11 +88,11 @@ const buildSchema = (questions: Question[]) => {
const plainLabel = stripHtml(q.label);
if (q.type === "checkbox") {
shape[q.id] = q.required
? z.array(z.string()).min(1, `จำเป็นต้องตอบ "${plainLabel}"`)
? z.array(z.string()).min(1, `จำเป็นต้องตอบข้อนี้`)
: z.array(z.string()).optional();
} else {
shape[q.id] = q.required
? z.string().min(1, `จำเป็นต้องตอบ "${plainLabel}"`)
? z.string().min(1, `จำเป็นต้องตอบข้อนี้`)
: z.string().optional();
}
});
-6
View File
@@ -1,6 +0,0 @@
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
const { startTiktokFeedInterval } = await import('@/lib/autofeed');
startTiktokFeedInterval();
}
}
-59
View File
@@ -1,59 +0,0 @@
import { getRedisClient } from "@/lib/redis";
import { sendDiscordNotification } from "@/lib/discord";
import { getLatestTiktokVideo, getTiktokProfile } from "@/lib/followers/tiktok";
async function checkTiktokFeed() {
try {
const latestVideo = await getLatestTiktokVideo();
if (!latestVideo) return;
const redis = await getRedisClient();
const redisKey = "erika:tiktok_last_video_id";
const lastVideoId = await redis.get(redisKey);
if (lastVideoId === latestVideo.id) {
return; // Already notified
}
let officialAuthorName = "TikTok";
let officialAvatarUrl: string | undefined = undefined;
try {
const profile = await getTiktokProfile();
if (profile.displayName) officialAuthorName = profile.displayName;
if (profile.avatarUrl) officialAvatarUrl = profile.avatarUrl;
} catch (e) {
console.error("[TikTok Feed] Failed to fetch profile:", e);
}
const message = `ลงคลิปใหม่แล้วววสสสสส ${latestVideo.shareUrl}`;
const embed = {
title: latestVideo.title || "คลิปใหม่จาก TikTok",
url: latestVideo.shareUrl || undefined,
color: 0xff0050,
author: {
name: officialAuthorName,
url: latestVideo.shareUrl || "https://www.tiktok.com/",
icon_url: officialAvatarUrl || undefined
},
image: latestVideo.coverImageUrl ? { url: latestVideo.coverImageUrl } : undefined
};
await sendDiscordNotification(message, embed);
await redis.set(redisKey, latestVideo.id);
} catch (error) {
console.error("[TikTok Feed] Error processing:", error);
}
}
export function startTiktokFeedInterval() {
if (!(global as any).tiktokFeedIntervalStarted) {
(global as any).tiktokFeedIntervalStarted = true;
console.log("[TikTok Feed] Starting 5-minute interval check in background...");
// Run immediately on start
checkTiktokFeed();
// Then every 5 minutes
setInterval(checkTiktokFeed, 5 * 60 * 1000);
}
}
-35
View File
@@ -1,35 +0,0 @@
export async function sendDiscordNotification(content: string, embed?: any) {
const token = process.env.DISCORD_BOT_TOKEN;
const channelId = process.env.DISCORD_CHANNEL_ID;
if (!token) {
console.error("[Discord Notification] Missing DISCORD_BOT_TOKEN");
return;
}
if (!channelId) {
console.error("[Discord Notification] Missing DISCORD_CHANNEL_ID environment variable. Please add it to your .env file.");
return;
}
try {
const res = await fetch(`https://discord.com/api/v10/channels/${channelId}/messages`, {
method: "POST",
headers: {
"Authorization": `Bot ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
content,
embeds: embed ? [embed] : undefined
})
});
if (!res.ok) {
console.error("[Discord Notification] Failed to send message:", await res.text());
} else {
}
} catch (error) {
console.error("[Discord Notification] Error sending message:", error);
}
}