From 0f5a501e9ca44ad8a1e79e771a6f8885f458a93c Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Mon, 19 Feb 2024 10:01:06 +0100 Subject: [PATCH] fix: public link download in authenticated context --- .../composables/download/useDownloadFile.ts | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/web-pkg/src/composables/download/useDownloadFile.ts b/packages/web-pkg/src/composables/download/useDownloadFile.ts index 8861d2dda9c..fdaff1e2308 100644 --- a/packages/web-pkg/src/composables/download/useDownloadFile.ts +++ b/packages/web-pkg/src/composables/download/useDownloadFile.ts @@ -24,18 +24,27 @@ export const useDownloadFile = (options?: DownloadFileOptions) => { const { owncloudSdk: client } = clientService const isUserContext = store.getters['runtime/auth/isUserContextReady'] - // construct the url and headers - let url - if (unref(isPublicLinkContext)) { - url = file.downloadURL - } else { - if (version === null) { - url = `${client.helpers._davPath}${file.webDavPath}` - } else { - url = client.fileVersions.getFileVersionUrl(file.fileId, version) + // public links have a pre-signed download url + if (file.downloadURL) { + try { + triggerDownloadWithFilename(file.downloadURL, file.name) + } catch (e) { + console.error(e) + store.dispatch('showErrorMessage', { + title: $gettext('Download failed'), + desc: $gettext('File could not be located'), + errors: [e] + }) } + return } + // construct the download url + const url = + version === null + ? `${client.helpers._davPath}${file.webDavPath}` + : client.fileVersions.getFileVersionUrl(file.fileId, version) + // download with signing enabled if (isUserContext && unref(isUrlSigningEnabled)) { const httpClient = clientService.httpAuthenticated