-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom image thumbnail stream endpoint
- Loading branch information
Showing
9 changed files
with
359 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Image; | ||
|
||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\MappedParameter\ImageDownloadConfigParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query\ContainParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query\CoverParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query\ForceResizeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query\FrameParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query\ImageConfigParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query\MimeTypeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query\ResizeModeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Service\BinaryServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidElementTypeException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ThumbnailResizingFailedException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseHeaders; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions; | ||
use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
use Symfony\Component\HttpFoundation\StreamedResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapQueryString; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CustomStreamController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
private readonly AssetServiceInterface $assetService, | ||
private readonly BinaryServiceInterface $binaryService, | ||
private readonly SecurityServiceInterface $securityService, | ||
SerializerInterface $serializer | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws AccessDeniedException | ||
* @throws NotFoundException | ||
* @throws InvalidElementTypeException | ||
* @throws ThumbnailResizingFailedException | ||
* @throws UserNotFoundException | ||
*/ | ||
#[Route( | ||
'/assets/{id}/image/stream/custom', | ||
name: 'pimcore_studio_api_stream_image_custom', | ||
methods: ['GET'] | ||
)] | ||
#[IsGranted(UserPermissions::ASSETS->value)] | ||
#[Get( | ||
path: self::PREFIX . '/assets/{id}/image/stream/custom', | ||
operationId: 'asset_image_stream_custom', | ||
description: 'asset_image_stream_custom_description', | ||
summary: 'asset_image_stream_custom_summary', | ||
tags: [Tags::Assets->name] | ||
)] | ||
#[IdParameter(type: 'image')] | ||
#[MimeTypeParameter] | ||
#[ResizeModeParameter] | ||
#[ImageConfigParameter('width', 140)] | ||
#[ImageConfigParameter('height')] | ||
#[ImageConfigParameter('quality')] | ||
#[ImageConfigParameter('dpi')] | ||
#[ContainParameter] | ||
#[FrameParameter] | ||
#[CoverParameter] | ||
#[ForceResizeParameter] | ||
#[SuccessResponse( | ||
description: 'asset_image_stream_custom_success_response', | ||
content: [new MediaType('image/*')], | ||
headers: [new ContentDisposition(HttpResponseHeaders::INLINE_TYPE->value)] | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
HttpResponseCodes::NOT_FOUND, | ||
])] | ||
public function streamCustomThumbnailConfig( | ||
int $id, | ||
#[MapQueryString] ImageDownloadConfigParameter $parameters | ||
): StreamedResponse { | ||
$asset = $this->assetService->getAssetElement( | ||
$this->securityService->getCurrentUser(), | ||
$id | ||
); | ||
|
||
return $this->binaryService->streamImageThumbnailFromConfig($asset, $parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Asset/OpenApi/Attribute/Parameter/Query/ContainParameter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\QueryParameter; | ||
use OpenApi\Attributes\Schema; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class ContainParameter extends QueryParameter | ||
{ | ||
public function __construct(string $description = 'Contain', mixed $defaultValue = null) | ||
{ | ||
parent::__construct( | ||
name: 'contain', | ||
description: $description, | ||
in: 'query', | ||
schema: new Schema(type: 'boolean', example: $defaultValue), | ||
); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Asset/OpenApi/Attribute/Parameter/Query/CoverParameter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\QueryParameter; | ||
use OpenApi\Attributes\Schema; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class CoverParameter extends QueryParameter | ||
{ | ||
public function __construct(string $description = 'Cover', mixed $defaultValue = null) | ||
{ | ||
parent::__construct( | ||
name: 'cover', | ||
description: $description, | ||
in: 'query', | ||
schema: new Schema(type: 'boolean', example: $defaultValue), | ||
); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Asset/OpenApi/Attribute/Parameter/Query/ForceResizeParameter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\QueryParameter; | ||
use OpenApi\Attributes\Schema; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class ForceResizeParameter extends QueryParameter | ||
{ | ||
public function __construct(string $description = 'ForceResize', mixed $defaultValue = null) | ||
{ | ||
parent::__construct( | ||
name: 'forceResize', | ||
description: $description, | ||
in: 'query', | ||
schema: new Schema(type: 'boolean', example: $defaultValue), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.