From 298efc3345b806cc1644531fbf52f70bb39c85a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Pluta?= Date: Fri, 17 Jan 2025 16:13:02 +0100 Subject: [PATCH] Use path instead of explicit token for ntfy-sh backend --- src/backend/index.ts | 5 +---- src/backend/{ntfy-sh.ts => ntfy.ts} | 11 +++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) rename src/backend/{ntfy-sh.ts => ntfy.ts} (69%) diff --git a/src/backend/index.ts b/src/backend/index.ts index 8c7b9b3..4ea5b5a 100644 --- a/src/backend/index.ts +++ b/src/backend/index.ts @@ -1,10 +1,7 @@ import dayjs from "dayjs"; import { NotificationDatabase } from "../types/notification"; import { Config } from "../types/config"; -import { NtfySH } from "./ntfy-sh"; - -export { Backend } from "./base"; -export { NtfySH } from "./ntfy-sh"; +import { NtfySH } from "./ntfy"; const backends = [ new NtfySH() diff --git a/src/backend/ntfy-sh.ts b/src/backend/ntfy.ts similarity index 69% rename from src/backend/ntfy-sh.ts rename to src/backend/ntfy.ts index ae9b972..1401b86 100644 --- a/src/backend/ntfy-sh.ts +++ b/src/backend/ntfy.ts @@ -1,25 +1,28 @@ +import fs from "fs"; import { BackendSettings } from "../types/config"; import { Notification } from "../types/notification"; import { Backend } from "./base"; type Config = { url: string; - token: string; + tokenFile: string; topic?: string; } & BackendSettings; export class NtfySH extends Backend { - public name = "ntfy.sh"; + public name = "ntfy"; - protected requiredFields = ['url', 'token'] as const; + protected requiredFields = ['url', 'tokenFile'] as const; protected notify(config: Config, notification: Notification): void { + const token = fs.readFileSync(config.tokenFile, 'utf-8'); + fetch(`https://${config.url}/${config.topic || 'obsidian'}`, { method: 'POST', body: notification.text, headers: { 'Title': notification.title, - 'Authorization': `Bearer ${config.token}` + 'Authorization': `Bearer ${token}` } }) }