mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
32 lines
896 B
TypeScript
32 lines
896 B
TypeScript
import type { NotificationConfig } from "~/schemas/notifications";
|
|
|
|
export function buildDiscordShoutrrrUrl(config: Extract<NotificationConfig, { type: "discord" }>): string {
|
|
const url = new URL(config.webhookUrl);
|
|
const pathParts = url.pathname.split("/").filter(Boolean);
|
|
|
|
if (pathParts.length < 4 || pathParts[0] !== "api" || pathParts[1] !== "webhooks") {
|
|
throw new Error("Invalid Discord webhook URL format");
|
|
}
|
|
|
|
const [, , webhookId, webhookToken] = pathParts;
|
|
|
|
let shoutrrrUrl = `discord://${webhookToken}@${webhookId}`;
|
|
|
|
const params = new URLSearchParams();
|
|
if (config.username) {
|
|
params.append("username", config.username);
|
|
}
|
|
if (config.avatarUrl) {
|
|
params.append("avatarurl", config.avatarUrl);
|
|
}
|
|
if (config.threadId) {
|
|
params.append("thread_id", config.threadId);
|
|
}
|
|
|
|
if (params.toString()) {
|
|
shoutrrrUrl += `?${params.toString()}`;
|
|
}
|
|
|
|
return shoutrrrUrl;
|
|
}
|