MCPcopy
hub / github.com/FlowiseAI/Flowise / checkUsageLimit

Function checkUsageLimit

packages/server/src/utils/quotaUsage.ts:50–75  ·  view source on GitHub ↗
(
    type: UsageType,
    subscriptionId: string,
    usageCacheManager: UsageCacheManager,
    currentUsage: number
)

Source from the content-addressed store, hash-verified

48
49// For usage that doesn't renew per month, we just get the count from database and check
50export const checkUsageLimit = async (
51 type: UsageType,
52 subscriptionId: string,
53 usageCacheManager: UsageCacheManager,
54 currentUsage: number
55) => {
56 if (!usageCacheManager || !subscriptionId) return
57
58 const quotas = await usageCacheManager.getQuotas(subscriptionId)
59
60 let limit = -1
61 switch (type) {
62 case 'flows':
63 limit = quotas[LICENSE_QUOTAS.FLOWS_LIMIT]
64 break
65 case 'users':
66 limit = quotas[LICENSE_QUOTAS.USERS_LIMIT] + (Math.max(quotas[LICENSE_QUOTAS.ADDITIONAL_SEATS_LIMIT], 0) || 0)
67 break
68 }
69
70 if (limit === -1) return
71
72 if (currentUsage > limit) {
73 throw new InternalFlowiseError(StatusCodes.PAYMENT_REQUIRED, `Limit exceeded: ${type}`)
74 }
75}
76
77// As predictions limit renew per month, we set to cache with 1 month TTL
78export const updatePredictionsUsage = async (

Callers 6

saveChatflowFunction · 0.90
createAssistantFunction · 0.90
importDataFunction · 0.90
importAssistantsFunction · 0.90
createMethod · 0.90
saveInviteAccountMethod · 0.90

Calls 1

getQuotasMethod · 0.80

Tested by

no test coverage detected