From e725d3c89c2de8d0c8f58c95c32dc3527d1e5f07 Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Wed, 5 Jun 2024 11:13:04 +0200 Subject: [PATCH] Implement file:local_path for download --- src/components/HrefActions.vue | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/components/HrefActions.vue b/src/components/HrefActions.vue index 70ef01265..cf332e371 100644 --- a/src/components/HrefActions.vue +++ b/src/components/HrefActions.vue @@ -119,12 +119,22 @@ export default { } return {}; }, + filename() { + if (typeof this.data['file:local_path'] === 'string') { + return this.getFilename(this.data['file:local_path']); + } + return this.getFilename(this.href); + }, downloadProps() { if (this.hasDownloadButton && !this.useAltDownloadMethod) { - return { + const props = { href: this.href, - target: '_blank' + target: '_blank', }; + if (!this.browserCanOpenFile) { + props.download = this.filename; + } + return props; } return {}; }, @@ -222,6 +232,9 @@ export default { } }, methods: { + getFilename(path) { + return path.split(/[\\/]/).pop(); + }, async altDownload() { if (!window.isSecureContext) { window.location.href = this.href; @@ -273,8 +286,7 @@ export default { throw new Error(msg); } - const name = this.href.substr(this.href.lastIndexOf('/') + 1); - const fileStream = StreamSaver.createWriteStream(name); + const fileStream = StreamSaver.createWriteStream(this.filename); // Prevent the user from leaving the page while the download is in progress // As this is not a normal download a user need to stay on the page for the download to complete