From 3793dc8a63ee8f3e3bd867dbd66f92c7ae87764d Mon Sep 17 00:00:00 2001 From: Xiao Gui <xgui3783@gmail.com> Date: Tue, 15 Oct 2019 17:13:46 +0200 Subject: [PATCH] chore: allow downloading of autoradiographs --- deploy/datasets/index.js | 6 ++++++ src/ui/databrowserModule/fileviewer/fileviewer.component.ts | 5 ++++- .../databrowserModule/fileviewer/fileviewer.template.html | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/deploy/datasets/index.js b/deploy/datasets/index.js index 93124730f..1a7bc9912 100644 --- a/deploy/datasets/index.js +++ b/deploy/datasets/index.js @@ -132,6 +132,12 @@ datasetsRouter.get('/previewFile', cacheMaxAge24Hr, (req, res) => { const { file } = req.query const filePath = previewFileMap.get(file) + // Set content type to give browser a hint for download + const ext = path.extname(filePath).slice(1) + const type = express.static.mime.types[ext] + + if (type) res.setHeader('Content-Type', type) + // even though req.url is modified, req.query is not // for now, just serve non encoded image diff --git a/src/ui/databrowserModule/fileviewer/fileviewer.component.ts b/src/ui/databrowserModule/fileviewer/fileviewer.component.ts index 020532d08..642546532 100644 --- a/src/ui/databrowserModule/fileviewer/fileviewer.component.ts +++ b/src/ui/databrowserModule/fileviewer/fileviewer.component.ts @@ -32,7 +32,10 @@ export class FileViewer implements OnChanges{ private cdr: ChangeDetectorRef, @Optional() @Inject(MAT_DIALOG_DATA) data ){ - if (data) this.previewFile = data.previewFile + if (data) { + this.previewFile = data.previewFile + this.downloadUrl = this.previewFile.url + } } public downloadUrl: string diff --git a/src/ui/databrowserModule/fileviewer/fileviewer.template.html b/src/ui/databrowserModule/fileviewer/fileviewer.template.html index ddcde7e8a..cee788c39 100644 --- a/src/ui/databrowserModule/fileviewer/fileviewer.template.html +++ b/src/ui/databrowserModule/fileviewer/fileviewer.template.html @@ -86,6 +86,10 @@ <i class="fas fa-file-csv"></i> </a> + <!-- nb --> + <!-- cross origin download attribute will be ignored --> + <!-- this effective means that when dev on localhost:8080, resource request to localhost:3000 will always open in a new window --> + <!-- link: https://developers.google.com/web/updates/2018/02/chrome-65-deprecations#block_cross-origin_wzxhzdk5a_download --> <a mat-icon-button *ngIf="downloadUrl" [href]="downloadUrl" -- GitLab