| 1 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | package storage |
| 4 | |
| 5 | // Quota is the disk-usage budget for a user or org. Recorded in the DB |
| 6 | // under users.disk_quota_* and orgs.disk_quota_* (added when those tables |
| 7 | // exist). S04 wires the type only — enforcement lives in a future policy |
| 8 | // package called from the push pipeline (S14) and attachment uploads. |
| 9 | type Quota struct { |
| 10 | Used int64 // bytes currently used |
| 11 | Limit int64 // bytes allowed (0 = unlimited) |
| 12 | } |
| 13 | |
| 14 | // Available returns Limit - Used, clamped at zero. Returns -1 when the |
| 15 | // quota is unlimited. |
| 16 | func (q Quota) Available() int64 { |
| 17 | if q.Limit == 0 { |
| 18 | return -1 |
| 19 | } |
| 20 | if q.Used >= q.Limit { |
| 21 | return 0 |
| 22 | } |
| 23 | return q.Limit - q.Used |
| 24 | } |
| 25 | |
| 26 | // WouldExceed reports whether writing additional bytes n would push past |
| 27 | // the limit. Always false for an unlimited quota. |
| 28 | func (q Quota) WouldExceed(n int64) bool { |
| 29 | if q.Limit == 0 { |
| 30 | return false |
| 31 | } |
| 32 | return q.Used+n > q.Limit |
| 33 | } |
| 34 |