add scanning

This commit is contained in:
Garret Patti
2026-04-05 18:55:53 -04:00
parent c87a9b33bb
commit 8829188c58
11 changed files with 872 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import { NextRequest, NextResponse } from 'next/server'
import cron from 'node-cron'
import { requireAdmin } from '@/lib/auth'
import { getScanConfig, updateScanConfig } from '@/lib/app-settings'
import { restartScheduler } from '@/lib/scheduler'
export async function GET(request: NextRequest) {
const auth = await requireAdmin(request)
if (auth instanceof NextResponse) return auth
const { schedule, enabled } = getScanConfig()
return NextResponse.json({ schedule, enabled })
}
export async function PUT(request: NextRequest) {
const auth = await requireAdmin(request)
if (auth instanceof NextResponse) return auth
let body: { schedule?: string; enabled?: boolean }
try {
body = await request.json()
} catch {
return NextResponse.json({ error: 'Invalid JSON body' }, { status: 400 })
}
const { schedule, enabled } = body
if (typeof schedule !== 'string' || !schedule.trim()) {
return NextResponse.json({ error: 'schedule is required' }, { status: 400 })
}
if (typeof enabled !== 'boolean') {
return NextResponse.json({ error: 'enabled must be a boolean' }, { status: 400 })
}
if (!cron.validate(schedule)) {
return NextResponse.json({ error: 'Invalid cron expression' }, { status: 400 })
}
updateScanConfig(schedule, enabled)
restartScheduler()
return NextResponse.json({ schedule, enabled })
}