Skip to content

Commit 70ce114

Browse files
ndg63276Mark Williamsgfrn
authored
LIMS-1962: Allow downloading of html files (#1006)
* LIMS-1962: Allow downloading of html files * LIMS-1962: Ignore security advisories * Update api/composer.json Co-authored-by: Guilherme Francisco <[email protected]> --------- Co-authored-by: Mark Williams <[email protected]> Co-authored-by: Guilherme Francisco <[email protected]>
1 parent 446e9fb commit 70ce114

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

api/src/Page/Download.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ function _get_file($id, $file)
268268
$response->headers->set("Content-Length", filesize($filename));
269269
} elseif ($filesystem->exists($filename.'.gz')) {
270270
$filename = $filename.'.gz';
271-
if ($this->arg('download') == 1) {
272-
// View log file, so unzip and serve
271+
if ($this->has_arg('download') && $this->arg('download') < 3) {
272+
// View/open file, so unzip and serve
273273
$response = new Response(readgzfile($filename));
274274
$this->set_mime_content($response, $file['FILENAME'], $id);
275275
} else {
@@ -549,21 +549,20 @@ function set_mime_content($response, $filename, $prefix = null)
549549

550550
if (in_array($path_ext, array('html', 'htm'))) {
551551
$response->headers->set("Content-Type", "text/html");
552-
$this->_set_disposition_inline($response);
553552
} elseif ($path_ext == 'pdf') {
554553
$response->headers->set("Content-Type", "application/pdf");
555-
$this->_set_disposition_attachment($response, $saved_filename);
556554
} elseif ($path_ext == 'png') {
557555
$response->headers->set("Content-Type", "image/png");
558-
$this->_set_disposition_attachment($response, $saved_filename);
559556
} elseif (in_array($path_ext, array('jpg', 'jpeg'))) {
560557
$response->headers->set("Content-Type", "image/jpeg");
561-
$this->_set_disposition_attachment($response, $saved_filename);
562-
} elseif (in_array($path_ext, array('log', 'txt', 'error', 'LP', 'json', 'lsa'))) {
558+
} elseif (in_array($path_ext, array('log', 'txt', 'error', 'LP', 'json', 'lsa', 'lst'))) {
563559
$response->headers->set("Content-Type", "text/plain");
564-
$this->_set_disposition_inline($response);
565560
} else {
566561
$response->headers->set("Content-Type", "application/octet-stream");
562+
}
563+
if ($this->has_arg('download') && $this->arg('download') < 3) {
564+
$this->_set_disposition_inline($response);
565+
} else {
567566
$this->_set_disposition_attachment($response, $saved_filename);
568567
}
569568
}

client/src/js/modules/dc/views/autoprocattachments.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ define(['marionette',
7575
var baseDownloadUrl = `${app.apiurl}/download/${this.column.escape('urlRoot')}/attachments/${this.model.escape(this.column.get('idParam'))}`
7676

7777
// Default behaviour for download btn
78-
this.$el.html(`<a href="${baseDownloadUrl}/dl/2" class="button dl"><i class="fa fa-download"/> Download</a>`)
78+
this.$el.html(`<a href="${baseDownloadUrl}/dl/3" class="button dl"><i class="fa fa-download"/> Download</a>`)
7979

8080
// Additional btns per filetype
8181
switch (this.model.get('FILETYPE')) {
8282
case 'Log':
8383
case 'Logfile':
84+
this.$el.append(`<a class="dl button" href="${baseDownloadUrl}/dl/2"><i class="fa fa-file-text-o"/> Open</a>`)
8485
this.$el.append(`<a class="vaplog button" href="${baseDownloadUrl}/dl/1"> <i class="fa fa-search"/> View </a>`);
8586
break;
8687

0 commit comments

Comments
 (0)