summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-01-07 11:46:24 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-01-08 20:39:48 +0100
commit87e99651f5d7b0f86bcae2a7366f6ae4f0600a87 (patch)
treec720b16cfb94ce70a1b0b860d4df06f83bcf6fb5
parent50b880edeba3166cd7718c1fb3447f618194337b (diff)
downloadnextcloud-server-87e99651f5d7b0f86bcae2a7366f6ae4f0600a87.tar.gz
nextcloud-server-87e99651f5d7b0f86bcae2a7366f6ae4f0600a87.zip
Only return 1 type
Throw proper exception if we can't get the mimetype for a preview. Catch it later on so we can just return a not found for the preview. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r--lib/private/Preview/Generator.php22
-rw-r--r--lib/private/legacy/image.php5
2 files changed, 20 insertions, 7 deletions
diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php
index 4f9f7f3bc1f..db3b4e87f72 100644
--- a/lib/private/Preview/Generator.php
+++ b/lib/private/Preview/Generator.php
@@ -120,9 +120,13 @@ class Generator {
// Try to get a cached preview. Else generate (and store) one
try {
- $file = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType());
- } catch (NotFoundException $e) {
- $file = $this->generatePreview($previewFolder, $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight);
+ try {
+ $file = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType());
+ } catch (NotFoundException $e) {
+ $file = $this->generatePreview($previewFolder, $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight);
+ }
+ } catch (\InvalidArgumentException $e) {
+ throw new NotFoundException();
}
return $file;
@@ -165,7 +169,14 @@ class Generator {
continue;
}
- $ext = $this->getExtention($preview->dataMimeType());
+ // Try to get the extention.
+ try {
+ $ext = $this->getExtention($preview->dataMimeType());
+ } catch (\InvalidArgumentException $e) {
+ // Just continue to the next iteration if this preview doesn't have a valid mimetype
+ continue;
+ }
+
$path = (string)$preview->width() . '-' . (string)$preview->height() . '-max.' . $ext;
try {
$file = $previewFolder->newFile($path);
@@ -382,6 +393,7 @@ class Generator {
/**
* @param string $mimeType
* @return null|string
+ * @throws \InvalidArgumentException
*/
private function getExtention($mimeType) {
switch ($mimeType) {
@@ -392,7 +404,7 @@ class Generator {
case 'image/gif':
return 'gif';
default:
- return null;
+ throw new \InvalidArgumentException('Not a valid mimetype');
}
}
}
diff --git a/lib/private/legacy/image.php b/lib/private/legacy/image.php
index eb7baf5134c..d132c0e3fd9 100644
--- a/lib/private/legacy/image.php
+++ b/lib/private/legacy/image.php
@@ -318,11 +318,12 @@ class OC_Image implements \OCP\IImage {
}
/**
- * @return null|string Returns the mimetype of the data
+ * @return string Returns the mimetype of the data. Returns the empty string
+ * if the data is not valid.
*/
public function dataMimeType() {
if (!$this->valid()) {
- return null;
+ return '';
}
switch ($this->mimeType) {