diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-10-24 17:54:56 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-10-24 17:54:56 -0400 |
commit | 51c333e538cdea9c632558f9ab752dd4c4fa30ae (patch) | |
tree | 6f0027cca95f9aaea854970c3f77ef61516b5e56 /app | |
parent | 1ffea55bd117a07d37009307f8d7393d1392838a (diff) |
Regenerate thumbnails if missing
Diffstat (limited to 'app')
-rw-r--r-- | app/Controller/File.php | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/app/Controller/File.php b/app/Controller/File.php index 3aadf076..4d771e2f 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -109,7 +109,7 @@ class File extends Base } /** - * Return the file content (work only for images) + * Display image * * @access public */ @@ -119,36 +119,38 @@ class File extends Base $task = $this->getTask(); $file = $this->file->getById($this->request->getIntegerParam('file_id')); - if ($file['task_id'] != $task['id']) { - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + if ($file['task_id'] == $task['id']) { + $this->response->contentType($this->file->getImageMimeType($file['name'])); + $this->objectStorage->output($file['path']); } - - $this->response->contentType($this->file->getImageMimeType($file['name'])); - $this->objectStorage->output($file['path']); } catch (ObjectStorageException $e) { $this->logger->error($e->getMessage()); } } /** - * Return image thumbnails + * Display image thumbnails * * @access public */ public function thumbnail() { + $this->response->contentType('image/jpeg'); + try { $task = $this->getTask(); $file = $this->file->getById($this->request->getIntegerParam('file_id')); - if ($file['task_id'] != $task['id']) { - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + if ($file['task_id'] == $task['id']) { + $this->objectStorage->output($this->file->getThumbnailPath($file['path'])); } - - $this->response->contentType('image/jpeg'); - $this->objectStorage->output($this->file->getThumbnailPath($file['path'])); } catch (ObjectStorageException $e) { $this->logger->error($e->getMessage()); + + // Try to generate thumbnail on the fly for images uploaded before Kanboard < 1.0.19 + $data = $this->objectStorage->get($file['path']); + $this->file->generateThumbnailFromData($file['path'], $data); + $this->objectStorage->output($this->file->getThumbnailPath($file['path'])); } } |