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[]; tags: string[];
imageUrl?: string; imageUrl?: string;
}) { }) {
const webhookUrl = config.discord.webhook; const webhookUrl = (config as any)?.webhook?.discord_webhook_uri
if (!webhookUrl) return; ?? (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 { try {
await fetch(webhookUrl, { const response = await fetch(webhookUrl, {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ 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) { } catch (error) {
console.error("[Discord Webhook Error]", error); console.error("[Discord Webhook Error]", error);
} }
@ -565,4 +575,4 @@ export default new Elysia({ prefix: "/post" })
if (!randomPost) return status(404, "포스트를 찾을 수 없습니다."); if (!randomPost) return status(404, "포스트를 찾을 수 없습니다.");
return fetch(randomPost.mediaUrl, { cache: "no-store" }); return fetch(randomPost.mediaUrl, { cache: "no-store" });
}); });