| 1 | export const MAX_IMAGE_ATTACHMENT_BYTES = 64 * 1024 * 1024; |
| 2 | |
| 3 | const MIB = 1024 * 1024; |
| 4 | |
| 5 | export interface OversizeAttachment { |
| 6 | file: File; |
| 7 | limitMiB: number; |
| 8 | } |
| 9 | |
| 10 | // Sizes come from File metadata, so a refused file is never read, hashed or |
| 11 | // base64-encoded. |
| 12 | export function splitOversizeAttachments(files: File[]): { accepted: File[]; oversize: OversizeAttachment[] } { |
| 13 | const accepted: File[] = []; |
| 14 | const oversize: OversizeAttachment[] = []; |
| 15 | for (const file of files) { |
| 16 | const limit = file.type.startsWith("image/") ? MAX_IMAGE_ATTACHMENT_BYTES : Infinity; |
| 17 | if (file.size > limit) oversize.push({ file, limitMiB: limit / MIB }); |
| 18 | else accepted.push(file); |
| 19 | } |
| 20 | return { accepted, oversize }; |
| 21 | } |
| 22 |