| 1 | package attachment |
| 2 | |
| 3 | const ( |
| 4 | MaxSourceBytes = 64 << 20 |
| 5 | MaxSourcePixels = 50_000_000 |
| 6 | DefaultMaxCount = 20 |
| 7 | DefaultBatchBytes = 200 << 20 |
| 8 | ViewImageMaxBytes = 3 << 20 |
| 9 | ViewImageMaxPixels = 40_000_000 |
| 10 | VariantMaxDim = 1568 |
| 11 | VariantJPEGQuality = 85 |
| 12 | VariantPolicyV1 = 1 |
| 13 | DefaultCacheBytes = 512 << 20 |
| 14 | DefaultTransforms = 2 |
| 15 | ) |
| 16 | |
| 17 | // Policy is the shared budget object. Host is the final enforcer. |
| 18 | type Policy struct { |
| 19 | MaxBytes int64 |
| 20 | MaxPixels int64 |
| 21 | MaxCount int |
| 22 | MaxBatchBytes int64 |
| 23 | } |
| 24 | |
| 25 | func DefaultPolicy() Policy { |
| 26 | return Policy{ |
| 27 | MaxBytes: MaxSourceBytes, |
| 28 | MaxPixels: MaxSourcePixels, |
| 29 | MaxCount: DefaultMaxCount, |
| 30 | MaxBatchBytes: DefaultBatchBytes, |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func ViewImagePolicy() Policy { |
| 35 | return Policy{ |
| 36 | MaxBytes: ViewImageMaxBytes, |
| 37 | MaxPixels: ViewImageMaxPixels, |
| 38 | MaxCount: 1, |
| 39 | MaxBatchBytes: ViewImageMaxBytes, |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func (p Policy) withDefaults() Policy { |
| 44 | if p.MaxBytes <= 0 { |
| 45 | p.MaxBytes = MaxSourceBytes |
| 46 | } |
| 47 | if p.MaxPixels <= 0 { |
| 48 | p.MaxPixels = MaxSourcePixels |
| 49 | } |
| 50 | if p.MaxCount <= 0 { |
| 51 | p.MaxCount = DefaultMaxCount |
| 52 | } |
| 53 | if p.MaxBatchBytes <= 0 { |
| 54 | p.MaxBatchBytes = DefaultBatchBytes |
| 55 | } |
| 56 | return p |
| 57 | } |
| 58 |