import { NextResponse } from 'next/server'; import { activateFreeTrial } from '@/lib/license'; export async function POST() { try { const result = await activateFreeTrial(); if (result.success) { const response = NextResponse.json({ success: true }); // 设置许可证激活 cookie(用于 middleware 快速检查) response.cookies.set('license_activated', 'true', { httpOnly: true, secure: process.env.NODE_ENV === 'production', sameSite: 'lax', maxAge: 365 * 24 * 60 * 60, // 1年 path: '/', }); return response; } else { return NextResponse.json( { success: false, error: result.error }, { status: 400 } ); } } catch (error) { console.error('免费试用激活失败:', error); return NextResponse.json( { success: false, error: '服务器错误' }, { status: 500 } ); } }