import {env} from 'cloudflare:workers';
import {launchMissions} from '@/lib/missions';
import {response,errorResponse,throttle,hash} from '@/lib/commons';
export async function POST(r:Request){try{const u=new URL(r.url),origin=r.headers.get('origin');if(origin&&origin!==u.origin)return response({error:{code:'ORIGIN_REJECTED',message:'Origin not allowed'}},403);await throttle(env.DB,'missions:'+await hash(r.headers.get('cf-connecting-ip')||'local'),4,3600);return response({data:await launchMissions(env.DB,u.searchParams.get('daily')==='1')})}catch(e){return errorResponse(e)}}
