Fix ntfy delivery diagnostics

This commit is contained in:
dinlo
2026-06-27 15:38:31 +08:00
parent a88ed8da75
commit 292cef5cbb
7 changed files with 33 additions and 17 deletions
+4 -4
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,7 +1,7 @@
{
"id": "reminder-notifier",
"name": "Reminder Notifier",
"version": "0.1.0",
"version": "0.1.1",
"minAppVersion": "1.5.0",
"description": "Create reminders from notes and send notifications through Telegram, ntfy, webhooks, Discord, or local Obsidian notices.",
"author": "",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "obsidian-reminder-notifier",
"version": "0.1.0",
"version": "0.1.1",
"description": "Obsidian plugin for note-based reminders and external notifications.",
"main": "main.js",
"scripts": {
+17 -10
View File
@@ -1,14 +1,15 @@
import { requestUrl } from "obsidian";
import { NotificationPayload, NotificationProvider, NotificationProviderConfig } from "../types";
import { asString } from "../utils/template";
import { normalizeNtfyServerUrl } from "../utils/ntfy";
export class NtfyNotifier implements NotificationProvider {
id = "ntfy" as const;
name = "ntfy";
async send(payload: NotificationPayload, provider: NotificationProviderConfig): Promise<void> {
const serverUrl = asString(provider.config.serverUrl, "https://ntfy.sh").replace(/\/$/, "");
const topic = asString(provider.config.topic);
const serverUrl = normalizeNtfyServerUrl(asString(provider.config.serverUrl, "https://ntfy.sh"));
const topic = asString(provider.config.topic).trim();
if (!topic) {
throw new Error("ntfy topic is required.");
}
@@ -18,7 +19,7 @@ export class NtfyNotifier implements NotificationProvider {
Priority: String(provider.config.priority ?? priorityToNtfy(payload.priority)),
};
const token = asString(provider.config.token);
const token = asString(provider.config.token).trim();
if (token) {
headers.Authorization = `Bearer ${token}`;
}
@@ -28,13 +29,19 @@ export class NtfyNotifier implements NotificationProvider {
headers.Tags = tags.join(",");
}
await requestUrl({
url: `${serverUrl}/${encodeURIComponent(topic)}`,
method: "POST",
headers,
body: payload.message,
throw: true,
});
const url = `${serverUrl}/${encodeURIComponent(topic)}`;
try {
await requestUrl({
url,
method: "POST",
headers,
body: payload.message,
throw: true,
});
} catch (error) {
const details = error instanceof Error ? error.message : String(error);
throw new Error(`ntfy send failed for ${serverUrl}/${topic}: ${details}`);
}
}
async test(provider: NotificationProviderConfig): Promise<void> {
+5
View File
@@ -0,0 +1,5 @@
export function normalizeNtfyServerUrl(value: string): string {
const trimmed = value.trim() || "https://ntfy.sh";
const withProtocol = /^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
return withProtocol.replace(/\/+$/, "");
}
+3
View File
@@ -1,4 +1,5 @@
import assert from "node:assert/strict";
import { normalizeNtfyServerUrl } from "../src/utils/ntfy";
import { getNextRepeatDate, parseReminderDate } from "../src/utils/date";
const base = new Date("2026-06-27T10:00:00");
@@ -22,3 +23,5 @@ assert.equal(nextDaily, "2026-06-28T10:00:00.000Z");
const nextWeekly = getNextRepeatDate("2026-06-20T10:00:00.000Z", { frequency: "weekly", interval: 2 }, new Date("2026-06-27T10:00:01.000Z"));
assert.equal(nextWeekly, "2026-07-04T10:00:00.000Z");
assert.equal(normalizeNtfyServerUrl("notifai.dinlo.ru/"), "https://notifai.dinlo.ru");
assert.equal(normalizeNtfyServerUrl("http://127.0.0.1:8080/"), "http://127.0.0.1:8080");
+2 -1
View File
@@ -1,3 +1,4 @@
{
"0.1.0": "1.5.0"
"0.1.0": "1.5.0",
"0.1.1": "1.5.0"
}