Spaces:
Running
Running
| import { NextResponse } from 'next/server'; | |
| import { runSync } from '@/lib/sync-service'; | |
| import { JsonStore } from '@/lib/store'; | |
| export async function POST(request: Request) { | |
| try { | |
| // Endpoints are protected by proxy.ts middleware (x-api-key) | |
| try { | |
| const result = await runSync(); | |
| return NextResponse.json({ message: 'Sync started', totalAssets: result.totalAssets }); | |
| } catch (error: any) { | |
| if (error.message === 'Sync already in progress') { | |
| return NextResponse.json({ message: error.message }, { status: 409 }); | |
| } | |
| throw error; | |
| } | |
| } catch (error) { | |
| console.error("Error in sync route:", error); | |
| return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 }); | |
| } | |
| } | |