Some checks failed
Build & Deploy / 🔍 Prepare Environment (push) Successful in 5s
Build & Deploy / 🧪 QA (push) Failing after 1m14s
Build & Deploy / 🏗️ Build (push) Failing after 4m44s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🔔 Notifications (push) Successful in 1s
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import {
|
|
NotificationOptions,
|
|
NotificationService,
|
|
} from "./notification-service";
|
|
|
|
export interface GotifyConfig {
|
|
url: string;
|
|
token: string;
|
|
enabled: boolean;
|
|
}
|
|
|
|
export class GotifyNotificationService implements NotificationService {
|
|
constructor(private config: GotifyConfig) {}
|
|
|
|
async notify(options: NotificationOptions): Promise<void> {
|
|
if (!this.config.enabled) return;
|
|
|
|
try {
|
|
const { title, message, priority = 4 } = options;
|
|
const url = new URL("message", this.config.url);
|
|
url.searchParams.set("token", this.config.token);
|
|
|
|
const response = await fetch(url.toString(), {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
title,
|
|
message,
|
|
priority,
|
|
}),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorText = await response.text();
|
|
console.error("Gotify notification failed:", {
|
|
status: response.status,
|
|
error: errorText,
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error("Gotify notification error:", error);
|
|
}
|
|
}
|
|
}
|
|
|
|
export class NoopNotificationService implements NotificationService {
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
async notify(_options: NotificationOptions): Promise<void> {
|
|
// Do nothing
|
|
}
|
|
}
|