WuYongJie ba98bf22cc feat: 添加许可证系统、Agent部署模块和Harbor镜像管理
- 新增许可证服务器 (license-server/)
- 新增 Agent 部署模块 (flnxi-agent/)
- 添加许可证验证和激活页面
- 添加 Harbor 镜像同步脚本
- 更新素材系统支持许可证验证
2025-12-15 21:19:46 +08:00

69 lines
2.0 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { getAdminSession, generateLicenseKey } from '@/lib/auth';
import { prisma } from '@/lib/db';
import { LICENSE_CONFIGS } from '@/lib/types';
export async function GET() {
const session = await getAdminSession();
if (!session) {
return NextResponse.json({ error: '未授权' }, { status: 401 });
}
try {
const licenses = await prisma.license.findMany({
orderBy: { createdAt: 'desc' },
include: {
customer: { select: { companyName: true } },
_count: { select: { activations: true } },
},
});
return NextResponse.json({ licenses });
} catch (error) {
console.error('获取许可证列表失败:', error);
return NextResponse.json({ error: '服务器错误' }, { status: 500 });
}
}
export async function POST(request: NextRequest) {
const session = await getAdminSession();
if (!session) {
return NextResponse.json({ error: '未授权' }, { status: 401 });
}
try {
const { customerId, licenseType, expiresInDays } = await request.json();
if (!licenseType || !['FREE', 'STANDARD', 'PRO'].includes(licenseType)) {
return NextResponse.json(
{ success: false, error: '无效的许可证类型' },
{ status: 400 }
);
}
const config = LICENSE_CONFIGS[licenseType as keyof typeof LICENSE_CONFIGS];
const licenseKey = generateLicenseKey();
const expiresAt = expiresInDays
? new Date(Date.now() + expiresInDays * 24 * 60 * 60 * 1000)
: null;
const license = await prisma.license.create({
data: {
licenseKey,
licenseType,
customerId: customerId || null,
maxUsers: config.limits.maxUsers,
maxMaterials: config.limits.maxMaterials,
features: config.features,
expiresAt,
},
});
return NextResponse.json({ success: true, license });
} catch (error) {
console.error('生成许可证失败:', error);
return NextResponse.json({ success: false, error: '服务器错误' }, { status: 500 });
}
}