Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 15 additions & 11 deletions src/Controller/Admin/Asset/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1192,19 +1192,21 @@ public function getImageThumbnailAction(Request $request): BinaryFileResponse|Js

if ($request->query->get('treepreview')) {
$thumbnailConfig = Asset\Image\Thumbnail\Config::getPreviewConfig();
$exists = $image->getThumbnail($thumbnailConfig)->exists();
if (!$exists) {
if ($request->query->get('origin') === 'treeNode') {
OpenDxp::getContainer()->get('messenger.bus.opendxp-core')->dispatch(
new AssetPreviewImageMessage($image->getId())
);
if (!$image->getThumbnail($thumbnailConfig)->exists()) {

throw $this->createNotFoundException(sprintf('Tree preview thumbnail not available for asset %s', $image->getId()));
}
OpenDxp::getContainer()->get('messenger.bus.opendxp-core')->dispatch(
new AssetPreviewImageMessage($image->getId())
);

if ($request->query->get('origin') === 'folderPreview') {
return new BinaryFileResponse(OPENDXP_WEB_ROOT . '/bundles/opendxpadmin/img/video-loading.gif');

$response = new BinaryFileResponse(OPENDXP_WEB_ROOT . '/bundles/opendxpadmin/img/video-loading.gif');
$response->headers->set('Cache-Control', 'no-store');

return $response;
}

throw $this->createNotFoundException(sprintf('Tree preview thumbnail not available for asset %s', $image->getId()));
}
}

Expand Down Expand Up @@ -1699,15 +1701,17 @@ public function getFolderContentPreviewAction(Request $request,
$filenameDisplay = substr($filenameDisplay, 0, 25) . '...' . pathinfo($filenameDisplay, PATHINFO_EXTENSION);
}

// Like for treeGetChildrenByIdAction, so we respect isAllowed method which can be extended (object DI) for custom permissions, so relying only users_workspaces_asset is insufficient and could lead security breach
// Like for treeGetChildrenByIdAction, so we respect isAllowed method which can be extended (object DI) for custom permissions,
// so relying only users_workspaces_asset is insufficient and could lead security breach
if ($asset->isAllowed('list')) {

$assets[] = [
'id' => $asset->getId(),
'type' => $asset->getType(),
'filename' => $asset->getFilename(),
'filenameDisplay' => htmlspecialchars($filenameDisplay ?? ''),
'url' => $this->elementService->getThumbnailUrl($asset, ['origin' => 'folderPreview']),
'idPath' => $data['idPath'] = Element\Service::getIdPath($asset),
'idPath' => Element\Service::getIdPath($asset),
];
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Service/ElementService.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public function getThumbnailUrl(Asset $asset, array $params = []): ?string
'_dc' => $asset->getModificationDate(),
];

if ($asset instanceof Asset\Image && ($params['origin'] ?? null) === 'folderPreview') {
if (!$asset->getThumbnail(Asset\Image\Thumbnail\Config::getPreviewConfig())->exists()) {
$defaults['_dc'] = time();
}
}

$params = [...$defaults, ...$params];

switch ($asset) {
Expand Down
Loading