Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions services/binary-mirror/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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", {
Expand All @@ -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);