(
groupId: string,
contentItem: { type: ContentType; data: string },
notify = true
)
| 263 | // } |
| 264 | |
| 265 | async downloadMedia( |
| 266 | groupId: string, |
| 267 | contentItem: { type: ContentType; data: string }, |
| 268 | notify = true |
| 269 | ) { |
| 270 | const content = await getContentFromData( |
| 271 | contentItem.type, |
| 272 | contentItem.data |
| 273 | ); |
| 274 | if (!content) return contentItem; |
| 275 | contentItem.data = await content.insertMedia(async (hashes) => { |
| 276 | const attachments = await this.db.attachments.all |
| 277 | .where((eb) => eb("attachments.hash", "in", hashes)) |
| 278 | .items(); |
| 279 | |
| 280 | await this.db.fs().queueDownloads( |
| 281 | attachments.map((a) => ({ |
| 282 | filename: a.hash, |
| 283 | chunkSize: a.chunkSize |
| 284 | })), |
| 285 | groupId, |
| 286 | notify ? { readOnDownload: false } : undefined |
| 287 | ); |
| 288 | |
| 289 | const sources: Record<string, string> = {}; |
| 290 | for (const attachment of attachments) { |
| 291 | const src = await this.db.attachments.read( |
| 292 | attachment.hash, |
| 293 | getOutputType(attachment) |
| 294 | ); |
| 295 | if (!src || typeof src !== "string") continue; |
| 296 | sources[attachment.hash] = src; |
| 297 | } |
| 298 | return sources; |
| 299 | }); |
| 300 | return contentItem; |
| 301 | } |
| 302 | |
| 303 | async removeAttachments(id: string, hashes: string[]) { |
| 304 | const contentItem = await this.get(id); |
no test coverage detected