Initial commit

This commit is contained in:
mstfyldz
2026-05-27 16:47:37 +03:00
commit 3ee41864f4
40 changed files with 9041 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
import { NextRequest, NextResponse } from 'next/server'
import { requireAuth } from '@/lib/auth'
import { readConfig } from '@/lib/config'
import { testDb, getDbStats, getTables, runQuery } from '@/lib/db'
export async function GET(req: NextRequest) {
const err = await requireAuth(req)
if (err) return err
const dbId = req.nextUrl.searchParams.get('dbId')
const action = req.nextUrl.searchParams.get('action') ?? 'stats'
if (!dbId) return NextResponse.json({ error: 'dbId gerekli' }, { status: 400 })
const config = readConfig()
const db = config.databases.find(d => d.id === dbId)
if (!db) return NextResponse.json({ error: 'DB bulunamadı' }, { status: 404 })
if (action === 'test') return NextResponse.json(await testDb(db))
try {
if (action === 'stats') return NextResponse.json(await getDbStats(db))
if (action === 'tables') return NextResponse.json(await getTables(db))
} catch (e: unknown) {
return NextResponse.json({ error: e instanceof Error ? e.message : 'Bağlantı hatası' }, { status: 400 })
}
return NextResponse.json({ error: 'Geçersiz action' }, { status: 400 })
}
export async function POST(req: NextRequest) {
const err = await requireAuth(req)
if (err) return err
const body = await req.json()
if (body.action === 'test') {
return NextResponse.json(await testDb(body.db))
}
const { dbId, sql } = body
const config = readConfig()
const db = config.databases.find(d => d.id === dbId)
if (!db) return NextResponse.json({ error: 'DB bulunamadı' }, { status: 404 })
return NextResponse.json(await runQuery(db, sql))
}