Use path instead of explicit token for ntfy-sh backend
This commit is contained in:
@@ -1,10 +1,7 @@
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { NotificationDatabase } from "../types/notification";
|
import { NotificationDatabase } from "../types/notification";
|
||||||
import { Config } from "../types/config";
|
import { Config } from "../types/config";
|
||||||
import { NtfySH } from "./ntfy-sh";
|
import { NtfySH } from "./ntfy";
|
||||||
|
|
||||||
export { Backend } from "./base";
|
|
||||||
export { NtfySH } from "./ntfy-sh";
|
|
||||||
|
|
||||||
const backends = [
|
const backends = [
|
||||||
new NtfySH()
|
new NtfySH()
|
||||||
|
|||||||
@@ -1,25 +1,28 @@
|
|||||||
|
import fs from "fs";
|
||||||
import { BackendSettings } from "../types/config";
|
import { BackendSettings } from "../types/config";
|
||||||
import { Notification } from "../types/notification";
|
import { Notification } from "../types/notification";
|
||||||
import { Backend } from "./base";
|
import { Backend } from "./base";
|
||||||
|
|
||||||
type Config = {
|
type Config = {
|
||||||
url: string;
|
url: string;
|
||||||
token: string;
|
tokenFile: string;
|
||||||
topic?: string;
|
topic?: string;
|
||||||
} & BackendSettings;
|
} & BackendSettings;
|
||||||
|
|
||||||
export class NtfySH extends Backend<Config> {
|
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 {
|
protected notify(config: Config, notification: Notification): void {
|
||||||
|
const token = fs.readFileSync(config.tokenFile, 'utf-8');
|
||||||
|
|
||||||
fetch(`https://${config.url}/${config.topic || 'obsidian'}`, {
|
fetch(`https://${config.url}/${config.topic || 'obsidian'}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: notification.text,
|
body: notification.text,
|
||||||
headers: {
|
headers: {
|
||||||
'Title': notification.title,
|
'Title': notification.title,
|
||||||
'Authorization': `Bearer ${config.token}`
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user