diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-01-04 10:00:07 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-01-07 11:41:54 +0100 |
commit | 5b216500976019734e67b3edd8b17c8e18c9c8cc (patch) | |
tree | 317639e279432da92108fcd980883c664f932210 /lib/private/Preview/Generator.php | |
parent | f25e51c3691e8dce3c0f6c8ed56f4effa9ebb0dc (diff) | |
download | nextcloud-server-5b216500976019734e67b3edd8b17c8e18c9c8cc.tar.gz nextcloud-server-5b216500976019734e67b3edd8b17c8e18c9c8cc.zip |
Don't lie about the preview mimetype
For legacy reasons we stored all the previews with a png extention.
However we did not put png data in them all the time.
This caused the preview endpoints to always report that a preview is a
png file. Which was a lie.
Since we abstract away from the storage etc in the previewmanager. There
is no need anymore to store them as .png files and instead we can use
the actual file extention.
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Preview/Generator.php')
-rw-r--r-- | lib/private/Preview/Generator.php | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index 402732ecda9..91173d41afa 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -128,7 +128,7 @@ class Generator { // Try to get a cached preview. Else generate (and store) one try { - $file = $this->getCachedPreview($previewFolder, $width, $height, $crop); + $file = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType()); } catch (NotFoundException $e) { $file = $this->generatePreview($previewFolder, $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight); } @@ -173,7 +173,8 @@ class Generator { continue; } - $path = (string)$preview->width() . '-' . (string)$preview->height() . '-max.png'; + $ext = $this->getExtention($preview->dataMimeType()); + $path = (string)$preview->width() . '-' . (string)$preview->height() . '-max.' . $ext; try { $file = $previewFolder->newFile($path); $file->putContent($preview->data()); @@ -201,14 +202,17 @@ class Generator { * @param int $width * @param int $height * @param bool $crop + * @param string $mimeType * @return string */ - private function generatePath($width, $height, $crop) { + private function generatePath($width, $height, $crop, $mimeType) { $path = (string)$width . '-' . (string)$height; if ($crop) { $path .= '-crop'; } - $path .= '.png'; + + $ext = $this->getExtention($mimeType); + $path .= '.' . $ext; return $path; } @@ -340,7 +344,7 @@ class Generator { } - $path = $this->generatePath($width, $height, $crop); + $path = $this->generatePath($width, $height, $crop, $preview->dataMimeType()); try { $file = $previewFolder->newFile($path); $file->putContent($preview->data()); @@ -356,12 +360,13 @@ class Generator { * @param int $width * @param int $height * @param bool $crop + * @param string $mimeType * @return ISimpleFile * * @throws NotFoundException */ - private function getCachedPreview(ISimpleFolder $previewFolder, $width, $height, $crop) { - $path = $this->generatePath($width, $height, $crop); + private function getCachedPreview(ISimpleFolder $previewFolder, $width, $height, $crop, $mimeType) { + $path = $this->generatePath($width, $height, $crop, $mimeType); return $previewFolder->getFile($path); } @@ -381,4 +386,21 @@ class Generator { return $folder; } + + /** + * @param string $mimeType + * @return null|string + */ + private function getExtention($mimeType) { + switch ($mimeType) { + case 'image/png': + return 'png'; + case 'image/jpeg': + return 'jpg'; + case 'image/gif': + return 'gif'; + default: + return null; + } + } } |