- Added manual database backup functionality with pg_dump - Added cron-based automated backups to Google Drive and Dropbox - Added ability to manually add, edit, and delete sites in Analytics - Added 1-day timeframe filter in Analytics page - Updated Dockerfile to include postgresql-client
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { requireAuth } from '@/lib/auth'
|
|
import { getAnalyticsStats, getAllDomains, addAnalyticsSite, renameAnalyticsSite, deleteAnalyticsSite } from '@/lib/appDb'
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const err = await requireAuth(req)
|
|
if (err) return err
|
|
|
|
const domain = req.nextUrl.searchParams.get('domain')
|
|
const days = parseInt(req.nextUrl.searchParams.get('days') ?? '30')
|
|
|
|
if (!domain) {
|
|
// Domain listesi döndür
|
|
const domains = await getAllDomains()
|
|
return NextResponse.json({ domains })
|
|
}
|
|
|
|
const stats = await getAnalyticsStats(domain, days)
|
|
return NextResponse.json(stats)
|
|
}
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const err = await requireAuth(req)
|
|
if (err) return err
|
|
|
|
const { domain } = await req.json()
|
|
if (!domain) return NextResponse.json({ error: 'Domain required' }, { status: 400 })
|
|
|
|
await addAnalyticsSite(domain)
|
|
return NextResponse.json({ ok: true })
|
|
}
|
|
|
|
export async function PUT(req: NextRequest) {
|
|
const err = await requireAuth(req)
|
|
if (err) return err
|
|
|
|
const { oldDomain, newDomain } = await req.json()
|
|
if (!oldDomain || !newDomain) return NextResponse.json({ error: 'Missing params' }, { status: 400 })
|
|
|
|
await renameAnalyticsSite(oldDomain, newDomain)
|
|
return NextResponse.json({ ok: true })
|
|
}
|
|
|
|
export async function DELETE(req: NextRequest) {
|
|
const err = await requireAuth(req)
|
|
if (err) return err
|
|
|
|
const domain = req.nextUrl.searchParams.get('domain')
|
|
if (!domain) return NextResponse.json({ error: 'Domain required' }, { status: 400 })
|
|
|
|
await deleteAnalyticsSite(domain)
|
|
return NextResponse.json({ ok: true })
|
|
}
|