From 0b3fda4beb6c398dbb9f354536d77cdd4ad2d3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Pluta?= Date: Tue, 25 Feb 2025 15:52:37 +0100 Subject: [PATCH] Implement Debug backend which prints the notification to stdout --- src/backend/debug.ts | 15 +++++++++++++++ src/backend/index.ts | 6 ++++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/backend/debug.ts diff --git a/src/backend/debug.ts b/src/backend/debug.ts new file mode 100644 index 0000000..98f8fb0 --- /dev/null +++ b/src/backend/debug.ts @@ -0,0 +1,15 @@ +import { BackendSettings } from "../types/config"; +import { Notification } from "../types/notification"; +import { Backend } from "./base"; + +type Config = BackendSettings; + +export class Debug extends Backend { + public name = "debug"; + + protected requiredFields = [] as const; + + protected notify(config: Config, notification: Notification): void { + console.log(JSON.stringify(notification, undefined, 2)); + } +} \ No newline at end of file diff --git a/src/backend/index.ts b/src/backend/index.ts index c51959d..4dd3d42 100644 --- a/src/backend/index.ts +++ b/src/backend/index.ts @@ -2,8 +2,10 @@ import dayjs from "dayjs"; import { NotificationDatabase } from "../types/notification"; import { Config } from "../types/config"; import { NtfySH } from "./ntfy"; +import { Debug } from "./debug"; const backends = [ + new Debug(), new NtfySH() ]; @@ -16,8 +18,8 @@ export async function remind(config: Config, db: NotificationDatabase) { const notifications = db[now] ?? []; for (const notification of notifications) { - for (const backend of backends) { - console.info(`Dispatching a notification: [${notification.text}]`) + console.info(`Dispatching a notification: [${notification.text}]`) + for (const backend of backends) { backend.remind(config, notification); await snooze(1500); }