* Best-effort storage threshold evaluation after a usage change. Re-reads the * (now updated) usage and plan limit, then delegates dedup + send to * maybeNotifyLimit. Never throws. * * The caller passes the subscription it already resolved for the increment/ * decrement, so the whole pa
( userId: string, workspaceId: string, sub: HighestPrioritySubscription | null, rearmOnly = false )
| 34 | * threshold re-arms but never sends (a drop is not a fresh crossing). |
| 35 | */ |
| 36 | async function maybeNotifyStorageLimit( |
| 37 | userId: string, |
| 38 | workspaceId: string, |
| 39 | sub: HighestPrioritySubscription | null, |
| 40 | rearmOnly = false |
| 41 | ): Promise<void> { |
| 42 | try { |
| 43 | const [usage, limit] = await Promise.all([ |
| 44 | getUserStorageUsage(userId, sub), |
| 45 | getUserStorageLimit(userId, sub), |
| 46 | ]) |
| 47 | |
| 48 | await maybeNotifyLimit({ |
| 49 | category: 'storage', |
| 50 | billedUserId: userId, |
| 51 | workspaceId, |
| 52 | currentUsage: usage, |
| 53 | limit, |
| 54 | usageLabel: formatGb(usage, 2), |
| 55 | limitLabel: formatGb(limit, 0), |
| 56 | rearmOnly, |
| 57 | subscription: sub, |
| 58 | }) |
| 59 | } catch (error) { |
| 60 | logger.error('Error evaluating storage limit notification:', error) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Increment storage usage after successful file upload |
no test coverage detected