diff --git a/app/form/client.tsx b/app/form/client.tsx index b8e0aa7..e6a2187 100644 --- a/app/form/client.tsx +++ b/app/form/client.tsx @@ -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(); } }); diff --git a/instrumentation.ts b/instrumentation.ts deleted file mode 100644 index 72eb8e7..0000000 --- a/instrumentation.ts +++ /dev/null @@ -1,6 +0,0 @@ -export async function register() { - if (process.env.NEXT_RUNTIME === 'nodejs') { - const { startTiktokFeedInterval } = await import('@/lib/autofeed'); - startTiktokFeedInterval(); - } -} diff --git a/lib/autofeed.ts b/lib/autofeed.ts deleted file mode 100644 index 57f710c..0000000 --- a/lib/autofeed.ts +++ /dev/null @@ -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); - } -} diff --git a/lib/discord.ts b/lib/discord.ts deleted file mode 100644 index 835e5b9..0000000 --- a/lib/discord.ts +++ /dev/null @@ -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); - } -}