From 89feb0ae03c5a492526df077b2a3b382b0428ca8 Mon Sep 17 00:00:00 2001 From: phecho Date: Tue, 13 Dec 2016 19:49:16 +0800 Subject: Implement feature #2843 --- app/Controller/FileViewerController.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'app/Controller/FileViewerController.php') diff --git a/app/Controller/FileViewerController.php b/app/Controller/FileViewerController.php index 518f5b0b..3e0182ba 100644 --- a/app/Controller/FileViewerController.php +++ b/app/Controller/FileViewerController.php @@ -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 * -- cgit v1.2.3