From 3f3e83c13a9fe7c22dacdccb4bf7925ae6ca55d6 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 12 Sep 2022 15:45:09 -0700 Subject: [PATCH] refactor: move file download logic --- src/components/Timeline.vue | 14 +++++--------- src/services/DavRequests.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index ea916663..f18a36e7 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -851,15 +851,11 @@ export default { await this.deleteFromViewWithAnimation(delIds, updatedDays); }, - /** Download the selected files */ - async downloadSelection() { - if (this.selection.size === 0) { - return; - } - - // Get files to download - const fileInfos = await dav.getFiles([...this.selection].map(p => p.fileid)); - await dav.downloadFiles(fileInfos.map(f => f.filename)); + /** + * Download the currently selected files + */ + downloadSelection() { + dav.downloadFilesByIds([...this.selection].map(p => p.fileid)); }, /** diff --git a/src/services/DavRequests.js b/src/services/DavRequests.js index 343d84fc..a1bbf7d6 100644 --- a/src/services/DavRequests.js +++ b/src/services/DavRequests.js @@ -171,3 +171,17 @@ export async function deleteFile(path) { ) }) } + +/** + * Download the files given by the fileIds + * @param {number[]} fileIds + */ +export async function downloadFilesByIds(fileIds) { + if (fileIds.length === 0) { + return; + } + + // Get files to download + const fileInfos = await getFiles(fileIds); + await downloadFiles(fileInfos.map(f => f.filename)); +}