feat: improve discord webhook configuration flexibility and add error logging for failed requests
This commit is contained in:
parent
0c1c566b3d
commit
d196a73d85
1 changed files with 14 additions and 4 deletions
|
|
@ -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" });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue