Skip to content

Commit

Permalink
core: add more sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Mar 21, 2024
1 parent 87bec4e commit 45c5e65
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/core/src/collections/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export default class Attachments extends Collection {
async ({ success, filename, groupId, eventData }) => {
if (!success || !eventData || !eventData.readOnDownload) return;
const attachment = this.attachment(filename);
if (!attachment) return;
if (!attachment || !attachment.metadata) return;

const src = await this.read(filename, getOutputType(attachment));
if (!src || !attachment.metadata) return;
if (!src) return;

EV.publish(EVENTS.mediaAttachmentDownloaded, {
groupId,
Expand Down Expand Up @@ -348,6 +348,7 @@ export default class Attachments extends Collection {
async downloadMedia(noteId, hashesToLoad) {
const attachments = this.media.filter(
(attachment) =>
!!attachment.metadata &&
hasItem(attachment.noteIds, noteId) &&
(!hashesToLoad || hasItem(hashesToLoad, attachment.metadata?.hash))
);
Expand Down Expand Up @@ -404,23 +405,30 @@ export default class Attachments extends Collection {
}

get images() {
return this.all.filter((attachment) => isImage(attachment.metadata.type));
return this.all.filter(
(attachment) => attachment.metadata && isImage(attachment.metadata.type)
);
}

get webclips() {
return this.all.filter((attachment) => isWebClip(attachment.metadata.type));
return this.all.filter(
(attachment) => attachment.metadata && isWebClip(attachment.metadata.type)
);
}

get media() {
return this.all.filter(
(attachment) =>
isImage(attachment.metadata.type) || isWebClip(attachment.metadata.type)
attachment.metadata &&
(isImage(attachment.metadata.type) ||
isWebClip(attachment.metadata.type))
);
}

get files() {
return this.all.filter(
(attachment) =>
attachment.metadata &&
!isImage(attachment.metadata.type) &&
!isWebClip(attachment.metadata.type)
);
Expand Down

0 comments on commit 45c5e65

Please sign in to comment.