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
+18 -8
View File
@@ -1,10 +1,14 @@
import { NextResponse } from 'next/server'
import { NextRequest, NextResponse } from 'next/server'
import { readConfig } from '@/lib/config'
import { createDbDumpBuffer } from '@/lib/backup'
import { requireAuth } from '@/lib/auth'
import pool from '@/lib/appDb'
// GET /api/db/backup?dbId=...
export async function GET(req: Request) {
export async function GET(req: NextRequest) {
const authErr = await requireAuth(req)
if (authErr) return authErr
const { searchParams } = new URL(req.url)
const dbId = searchParams.get('dbId')
if (!dbId) return NextResponse.json({ error: 'Missing dbId' }, { status: 400 })
@@ -18,16 +22,22 @@ export async function GET(req: Request) {
const dateStr = new Date().toISOString().replace(/[:.]/g, '-')
const filename = `${db.name}_${dateStr}.sql`
await pool.query(`INSERT INTO backup_logs (db_id, status, error, size, target) VALUES ($1, $2, $3, $4, $5)`, [dbId, 'success', null, buffer.length, 'manuel indirme'])
await pool.query(
`INSERT INTO backup_logs (db_id, status, message, file_size) VALUES ($1, $2, $3, $4)`,
[dbId, 'success', 'Manuel indirme', buffer.length]
)
return new NextResponse(buffer.toString('utf-8'), {
return new NextResponse(new Uint8Array(buffer), {
headers: {
'Content-Type': 'application/sql',
'Content-Disposition': `attachment; filename="${filename}"`
}
'Content-Type': 'application/octet-stream',
'Content-Disposition': `attachment; filename="${filename}"`,
},
})
} catch (e: any) {
await pool.query(`INSERT INTO backup_logs (db_id, status, error, size, target) VALUES ($1, $2, $3, $4, $5)`, [dbId, 'error', e.message, 0, 'manuel indirme'])
await pool.query(
`INSERT INTO backup_logs (db_id, status, message, file_size) VALUES ($1, $2, $3, $4)`,
[dbId, 'error', e.message, 0]
)
return NextResponse.json({ error: e.message }, { status: 500 })
}
}