feat: add cloud connections and update backups

This commit is contained in:
mstfyldz
2026-06-06 00:31:10 +03:00
parent 58d7fffc6b
commit a4c58135df
11 changed files with 589 additions and 221 deletions
+12 -9
View File
@@ -33,24 +33,27 @@ export async function POST(req: NextRequest) {
try {
const body = await req.json()
const { db_id, schedule, cloud_type, credentials, gdrive_folder_id } = body
const { db_id, schedule, connection_id, cloud_type, credentials, gdrive_folder_id } = body
if (!db_id || !schedule || !cloud_type || !credentials) {
return NextResponse.json({ error: 'Missing fields' }, { status: 400 })
if (!db_id || !schedule) {
return NextResponse.json({ error: 'db_id ve schedule zorunlu' }, { status: 400 })
}
// connection_id VEYA credentials zorunlu
if (!connection_id && !credentials) {
return NextResponse.json({ error: 'connection_id veya credentials gerekli' }, { status: 400 })
}
// Check if exists
const existing = await pool.query(`SELECT id FROM backup_configs WHERE db_id = $1`, [db_id])
if (existing.rows.length > 0) {
await pool.query(
`UPDATE backup_configs SET schedule=$1, cloud_type=$2, credentials=$3, gdrive_folder_id=$4 WHERE db_id=$5`,
[schedule, cloud_type, credentials, gdrive_folder_id || null, db_id]
`UPDATE backup_configs SET schedule=$1, cloud_type=$2, credentials=$3, gdrive_folder_id=$4, connection_id=$5 WHERE db_id=$6`,
[schedule, cloud_type || '', credentials || '', gdrive_folder_id || null, connection_id || null, db_id]
)
} else {
await pool.query(
`INSERT INTO backup_configs (id, db_id, schedule, cloud_type, credentials, gdrive_folder_id) VALUES ($1, $2, $3, $4, $5, $6)`,
[generateId(), db_id, schedule, cloud_type, credentials, gdrive_folder_id || null]
`INSERT INTO backup_configs (id, db_id, schedule, cloud_type, credentials, gdrive_folder_id, connection_id) VALUES ($1, $2, $3, $4, $5, $6, $7)`,
[generateId(), db_id, schedule, cloud_type || '', credentials || '', gdrive_folder_id || null, connection_id || null]
)
}