Merge pull-request #2891
This commit is contained in:
commit
eed51aef63
|
|
@ -82,6 +82,31 @@ class FileViewerController extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display file in browser
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function browser()
|
||||
{
|
||||
$file = $this->getFile();
|
||||
$etag = md5($file['path']);
|
||||
$this->response->withContentType($this->helper->file->getBrowserViewType($file['name']));
|
||||
$this->response->withCache(5 * 86400, $etag);
|
||||
|
||||
if ($this->request->getHeader('If-None-Match') === '"'.$etag.'"') {
|
||||
$this->response->status(304);
|
||||
} else {
|
||||
|
||||
try {
|
||||
$this->response->send();
|
||||
$this->objectStorage->output($file['path']);
|
||||
} catch (ObjectStorageException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display image thumbnail
|
||||
*
|
||||
|
|
|
|||
|
|
@ -106,4 +106,23 @@ class FileHelper extends Base
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the browser view mimetype based on the file extension.
|
||||
*
|
||||
* @param $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBrowserViewType($filename)
|
||||
{
|
||||
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
||||
|
||||
switch ($extension) {
|
||||
case 'pdf':
|
||||
return 'application/pdf';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,11 @@
|
|||
<i class="fa fa-eye fa-fw"></i>
|
||||
<?= $this->url->link(t('View file'), 'FileViewerController', 'show', array('project_id' => $project['id'], 'file_id' => $file['id']), false, 'popover') ?>
|
||||
</li>
|
||||
<?php elseif ($this->file->getBrowserViewType($file['name']) !== null): ?>
|
||||
<li>
|
||||
<i class="fa fa-eye fa-fw"></i>
|
||||
<?= $this->url->link(t('View file'), 'FileViewerController', 'browser', array('project_id' => $project['id'], 'file_id' => $file['id']), false, '', '', true) ?>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<li>
|
||||
<i class="fa fa-download fa-fw"></i>
|
||||
|
|
|
|||
Loading…
Reference in New Issue