Skip to content

Commit 5c6ea6d

Browse files
committed
Always try and show pre rendered preview
Currently if the following situation happens Server generates preview Server has command removed which allows a preview to be shown Client asks for preview, gets a 404 error when preview exists (Mime checked before preview) This happens more often with documents, or video as the commands are not native PHP, they require a binary on the server. After the fix the following would happen Server generates preview Server has command removed which allows a preview to be shown Client asks for preview, gets preview which has been generated (Mime checked after preview) This would also allow offline generation (for example a docker image containing the extra binaries), allowing a reduction in attack surface of the instance serving the preview data.
1 parent c79fa74 commit 5c6ea6d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/private/Preview/Generator.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
125125
if ($mimeType === null) {
126126
$mimeType = $file->getMimeType();
127127
}
128-
if (!$this->previewManager->isMimeSupported($mimeType)) {
129-
throw new NotFoundException();
130-
}
131128

132129
$previewFolder = $this->getPreviewFolder($file);
133130

@@ -154,7 +151,7 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
154151
$crop = $specification['crop'] ?? false;
155152
$mode = $specification['mode'] ?? IPreview::MODE_FILL;
156153

157-
// If both width and heigth are -1 we just want the max preview
154+
// If both width and height are -1 we just want the max preview
158155
if ($width === -1 && $height === -1) {
159156
$width = $maxWidth;
160157
$height = $maxHeight;
@@ -175,6 +172,10 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
175172
try {
176173
$preview = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType(), $previewVersion);
177174
} catch (NotFoundException $e) {
175+
if (!$this->previewManager->isMimeSupported($mimeType)) {
176+
throw new NotFoundException();
177+
}
178+
178179
if ($maxPreviewImage === null) {
179180
$maxPreviewImage = $this->helper->getImage($maxPreview);
180181
}

0 commit comments

Comments
 (0)