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
feat: send metadata along with download request
thecodrr2c927a5dd7ff
diff --git a/packages/core/collections/attachments.js b/packages/core/collections/attachments.jsindex 97f1656a4..0cdfd3470 100644--- a/packages/core/collections/attachments.js+++ b/packages/core/collections/attachments.js@@ -209,15 +209,17 @@ export default class Attachments extends Collection {);try {for (let i = 0; i < attachments.length; i++) {- const {- metadata: { hash },+ const { metadata, chunkSize } = attachments[i];+ await this._downloadMedia(+ metadata.hash,chunkSize,- } = attachments[i];- await this._downloadMedia(hash, chunkSize, {- total: attachments.length,- current: i,- groupId: noteId,- });+ {+ total: attachments.length,+ current: i,+ groupId: noteId,+ },+ metadata+ );}} finally {sendAttachmentsProgressEvent("download", noteId, attachments.length);@@ -225,16 +227,18 @@ export default class Attachments extends Collection {}async _downloadMedia(- hash,+ filename,chunkSize,{ total, current, groupId },+ metadata,notify = true) {sendAttachmentsProgressEvent("download", groupId, total, current);const isDownloaded = await this._db.fs.downloadFile(groupId,- hash,- chunkSize+ filename,+ chunkSize,+ metadata);if (!isDownloaded) return;diff --git a/packages/core/collections/content.js b/packages/core/collections/content.jsindex 4fc893ad7..8062144a7 100644--- a/packages/core/collections/content.js+++ b/packages/core/collections/content.js@@ -73,13 +73,19 @@ export default class Content extends Collection {async downloadMedia(groupId, contentItem, notify = true) {const content = getContentFromData(contentItem.type, contentItem.data);contentItem.data = await content.insertMedia((hash, { total, current }) => {+ const attachment = this._db.attachments.attachment(hash);+ if (!attachment) return;++ const metadata = attachment.metadata;+ const progressData = {+ total,+ current,+ groupId,+ };return this._db.attachments._downloadMedia(- hash,- {- total,- current,- groupId,- },+ metadata.hash,+ progressData,+ metadata,notify);});diff --git a/packages/core/database/fs.js b/packages/core/database/fs.jsindex 21e12a449..0796776f9 100644--- a/packages/core/database/fs.js+++ b/packages/core/database/fs.js@@ -8,28 +8,29 @@ export default class FileStorage {this._queue = [];}- async downloadFile(groupId, hash, chunkSize) {- const url = `${hosts.API_HOST}/s3?name=${hash}`;+ async downloadFile(groupId, filename, chunkSize, metadata) {+ const url = `${hosts.API_HOST}/s3?name=${filename}`;const token = await this.tokenManager.getAccessToken();- const { execute, cancel } = this.fs.downloadFile(hash, {+ const { execute, cancel } = this.fs.downloadFile(filename, {+ metadata,url,chunkSize,headers: { Authorization: `Bearer ${token}` },});- this._queue.push({ groupId, hash, cancel, type: "download" });+ this._queue.push({ groupId, filename, cancel, type: "download" });const result = await execute();this._deleteOp(groupId, "download");return result;}- async uploadFile(groupId, hash) {+ async uploadFile(groupId, filename) {const token = await this.tokenManager.getAccessToken();- const url = `${hosts.API_HOST}/s3?name=${hash}`;- const { execute, cancel } = this.fs.uploadFile(hash, {+ const url = `${hosts.API_HOST}/s3?name=${filename}`;+ const { execute, cancel } = this.fs.uploadFile(filename, {url,headers: { Authorization: `Bearer ${token}` },});- this._queue.push({ groupId, hash, cancel, type: "upload" });+ this._queue.push({ groupId, filename, cancel, type: "upload" });const result = await execute();this._deleteOp(groupId, "upload");return result;@@ -65,7 +66,7 @@ export default class FileStorage {if (localOnly) return await this.fs.deleteFile(filename);const token = await this.tokenManager.getToken();- const url = `${hosts.API_HOST}/s3?name=${hash}`;+ const url = `${hosts.API_HOST}/s3?name=${filename}`;return await this.fs.deleteFile(filename, {url,headers: { Authorization: `Bearer ${token}` },