A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: handle chunkSize
thecodrr36597616cc7a
diff --git a/packages/core/collections/attachments.js b/packages/core/collections/attachments.jsindex 947658051..e87102739 100644--- a/packages/core/collections/attachments.js+++ b/packages/core/collections/attachments.js@@ -28,6 +28,7 @@ export default class Attachments extends Collection {* filename: string,* type: string,* salt: string,+ * chunkSize: number,* key: {}* }} attachment* @param {string} noteId Optional as attachments will be parsed at extraction time@@ -49,8 +50,18 @@ export default class Attachments extends Collection {return this._collection.updateItem(oldAttachment);}- const { iv, length, alg, hash, hashType, filename, salt, type, key } =- attachment;+ const {+ iv,+ length,+ alg,+ hash,+ hashType,+ filename,+ salt,+ type,+ key,+ chunkSize,+ } = attachment;if (!iv ||@@ -60,6 +71,7 @@ export default class Attachments extends Collection {!hashType ||!filename ||!salt ||+ !chunkSize ||!key) {console.error("Attachment invalid:", attachment);@@ -76,6 +88,7 @@ export default class Attachments extends Collection {length,alg,key: encryptedKey,+ chunkSize,metadata: {hash,hashType,@@ -160,6 +173,7 @@ export default class Attachments extends Collection {attachment.metadata.hash,key,{+ chunkSize: attachment.chunkSize,iv: attachment.iv,salt: attachment.salt,length: attachment.length,@@ -195,8 +209,11 @@ export default class Attachments extends Collection {);try {for (let i = 0; i < attachments.length; i++) {- const { hash } = attachments[i].metadata;- await this._downloadMedia(hash, {+ const {+ metadata: { hash },+ chunkSize,+ } = attachments[i];+ await this._downloadMedia(hash, chunkSize, {total: attachments.length,current: i,groupId: noteId,@@ -207,9 +224,18 @@ export default class Attachments extends Collection {}}- async _downloadMedia(hash, { total, current, groupId }, notify = true) {+ async _downloadMedia(+ hash,+ chunkSize,+ { total, current, groupId },+ notify = true+ ) {sendAttachmentsProgressEvent("download", groupId, total, current + 1);- const isDownloaded = await this._db.fs.downloadFile(groupId, hash);+ const isDownloaded = await this._db.fs.downloadFile(+ groupId,+ hash,+ chunkSize+ );if (!isDownloaded) return;const src = await this.read(hash);@@ -281,7 +307,7 @@ export default class Attachments extends Collection {* @private*/async _getEncryptionKey() {- if (!this.key) this.key = await this._db.user.getAttachmentsKey();+ this.key = await this._db.user.getAttachmentsKey();if (!this.key)throw new Error("Failed to get user encryption key. Cannot cache attachments."diff --git a/packages/core/collections/content.js b/packages/core/collections/content.jsindex f632d80b7..d0fae2f41 100644--- a/packages/core/collections/content.js+++ b/packages/core/collections/content.js@@ -115,10 +115,8 @@ export default class Content extends Collection {return attachments.every((a) => a.hash !== attachment.metadata.hash);});- const toAdd = attachments.filter((a) => {- return noteAttachments.every(- (attachment) => a.hash !== attachment.metadata.hash- );+ const toAdd = attachments.filter((attachment) => {+ return noteAttachments.every((a) => attachment.hash !== a.metadata.hash);});for (let attachment of toDelete) {diff --git a/packages/core/content-types/tiny.js b/packages/core/content-types/tiny.jsindex d8482ab3a..1f9e4d9d0 100644--- a/packages/core/content-types/tiny.js+++ b/packages/core/content-types/tiny.js@@ -120,7 +120,7 @@ class Tiny {break;}default: {- if (!getDatasetAttribute(attachment, "hash")) return;+ if (!getDatasetAttribute(attachment, "hash")) continue;attachments.push({hash: getDatasetAttribute(attachment, "hash"),});diff --git a/packages/core/database/fs.js b/packages/core/database/fs.jsindex 745729282..03990d8fe 100644--- a/packages/core/database/fs.js+++ b/packages/core/database/fs.js@@ -8,11 +8,12 @@ export default class FileStorage {this._queue = [];}- async downloadFile(groupId, hash) {+ async downloadFile(groupId, hash, chunkSize) {const url = `${hosts.API_HOST}/s3?name=${hash}`;const token = await this.tokenManager.getAccessToken();const { execute, cancel } = this.fs.downloadFile(hash, {url,+ chunkSize,headers: { Authorization: `Bearer ${token}` },});this._queue.push({ groupId, hash, cancel, type: "download" });