Use path instead of explicit token for ntfy-sh backend
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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}`
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user