96 lines
2.8 KiB
TypeScript
96 lines
2.8 KiB
TypeScript
// 兼容性:重新导出新的订阅服务
|
|
export { SubscriptionService } from './subscription-service'
|
|
|
|
// 订阅计划配置(已弃用,保留用于向后兼容)
|
|
// @deprecated 请使用 SubscriptionService.getAvailablePlans() 替代
|
|
export const SUBSCRIPTION_PLANS = {
|
|
free: {
|
|
name: 'Free',
|
|
maxVersionLimit: 3,
|
|
promptLimit: 500,
|
|
price: 0,
|
|
features: [
|
|
'promptLimit',
|
|
'versionsPerPrompt'
|
|
]
|
|
},
|
|
pro: {
|
|
name: 'Pro',
|
|
maxVersionLimit: 10,
|
|
promptLimit: 5000,
|
|
price: 19.9,
|
|
features: [
|
|
'promptLimit',
|
|
'versionsPerPrompt',
|
|
'prioritySupport'
|
|
]
|
|
}
|
|
} as const
|
|
|
|
export type SubscriptionPlan = keyof typeof SUBSCRIPTION_PLANS
|
|
|
|
// 兼容性函数(已弃用,保留用于向后兼容)
|
|
|
|
// @deprecated 请使用 SubscriptionService.getUserPermissions() 替代
|
|
export function getUserVersionLimit(user: {
|
|
versionLimit: number
|
|
subscribePlan: string
|
|
maxVersionLimit: number
|
|
}): number {
|
|
const plan = user.subscribePlan as SubscriptionPlan
|
|
const planConfig = SUBSCRIPTION_PLANS[plan]
|
|
|
|
if (!planConfig) {
|
|
return Math.min(user.versionLimit, SUBSCRIPTION_PLANS.free.maxVersionLimit)
|
|
}
|
|
|
|
return Math.min(user.versionLimit, planConfig.maxVersionLimit)
|
|
}
|
|
|
|
// @deprecated 请使用 SubscriptionService.getPlanById() 替代
|
|
export function getMaxVersionLimit(subscribePlan: string): number {
|
|
const plan = subscribePlan as SubscriptionPlan
|
|
const planConfig = SUBSCRIPTION_PLANS[plan]
|
|
|
|
return planConfig?.maxVersionLimit || SUBSCRIPTION_PLANS.free.maxVersionLimit
|
|
}
|
|
|
|
// @deprecated 请使用 SubscriptionService.canCreateVersion() 替代
|
|
export function canCreateNewVersion(
|
|
currentVersionCount: number,
|
|
user: {
|
|
versionLimit: number
|
|
subscribePlan: string
|
|
maxVersionLimit: number
|
|
}
|
|
): boolean {
|
|
const versionLimit = getUserVersionLimit(user)
|
|
return currentVersionCount < versionLimit
|
|
}
|
|
|
|
// @deprecated 请使用 SubscriptionService.getVersionsToDelete() 替代
|
|
export function getVersionsToDelete(
|
|
currentVersionCount: number,
|
|
user: {
|
|
versionLimit: number
|
|
subscribePlan: string
|
|
maxVersionLimit: number
|
|
}
|
|
): number {
|
|
const versionLimit = getUserVersionLimit(user)
|
|
return Math.max(0, currentVersionCount - versionLimit + 1)
|
|
}
|
|
|
|
// @deprecated 请使用 SubscriptionService.getUserPermissions() 替代
|
|
export function getPromptLimit(subscribePlan: string): number {
|
|
const plan = subscribePlan as SubscriptionPlan
|
|
const planConfig = SUBSCRIPTION_PLANS[plan]
|
|
|
|
return planConfig?.promptLimit || SUBSCRIPTION_PLANS.free.promptLimit
|
|
}
|
|
|
|
// @deprecated 请使用 SubscriptionService.canCreatePrompt() 替代
|
|
export async function canCreateNewPrompt(userId: string): Promise<boolean> {
|
|
const { SubscriptionService } = await import('./subscription-service')
|
|
return await SubscriptionService.canCreatePrompt(userId)
|
|
} |