All checks were successful
Build & Deploy / 🔍 Prepare (push) Successful in 7s
Build & Deploy / 🧪 QA (push) Successful in 1m55s
Build & Deploy / 🏗️ Build (push) Successful in 4m18s
Build & Deploy / 🚀 Deploy (push) Successful in 26s
Build & Deploy / 🧪 Smoke Test (push) Successful in 49s
Build & Deploy / ⚡ Lighthouse (push) Successful in 4m11s
Build & Deploy / 🔔 Notify (push) Successful in 2s
- Added 5s timeout to GotifyNotificationService - Reduced timeout to 2s in UmamiAnalyticsService - Implemented non-blocking analytics tracking in layout using Next.js after() API
56 lines
1.4 KiB
TypeScript
56 lines
1.4 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 controller = new AbortController();
|
|
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
|
|
const response = await fetch(url.toString(), {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
title,
|
|
message,
|
|
priority,
|
|
}),
|
|
signal: controller.signal,
|
|
});
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
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 {
|
|
async notify(): Promise<void> {
|
|
// Do nothing
|
|
}
|
|
}
|