Use path instead of explicit token for ntfy-sh backend

This commit is contained in:
2025-01-17 16:13:02 +01:00
parent a270ee4ae5
commit 298efc3345
2 changed files with 8 additions and 8 deletions

View File

@@ -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()

View File

@@ -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<Config> {
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}`
}
})
}