munger-engine / app /api /v1 /sync /route.ts
dromerosm's picture
feat: Implement secure sync button with live API status and adaptive polling
4435002
raw
history blame contribute delete
821 Bytes
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 });
}
}