feat: update vps-panel backup and notification features

This commit is contained in:
mstfyldz
2026-06-05 23:53:57 +03:00
parent 29d03604f9
commit c1f04735d6
22 changed files with 1029 additions and 372 deletions
+52
View File
@@ -0,0 +1,52 @@
import { getNotificationSettings, NotificationSettings } from './appDb'
export async function sendStatusAlert(
siteName: string,
siteUrl: string,
oldStatus: string,
newStatus: string,
ms: number | null
) {
let settings: NotificationSettings | null
try {
settings = await getNotificationSettings()
} catch {
return
}
if (!settings || !settings.enabled) return
const isDown = newStatus !== 'up'
const emoji = newStatus === 'up' ? '✅' : newStatus === 'degraded' ? '⚠️' : '🔴'
const statusLabel = newStatus === 'up' ? 'Düzeldi (UP)' : newStatus === 'degraded' ? 'Yavaş (DEGRADED)' : 'Çöktü (DOWN)'
const msText = ms ? `${ms}ms` : ''
const text = `${emoji} *${siteName}*\nDurum: ${statusLabel}${msText}\nURL: ${siteUrl}`
if (settings.webhook_url) {
fetch(settings.webhook_url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text,
site: siteName,
url: siteUrl,
status: newStatus,
previous_status: oldStatus,
ms,
timestamp: new Date().toISOString(),
}),
}).catch(() => {})
}
if (settings.telegram_token && settings.telegram_chat_id) {
fetch(`https://api.telegram.org/bot${settings.telegram_token}/sendMessage`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
chat_id: settings.telegram_chat_id,
text: `🔔 *VPS Panel*\n\n${text}`,
parse_mode: 'Markdown',
}),
}).catch(() => {})
}
}