Skip to content

Commit

Permalink
Implement file:local_path for download
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Jun 5, 2024
1 parent 999faae commit e725d3c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/components/HrefActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
},
Expand Down Expand Up @@ -222,6 +232,9 @@ export default {
}
},
methods: {
getFilename(path) {
return path.split(/[\\/]/).pop();
},
async altDownload() {
if (!window.isSecureContext) {
window.location.href = this.href;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e725d3c

Please sign in to comment.