Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
If the preview is size 0 it is invalid
* delete it
* throw a NotFound Exception
  - This should a proper 404 to the user
  - Next time it is then regenerated

Signed-off-by: Roeland Jago Douma <[email protected]>
  • Loading branch information
rullzer committed Jan 24, 2018
commit f259e1cb8c03369e454810c5436e2f6b4444fa8d
16 changes: 13 additions & 3 deletions lib/private/Preview/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false,

// Get the max preview and infer the max preview sizes from that
$maxPreview = $this->getMaxPreview($previewFolder, $file, $mimeType);
if ($maxPreview->getSize() === 0) {
$maxPreview->delete();
throw new NotFoundException('Max preview size 0, invalid!');
}

list($maxWidth, $maxHeight) = $this->getPreviewSize($maxPreview);

// If both width and heigth are -1 we just want the max preview
Expand All @@ -129,15 +134,20 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false,
// Try to get a cached preview. Else generate (and store) one
try {
try {
$file = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType());
$preview = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType());
} catch (NotFoundException $e) {
$file = $this->generatePreview($previewFolder, $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight);
$preview = $this->generatePreview($previewFolder, $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight);
}
} catch (\InvalidArgumentException $e) {
throw new NotFoundException();
}

return $file;
if ($preview->getSize() === 0) {
$preview->delete();
throw new NotFoundException('Cached preview size 0, invalid!');
}

return $preview;
}

/**
Expand Down