Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add function to get note's attachments

thecodrr03bcccdba80a
diff --git a/packages/core/collections/attachments.js b/packages/core/collections/attachments.js
index 6237f605b..b61189d46 100644
--- a/packages/core/collections/attachments.js
+++ b/packages/core/collections/attachments.js
@@ -89,7 +89,13 @@ export default class Attachments extends Collection {
return await this._collection.updateItem(attachment);
}
- async get(hash) {
+ get(noteId) {
+ return this.file.filter((attachment) =>
+ hasItem(attachment.noteIds, noteId)
+ );
+ }
+
+ async read(hash) {
const attachment = this.all.find((a) => a.metadata.hash === hash);
if (!attachment) return;
@@ -183,6 +189,12 @@ export default class Attachments extends Collection {
);
}
+ get file() {
+ return this.all.filter(
+ (attachment) => !attachment.metadata.type.startsWith("image/")
+ );
+ }
+
get all() {
return this._collection.getItems();
}
diff --git a/packages/core/collections/content.js b/packages/core/collections/content.js
index 4474661e7..63f3ab31c 100644
--- a/packages/core/collections/content.js
+++ b/packages/core/collections/content.js
@@ -64,7 +64,7 @@ export default class Content extends Collection {
async insertAttachments(contentItem) {
const content = getContentFromData(contentItem.type, contentItem.data);
contentItem.data = await content.insertAttachments((hash) => {
- return this._db.attachments.get(hash);
+ return this._db.attachments.read(hash);
});
return contentItem;
}