apix/app/api/prompts/route.ts
Khoa.vo 8741e3b89f
Some checks are pending
CI / build (18.x) (push) Waiting to run
CI / build (20.x) (push) Waiting to run
feat: Initial commit with multi-provider image generation
2026-01-05 13:50:35 +07:00

22 lines
796 B
TypeScript

import { NextResponse } from 'next/server';
import { getPrompts, syncPromptsService } from '@/lib/prompts-service';
export async function GET() {
try {
const cache = await getPrompts();
// Lazy Auto-Crawl: Check if sync is needed (every 1 hour)
const ONE_HOUR = 60 * 60 * 1000;
const lastSync = cache.lastSync || 0;
if (Date.now() - lastSync > ONE_HOUR) {
console.log("[Auto-Crawl] Triggering background sync...");
// Fire and forget - don't await to keep UI fast
syncPromptsService().catch(err => console.error("[Auto-Crawl] Failed:", err));
}
return NextResponse.json(cache);
} catch (error) {
return NextResponse.json({ error: 'Failed to load prompts' }, { status: 500 });
}
}