diff --git a/src/components/Actions/Items/download.jsx b/src/components/Actions/Items/download.jsx index e326d386..4312d9f6 100644 --- a/src/components/Actions/Items/download.jsx +++ b/src/components/Actions/Items/download.jsx @@ -34,7 +34,7 @@ export const download = ({ label, icon, disabled: docs => docs.length === 0, - action: async (docs, { client }) => { + action: async (docs, { client, webviewIntent }) => { const fromMultiSelection = allMultiSelection.length > 0 const normalizedDocs = allMultiSelection.length > 0 @@ -48,7 +48,8 @@ export const download = ({ showAlert, t, pushModal, - popModal + popModal, + webviewIntent }) isMultiSelectionActive && navigate('..') }, diff --git a/src/components/Actions/handleFileDownloading.jsx b/src/components/Actions/handleFileDownloading.jsx index c9cc237d..52488592 100644 --- a/src/components/Actions/handleFileDownloading.jsx +++ b/src/components/Actions/handleFileDownloading.jsx @@ -13,6 +13,7 @@ import { is2SidedFile } from 'src/helpers/is2SidedFile' * @param {Function} params.showAlert - Function to show an alert * @param {Function} params.t - Translation function * @param {boolean} [params.fromMultiSelection] - Whether the action is from a multi-selection + * @param {WebviewService | undefined} [params.webviewIntent] - WebviewIntent used to call methods on FlagshipApp (when hosted in a WebView) */ export const handleFileDownloading = async ({ client, @@ -21,7 +22,8 @@ export const handleFileDownloading = async ({ pushModal, popModal, t, - fromMultiSelection + fromMultiSelection, + webviewIntent }) => { if ( filesWithPage.length === 1 && @@ -37,18 +39,24 @@ export const handleFileDownloading = async ({ textAction={t('action.download')} onClick={selectedChoice => { const selected = onPickSelectedPage(selectedChoice, file) - downloadFiles({ client, t, filesWithPage: selected, showAlert }) + downloadFiles({ + client, + t, + filesWithPage: selected, + showAlert, + webviewIntent + }) }} onClose={popModal} /> ) } else { - downloadFiles({ client, t, filesWithPage, showAlert }) + downloadFiles({ client, t, filesWithPage, showAlert, webviewIntent }) } return } if (filesWithPage.length > 0) { - downloadFiles({ client, t, filesWithPage, showAlert }) + downloadFiles({ client, t, filesWithPage, showAlert, webviewIntent }) } } diff --git a/src/components/Actions/utils.js b/src/components/Actions/utils.js index 326a8966..110c7ac7 100644 --- a/src/components/Actions/utils.js +++ b/src/components/Actions/utils.js @@ -8,7 +8,7 @@ import { handleConflictFilename } from 'src/helpers/handleConflictFilename' import { isReferencedBy } from 'cozy-client' import { getDisplayName } from 'cozy-client/dist/models/contact' -import { splitFilename } from 'cozy-client/dist/models/file' +import { downloadFile, splitFilename } from 'cozy-client/dist/models/file' import { getSharingLink } from 'cozy-client/dist/models/sharing' export const isAnyFileReferencedBy = (files, doctype) => { @@ -200,20 +200,15 @@ export const downloadFiles = async ({ client, filesWithPage, showAlert, - t + t, + webviewIntent }) => { try { const fileCollection = client.collection(FILES_DOCTYPE) if (filesWithPage.length === 1) { const { file, page } = filesWithPage[0] if (filesWithPage[0].page === null) { - const filename = file.name - const downloadURL = await fileCollection.getDownloadLinkById( - file.id, - filename - ) - - return fileCollection.forceFileDownload(`${downloadURL}?Dl=1`, filename) + return await downloadFile({ client, file, webviewIntent }) } else { const filename = makeFilenameWithPage({ file, page, t }) const bin = await getPdfPage({