feat: add docker monitoring and ui fixes

This commit is contained in:
mstfyldz
2026-06-03 00:58:54 +03:00
parent e5dc347a0b
commit 29d03604f9
24 changed files with 1682 additions and 553 deletions
+6 -20
View File
@@ -1,6 +1,7 @@
import { NextResponse } from 'next/server'
import { readConfig } from '@/lib/config'
import { createPgDumpStream } from '@/lib/backup'
import { createDbDumpBuffer } from '@/lib/backup'
import pool from '@/lib/appDb'
// GET /api/db/backup?dbId=...
export async function GET(req: Request) {
@@ -13,35 +14,20 @@ export async function GET(req: Request) {
if (!db) return NextResponse.json({ error: 'Database not found' }, { status: 404 })
try {
const child = await createPgDumpStream(db)
const buffer = await createDbDumpBuffer(db)
const dateStr = new Date().toISOString().replace(/[:.]/g, '-')
const filename = `${db.name}_${dateStr}.sql`
// Stream the output of pg_dump to the response
const stream = new ReadableStream({
start(controller) {
child.stdout.on('data', (chunk) => controller.enqueue(chunk))
child.on('close', (code) => {
if (code === 0) {
controller.close()
} else {
controller.error(new Error(`pg_dump exited with code ${code}`))
}
})
child.on('error', (err) => controller.error(err))
},
cancel() {
child.kill()
}
})
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'])
return new NextResponse(stream, {
return new NextResponse(buffer.toString('utf-8'), {
headers: {
'Content-Type': 'application/sql',
'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'])
return NextResponse.json({ error: e.message }, { status: 500 })
}
}