import { NextResponse } from 'next/server'; import { generateArticle } from '@/lib/engine'; /** * POST /api/cron/generate — генерит одну новую статью. * Защищено токеном CRON_TOKEN. * Cron на сервере дёргает каждые N часов с темой из бэклога. */ export async function POST(req) { const auth = req.headers.get('x-cron-token'); if (auth !== process.env.CRON_TOKEN) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } try { const { topic, tags = [], keywords = [] } = await req.json(); if (!topic) return NextResponse.json({ error: 'topic required' }, { status: 400 }); const article = await generateArticle({ topic, tags, keywords, autoPublish: true }); return NextResponse.json({ ok: true, slug: article.slug, title: article.title }); } catch (err) { return NextResponse.json({ error: err.message }, { status: 500 }); } }