mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
36 lines
938 B
TypeScript
36 lines
938 B
TypeScript
import type { NotificationConfig } from "~/schemas/notifications";
|
|
|
|
export function buildNtfyShoutrrrUrl(config: Extract<NotificationConfig, { type: "ntfy" }>): string {
|
|
let shoutrrrUrl: string;
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
const auth =
|
|
config.username && config.password
|
|
? `${encodeURIComponent(config.username)}:${encodeURIComponent(config.password)}@`
|
|
: "";
|
|
|
|
if (config.serverUrl) {
|
|
const url = new URL(config.serverUrl);
|
|
const hostname = url.hostname;
|
|
const port = url.port ? `:${url.port}` : "";
|
|
const scheme = url.protocol === "https:" ? "https" : "http";
|
|
|
|
params.append("scheme", scheme);
|
|
|
|
shoutrrrUrl = `ntfy://${auth}${hostname}${port}/${config.topic}`;
|
|
} else {
|
|
shoutrrrUrl = `ntfy://${auth}ntfy.sh/${config.topic}`;
|
|
}
|
|
|
|
if (config.priority) {
|
|
params.append("priority", config.priority);
|
|
}
|
|
|
|
if (params.toString()) {
|
|
shoutrrrUrl += `?${params.toString()}`;
|
|
}
|
|
|
|
return shoutrrrUrl;
|
|
}
|