MCPcopy Index your code
hub / github.com/simstudioai/sim / checkStorageQuota

Function checkStorageQuota

apps/sim/lib/billing/storage/limits.ts:168–206  ·  view source on GitHub ↗
(
  userId: string,
  additionalBytes: number
)

Source from the content-addressed store, hash-verified

166 * Always allows uploads when billing is disabled
167 */
168export async function checkStorageQuota(
169 userId: string,
170 additionalBytes: number
171): Promise<{ allowed: boolean; currentUsage: number; limit: number; error?: string }> {
172 if (!isBillingEnabled) {
173 return {
174 allowed: true,
175 currentUsage: 0,
176 limit: Number.MAX_SAFE_INTEGER,
177 }
178 }
179
180 try {
181 const [currentUsage, limit] = await Promise.all([
182 getUserStorageUsage(userId),
183 getUserStorageLimit(userId),
184 ])
185
186 const newUsage = currentUsage + additionalBytes
187 const allowed = newUsage <= limit
188
189 return {
190 allowed,
191 currentUsage,
192 limit,
193 error: allowed
194 ? undefined
195 : `Storage limit exceeded. Used: ${(newUsage / (1024 * 1024 * 1024)).toFixed(2)}GB, Limit: ${(limit / (1024 * 1024 * 1024)).toFixed(0)}GB`,
196 }
197 } catch (error) {
198 logger.error('Error checking storage quota:', error)
199 return {
200 allowed: false,
201 currentUsage: 0,
202 limit: 0,
203 error: 'Failed to check storage quota',
204 }
205 }
206}

Callers 5

uploadWorkspaceFileFunction · 0.90
route.tsFile · 0.90
route.tsFile · 0.85

Calls 3

getUserStorageUsageFunction · 0.85
getUserStorageLimitFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected