feat: improve discord webhook configuration flexibility and add error logging for failed requests

This commit is contained in:
암냥 2026-05-23 23:21:30 +09:00
commit d196a73d85
No known key found for this signature in database

View file

@ -68,11 +68,16 @@ async function sendDiscordNotification(payload: {
tags: string[];
imageUrl?: string;
}) {
const webhookUrl = config.discord.webhook;
if (!webhookUrl) return;
const webhookUrl = (config as any)?.webhook?.discord_webhook_uri
?? (config as any)?.discord?.webhook;
if (!webhookUrl || typeof webhookUrl !== "string") {
console.warn("[Discord Webhook] missing webhook URL in config.toml (expected [webhook].discord_webhook_uri)");
return;
}
try {
await fetch(webhookUrl, {
const response = await fetch(webhookUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
@ -86,6 +91,11 @@ async function sendDiscordNotification(payload: {
}],
}),
});
if (!response.ok) {
const errorText = await response.text().catch(() => "");
console.error(`[Discord Webhook] failed status=${response.status} body=${errorText}`);
}
} catch (error) {
console.error("[Discord Webhook Error]", error);
}
@ -565,4 +575,4 @@ export default new Elysia({ prefix: "/post" })
if (!randomPost) return status(404, "포스트를 찾을 수 없습니다.");
return fetch(randomPost.mediaUrl, { cache: "no-store" });
});
});