Skip to content

Commit 6e925fd

Browse files
committed
Asset folder preview: do not render preview images on-the-fly if they do not exist yet - as this could potentially break the entire hosting infrastructure when dealing with huge image files (>500MB)
1 parent 1798225 commit 6e925fd

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Controller/Admin/Asset/AssetController.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,12 +1167,17 @@ public function getImageThumbnailAction(Request $request): BinaryFileResponse|Js
11671167

11681168
if ($request->get('treepreview')) {
11691169
$thumbnailConfig = Asset\Image\Thumbnail\Config::getPreviewConfig();
1170-
if ($request->get('origin') === 'treeNode' && !$image->getThumbnail($thumbnailConfig)->exists()) {
1171-
\Pimcore::getContainer()->get('messenger.bus.pimcore-core')->dispatch(
1172-
new AssetPreviewImageMessage($image->getId())
1173-
);
1170+
$exists = $image->getThumbnail($thumbnailConfig)->exists();
1171+
if(!$exists) {
1172+
if ($request->get('origin') === 'treeNode') {
1173+
\Pimcore::getContainer()->get('messenger.bus.pimcore-core')->dispatch(
1174+
new AssetPreviewImageMessage($image->getId())
1175+
);
11741176

1175-
throw $this->createNotFoundException(sprintf('Tree preview thumbnail not available for asset %s', $image->getId()));
1177+
throw $this->createNotFoundException(sprintf('Tree preview thumbnail not available for asset %s', $image->getId()));
1178+
} elseif($request->get('origin') === 'folderPreview') {
1179+
return new BinaryFileResponse(PIMCORE_WEB_ROOT . '/bundles/pimcoreadmin/img/video-loading.gif');
1180+
}
11761181
}
11771182
}
11781183

@@ -1682,7 +1687,7 @@ public function getFolderContentPreviewAction(Request $request,
16821687
'type' => $asset->getType(),
16831688
'filename' => $asset->getFilename(),
16841689
'filenameDisplay' => htmlspecialchars($filenameDisplay ?? ''),
1685-
'url' => $this->elementService->getThumbnailUrl($asset),
1690+
'url' => $this->elementService->getThumbnailUrl($asset, ['origin' => 'folderPreview']),
16861691
'idPath' => $data['idPath'] = Element\Service::getIdPath($asset),
16871692
];
16881693
}

0 commit comments

Comments
 (0)