import { getContrail } from '$lib/contrail';
import type { RequestHandler } from './$types';

export const POST: RequestHandler = async ({ request, platform }) => {
	const secret = request.headers.get('X-Cron-Secret');
	if (secret !== platform!.env.CRON_SECRET) {
		return new Response('Unauthorized', { status: 401 });
	}

	const contrail = await getContrail(platform!.env);
	await contrail.ingest({}, platform!.env.DB);

	return new Response('OK');
};
