MCPcopy
hub / github.com/streetwriters/notesnook / downloadMedia

Method downloadMedia

packages/core/src/collections/content.ts:265–301  ·  view source on GitHub ↗
(
    groupId: string,
    contentItem: { type: ContentType; data: string },
    notify = true
  )

Source from the content-addressed store, hash-verified

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);

Callers 3

exportMethod · 0.45
publishMethod · 0.45
exportContentFunction · 0.45

Calls 9

getContentFromDataFunction · 0.85
ebFunction · 0.85
getOutputTypeFunction · 0.85
insertMediaMethod · 0.80
whereMethod · 0.80
queueDownloadsMethod · 0.80
readMethod · 0.65
itemsMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected