diff --git a/src/components/download/TimeSeriesFileDownloadComponent.vue b/src/components/download/TimeSeriesFileDownloadComponent.vue index 29e0cee24..76e48e437 100644 --- a/src/components/download/TimeSeriesFileDownloadComponent.vue +++ b/src/components/download/TimeSeriesFileDownloadComponent.vue @@ -128,9 +128,8 @@ const downloadFile = (downloadFormat: string) => { if (props.filter) { if (isFilterActionsFilter(props.filter)) { const queryParameters = filterToParams(props.filter) - const encodedFileName = encodeURIComponent(fileName.value) const url = new URL( - `${baseUrl}rest/fewspiservice/v1/timeseries/filters/actions${queryParameters}&downloadAsFile=${encodedFileName}&documentFormat=${downloadFormat}${viewPeriod}`, + `${baseUrl}rest/fewspiservice/v1/timeseries/filters/actions${queryParameters}&documentFormat=${downloadFormat}${viewPeriod}`, ) return downloadFileAttachment( url.href, @@ -150,7 +149,6 @@ const downloadFile = (downloadFormat: string) => { timeSeriesDisplayIndex: props.config?.index ?? 0, convertDatum: props.options.convertDatum, useDisplayUnits: props.options.useDisplayUnits, - downloadAsFile: true, } const queryParameters = filterToParams(timeSeriesFilter) const url = new URL( diff --git a/src/lib/download/downloadFiles.ts b/src/lib/download/downloadFiles.ts index 463db9cfc..1551d1a0e 100644 --- a/src/lib/download/downloadFiles.ts +++ b/src/lib/download/downloadFiles.ts @@ -1,6 +1,8 @@ import { DocumentFormat } from '@deltares/fews-pi-requests' function downloadWithLink(url: string, fileName: string) { + const encodedFileName = encodeURIComponent(fileName) + url = `${url}&downloadAsFile=${encodedFileName}` const link = document.createElement('a') link.href = url link.setAttribute('download', fileName) @@ -41,15 +43,15 @@ export async function downloadFileAttachment( ) { try { const headers = new Headers() - let extension: string = 'csv' - if (documentFormat === DocumentFormat.PI_JSON) extension = '.json' - if (documentFormat === DocumentFormat.PI_XML) extension = '.xml' - if (documentFormat === DocumentFormat.PI_CSV) extension = '.csv' - const downloadFileName = fileName + extension - if (accessToken) + if (accessToken) { + let extension: string = 'csv' + if (documentFormat === DocumentFormat.PI_JSON) extension = '.json' + if (documentFormat === DocumentFormat.PI_XML) extension = '.xml' + if (documentFormat === DocumentFormat.PI_CSV) extension = '.csv' + const downloadFileName = fileName + extension await downloadFileWithFetch(headers, url, downloadFileName, accessToken) - if (!accessToken || accessToken == '') - downloadWithLink(url, downloadFileName) + } + if (!accessToken || accessToken == '') downloadWithLink(url, fileName) } catch (error) { console.error('Error downloading file:', error) } diff --git a/src/services/authentication/AuthenticationManager.ts b/src/services/authentication/AuthenticationManager.ts index 75e818a0e..e8e8ae917 100644 --- a/src/services/authentication/AuthenticationManager.ts +++ b/src/services/authentication/AuthenticationManager.ts @@ -18,6 +18,7 @@ export class AuthenticationManager { } public getAccessToken(): string { + if (!configManager.authenticationIsEnabled) return '' if ( configManager.get('VITE_REQUEST_HEADER_AUTHORIZATION') !== RequestHeaderAuthorization.BEARER