Skip to content

Commit 9d139f0

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 5e3d6f2 commit 9d139f0

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
@@ -1213,12 +1213,17 @@ public function getImageThumbnailAction(Request $request): BinaryFileResponse|Js
12131213

12141214
if ($request->get('treepreview')) {
12151215
$thumbnailConfig = Asset\Image\Thumbnail\Config::getPreviewConfig();
1216-
if ($request->get('origin') === 'treeNode' && !$image->getThumbnail($thumbnailConfig)->exists()) {
1217-
\Pimcore::getContainer()->get('messenger.bus.pimcore-core')->dispatch(
1218-
new AssetPreviewImageMessage($image->getId())
1219-
);
1216+
$exists = $image->getThumbnail($thumbnailConfig)->exists();
1217+
if(!$exists) {
1218+
if ($request->get('origin') === 'treeNode') {
1219+
\Pimcore::getContainer()->get('messenger.bus.pimcore-core')->dispatch(
1220+
new AssetPreviewImageMessage($image->getId())
1221+
);
12201222

1221-
throw $this->createNotFoundException(sprintf('Tree preview thumbnail not available for asset %s', $image->getId()));
1223+
throw $this->createNotFoundException(sprintf('Tree preview thumbnail not available for asset %s', $image->getId()));
1224+
} elseif($request->get('origin') === 'folderPreview') {
1225+
return new BinaryFileResponse(PIMCORE_WEB_ROOT . '/bundles/pimcoreadmin/img/video-loading.gif');
1226+
}
12221227
}
12231228
}
12241229

@@ -1744,7 +1749,7 @@ public function getFolderContentPreviewAction(Request $request,
17441749
'type' => $asset->getType(),
17451750
'filename' => $asset->getFilename(),
17461751
'filenameDisplay' => htmlspecialchars($filenameDisplay ?? ''),
1747-
'url' => $this->elementService->getThumbnailUrl($asset),
1752+
'url' => $this->elementService->getThumbnailUrl($asset, ['origin' => 'folderPreview']),
17481753
'idPath' => $data['idPath'] = Element\Service::getIdPath($asset),
17491754
];
17501755
}

0 commit comments

Comments
 (0)