Letschat / src /app /api /sync /route.ts
HonzaH's picture
Upload 194 files
017e02b verified
Raw
History Blame Contribute Delete
702 Bytes
import { NextRequest, NextResponse } from 'next/server'
import { syncLocalToSupabase } from 'lib/persistence'
export async function POST(request: NextRequest) {
try {
const body = await request.json().catch(() => ({}))
const action = body?.action || request.nextUrl.searchParams.get('action')
if (action === 'local') {
const res = await syncLocalToSupabase()
return NextResponse.json({ ok: true, synced: res?.synced ?? 0 })
}
return NextResponse.json({ ok: false, error: 'unknown action' }, { status: 400 })
} catch (e) {
console.error('[api/sync] error', e)
return NextResponse.json({ ok: false, error: String(e) }, { status: 500 })
}
}