diff --git a/CHANGELOG.md b/CHANGELOG.md index fd0bac7d..b0d649d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ All notable changes to this project will be documented in this file. - Added relations checksum feature flag. - Fixes saving issues described in issue where saving resulted in infinite spinner. - Fixed loading of routes containing null string values. +- Fixed thumbnail resolve issue. - Fixed relations checksum test. - Optimized release data fetching. - Optimized list loading. diff --git a/src/State/MediaProvider.php b/src/State/MediaProvider.php index b621a9fa..7ea1be4c 100644 --- a/src/State/MediaProvider.php +++ b/src/State/MediaProvider.php @@ -20,6 +20,8 @@ use App\Repository\SlideRepository; use App\Utils\ValidationUtils; use Liip\ImagineBundle\Imagine\Cache\CacheManager; +use Liip\ImagineBundle\Imagine\Data\DataManager; +use Liip\ImagineBundle\Imagine\Filter\FilterManager; use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Uid\Ulid; @@ -43,6 +45,8 @@ public function __construct( private readonly RequestStack $requestStack, private readonly StorageInterface $storage, private readonly CacheManager $imagineCacheManager, + private readonly DataManager $dataManager, + private readonly FilterManager $filterManager, private readonly iterable $itemExtensions, ProviderInterface $collectionProvider, MediaRepository $entityRepository, @@ -164,7 +168,12 @@ public function toOutput(object $object): MediaDTO } if (str_starts_with($object->getMimeType(), 'image/')) { - $output->thumbnail = $this->imagineCacheManager->getBrowserPath($path, 'thumbnail'); + if (!$this->imagineCacheManager->isStored($path, 'thumbnail')) { + $binary = $this->dataManager->find('thumbnail', $path); + $filteredBinary = $this->filterManager->applyFilter($binary, 'thumbnail'); + $this->imagineCacheManager->store($filteredBinary, $path, 'thumbnail'); + } + $output->thumbnail = $this->imagineCacheManager->resolve($path, 'thumbnail'); } elseif (str_starts_with($object->getMimeType(), 'video/')) { $output->thumbnail = $baseUrl.'/media/thumbnail_video.png'; } else { diff --git a/tests/Api/MediaTest.php b/tests/Api/MediaTest.php index a18189a0..81cb35b5 100644 --- a/tests/Api/MediaTest.php +++ b/tests/Api/MediaTest.php @@ -77,6 +77,21 @@ public function testGetItem(): void // $this->assertMatchesResourceItemJsonSchema(Media::class); } + public function testThumbnailUrlDoesNotContainResolve(): void + { + $client = $this->getAuthenticatedClient(); + $iri = $this->findIriBy(Tenant\Media::class, ['tenant' => $this->tenant]); + + $response = $client->request('GET', $iri, ['headers' => ['Content-Type' => 'application/ld+json']]); + + $this->assertResponseIsSuccessful(); + $responseArray = $response->toArray(); + + $this->assertArrayHasKey('thumbnail', $responseArray); + $this->assertStringContainsString('/media/cache/thumbnail/', $responseArray['thumbnail']); + $this->assertStringNotContainsString('/media/cache/resolve/', $responseArray['thumbnail']); + } + public function testMediaUrlFromForeignTenant(): void { $iri = $this->findIriBy(Tenant\Media::class, ['title' => 'media_def_shared_to_abc']);