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

89 lines
2.1 KiB
TypeScript

/**
* 许可证限制检查工具
* 用于在各个 API 中检查是否达到许可证限制
*/
import { checkLimit, isFeatureEnabled, getLicenseType } from './license-service';
export interface LimitCheckResult {
allowed: boolean;
current: number;
max: number;
message?: string;
}
/**
* 检查是否可以创建新用户
*/
export async function canCreateUser(): Promise<LimitCheckResult> {
const result = await checkLimit('users');
if (!result.allowed) {
const licenseType = getLicenseType();
return {
...result,
message:
licenseType === 'FREE'
? `免费版最多支持 ${result.max} 个用户,当前已有 ${result.current} 个用户。请升级到标准版或专业版以解除限制。`
: `已达到用户数量上限(${result.max}),请联系管理员。`,
};
}
return result;
}
/**
* 检查是否可以上传新素材
*/
export async function canUploadMaterial(): Promise<LimitCheckResult> {
const result = await checkLimit('materials');
if (!result.allowed) {
const licenseType = getLicenseType();
return {
...result,
message:
licenseType === 'FREE'
? `免费版最多支持 ${result.max} 个素材,当前已有 ${result.current} 个素材。请升级到标准版或专业版以解除限制。`
: `已达到素材数量上限(${result.max}),请联系管理员。`,
};
}
return result;
}
/**
* 检查自定义模板功能是否可用
*/
export function canUseCustomTemplates(): boolean {
return isFeatureEnabled('customTemplates');
}
/**
* 检查部门隔离功能是否可用
*/
export function canUseDepartmentIsolation(): boolean {
return isFeatureEnabled('departmentIsolation');
}
/**
* 检查内网穿透功能是否可用
*/
export function canUseIntranetPenetration(): boolean {
return isFeatureEnabled('intranetPenetration');
}
/**
* 检查系统设置功能是否可用
*/
export function canUseSystemSettings(): boolean {
return isFeatureEnabled('systemSettings');
}
/**
* 检查 API 访问功能是否可用
*/
export function canUseApiAccess(): boolean {
return isFeatureEnabled('apiAccess');
}