* Groups large files needing a Files API upload by storage key so a file referenced across * multiple messages uploads once; the resulting handle is then applied to every occurrence.
(messages: Message[] | undefined)
| 159 | * multiple messages uploads once; the resulting handle is then applied to every occurrence. |
| 160 | */ |
| 161 | function groupUploadableFiles(messages: Message[] | undefined): UserFile[][] { |
| 162 | const groups = new Map<string, UserFile[]>() |
| 163 | for (const message of messages ?? []) { |
| 164 | for (const file of message.files ?? []) { |
| 165 | if (!file.remoteUrl || file.providerFileId || file.providerFileUri) continue |
| 166 | const dedupeKey = file.key || file.remoteUrl |
| 167 | const group = groups.get(dedupeKey) |
| 168 | if (group) group.push(file) |
| 169 | else groups.set(dedupeKey, [file]) |
| 170 | } |
| 171 | } |
| 172 | return [...groups.values()] |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Reads the file bytes straight from storage via the storage SDK (not by HTTP-fetching the |
no test coverage detected