- 新增许可证服务器 (license-server/) - 新增 Agent 部署模块 (flnxi-agent/) - 添加许可证验证和激活页面 - 添加 Harbor 镜像同步脚本 - 更新素材系统支持许可证验证
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
||
import { activate } from '@/lib/license';
|
||
|
||
export async function POST(request: NextRequest) {
|
||
try {
|
||
const { licenseKey } = await request.json();
|
||
|
||
if (!licenseKey) {
|
||
return NextResponse.json(
|
||
{ success: false, error: '请输入许可证密钥' },
|
||
{ status: 400 }
|
||
);
|
||
}
|
||
|
||
const result = await activate(licenseKey);
|
||
|
||
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 }
|
||
);
|
||
}
|
||
}
|