flnxi-Wu/lib/license/check-limits.ts
2026-05-25 14:52:24 +08:00

89 lines
2.3 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 = await 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 = await getLicenseType();
return {
...result,
message:
licenseType === 'FREE'
? `免费版最多支持 ${result.max} 个素材,当前已有 ${result.current} 个素材。请升级到标准版或专业版以解除限制。`
: `已达到素材数量上限(${result.max}),请联系管理员。`,
};
}
return result;
}
/**
* 检查自定义模板功能是否可用
*/
export async function canUseCustomTemplates(): Promise<boolean> {
return await isFeatureEnabled('customTemplates');
}
/**
* 检查部门隔离功能是否可用
*/
export async function canUseDepartmentIsolation(): Promise<boolean> {
return await isFeatureEnabled('departmentIsolation');
}
/**
* 检查内网穿透功能是否可用
*/
export async function canUseIntranetPenetration(): Promise<boolean> {
return await isFeatureEnabled('intranetPenetration');
}
/**
* 检查系统设置功能是否可用
*/
export async function canUseSystemSettings(): Promise<boolean> {
return await isFeatureEnabled('systemSettings');
}
/**
* 检查 API 访问功能是否可用
*/
export async function canUseApiAccess(): Promise<boolean> {
return await isFeatureEnabled('apiAccess');
}