diff --git a/services/binary-mirror/index.js b/services/binary-mirror/index.js index 1e19ea85..60b4b65e 100644 --- a/services/binary-mirror/index.js +++ b/services/binary-mirror/index.js @@ -41,6 +41,10 @@ app.get('*', async (req, res) => { return; } + if( req.query.download ) { + res.setHeader('Content-Disposition', `attachment; filename="${path.basename(message.path.split('?')[0])}"`); + } + try { console.log('File request: '+message.path+' with ETag:', etag); await streamFile(message.path, etag, res); diff --git a/services/fin/ucd-lib-client/client/public/elements/pages/record/app-media-download.js b/services/fin/ucd-lib-client/client/public/elements/pages/record/app-media-download.js index 0fb1aa7e..d64d4b79 100644 --- a/services/fin/ucd-lib-client/client/public/elements/pages/record/app-media-download.js +++ b/services/fin/ucd-lib-client/client/public/elements/pages/record/app-media-download.js @@ -507,6 +507,10 @@ export default class AppMediaDownload extends Mixin(LitElement).with( return; } + if( e.currentTarget?.href ) { + e.currentTarget.href = this._appendDownloadParam(e.currentTarget.href); + } + let path = this.rootRecord["@id"].replace(config.fcrepoBasePath, ""); gtag("event", "download", { event_category: "fullset", @@ -524,6 +528,11 @@ export default class AppMediaDownload extends Mixin(LitElement).with( e.preventDefault(); return; } + + if( e.currentTarget?.href ) { + e.currentTarget.href = this._appendDownloadParam(e.currentTarget.href); + } + let path = this.href.replace(config.fcrepoBasePath, ""); gtag("event", "download", { @@ -532,6 +541,12 @@ export default class AppMediaDownload extends Mixin(LitElement).with( value: 1, }); } + + _appendDownloadParam(url) { + if (!url) return url; + if (url.includes('download=')) return url; + return url + (url.includes('?') ? '&' : '?') + 'download=true'; + } } customElements.define("app-media-download", AppMediaDownload);