All files / src/server/files quota.ts

100% Statements 2/2
100% Branches 2/2
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20          16x                 53x          
// How much a user may store (receipts and documents together): a limit
// against misuse that keeps R2 within its free tier, not exact accounting.
// The usage comes from the sizes recorded in D1, checked before
// storage.put().
 
export const STORAGE_QUOTA = { bytes: 500 * 1024 * 1024, files: 1000 } as const
 
export interface StorageUsage {
  bytes: number
  files: number
}
 
/** Whether one more file of `incomingBytes` fits in the quota. */
export function fitsQuota(usage: StorageUsage, incomingBytes: number): boolean {
  return (
    usage.files + 1 <= STORAGE_QUOTA.files &&
    usage.bytes + incomingBytes <= STORAGE_QUOTA.bytes
  )
}