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
-33
View File
@@ -1,9 +1,5 @@
import fs from 'fs'
import path from 'path'
import pool from './appDb'
const CONFIG_PATH = path.join(process.cwd(), 'config.json')
export interface Site {
id: string
name: string
@@ -49,36 +45,7 @@ export function generateId(): string {
return `${Date.now()}-${Math.random().toString(36).slice(2, 7)}`
}
// Migration ve okuma bir arada
export async function readConfig(): Promise<Config> {
// Migration kontrolü
if (fs.existsSync(CONFIG_PATH)) {
try {
const raw = fs.readFileSync(CONFIG_PATH, 'utf-8')
const oldConfig = JSON.parse(raw) as Config
// Veritabanına aktar
for (const site of oldConfig.sites || []) {
await pool.query(`INSERT INTO config_sites (id, name, url, interval_min) VALUES ($1, $2, $3, $4) ON CONFLICT DO NOTHING`, [site.id, site.name, site.url, site.interval_min || 5])
}
for (const db of oldConfig.databases || []) {
await pool.query(`INSERT INTO config_databases (id, name, host, port, database, username, password, ssl, color, db_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT DO NOTHING`, [db.id, db.name, db.host, db.port, db.database, db.username, db.password, db.ssl || false, db.color, db.db_type || 'postgres'])
}
for (const svc of oldConfig.services || []) {
await pool.query(`INSERT INTO config_services (id, name, url, icon, description) VALUES ($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING`, [svc.id, svc.name, svc.url, svc.icon, svc.description])
}
for (const host of oldConfig.docker_hosts || []) {
await pool.query(`INSERT INTO config_docker_hosts (id, name, url) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING`, [host.id, host.name, host.url])
}
// Dosyanın uzantısını değiştirerek migration'ın bittiğini işaretle
fs.renameSync(CONFIG_PATH, CONFIG_PATH + '.bak')
console.log('[Migration] config.json verileri PostgreSQL tablolalarına aktarıldı ve dosya yedeklendi.')
} catch (e) {
console.error('[Migration] config.json veritabanına aktarılırken hata oluştu:', e)
}
}
// DB'den oku
const [sitesRes, dbsRes, svcsRes, dockerRes] = await Promise.all([
pool.query(`SELECT * FROM config_sites`),