fix(ntfy): wrong usage of token

This commit is contained in:
Nicolas Meienberger
2025-11-23 20:49:44 +01:00
parent daea3e64e4
commit 8d4e5d2d4e
2 changed files with 15 additions and 7 deletions

View File

@@ -49,8 +49,9 @@ export const ntfyNotificationConfigSchema = type({
type: "'ntfy'",
serverUrl: "string?",
topic: "string",
token: "string?",
priority: "'max' | 'high' | 'default' | 'low' | 'min'",
username: "string?",
password: "string?",
});
export const pushoverNotificationConfigSchema = type({

View File

@@ -3,19 +3,26 @@ 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}` : "";
shoutrrrUrl = `ntfy://${hostname}${port}/${config.topic}`;
const scheme = url.protocol === "https:" ? "https" : "http";
params.append("scheme", scheme);
shoutrrrUrl = `ntfy://${auth}${hostname}${port}/${config.topic}`;
} else {
shoutrrrUrl = `ntfy://ntfy.sh/${config.topic}`;
shoutrrrUrl = `ntfy://${auth}ntfy.sh/${config.topic}`;
}
const params = new URLSearchParams();
if (config.token) {
params.append("token", config.token);
}
if (config.priority) {
params.append("priority", config.priority);
}