-
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.
[Image Editor] Add endpoint to return original image stream (#642)
* add endpoint to return original image stream * Apply php-cs-fixer changes --------- Co-authored-by: lukmzig <[email protected]>
- Loading branch information
Showing
21 changed files
with
165 additions
and
24 deletions.
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
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,98 @@ | ||
<?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\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\ElementStreamResourceNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidElementTypeException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; | ||
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\StreamedResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class StreamController 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 ElementStreamResourceNotFoundException | ||
* @throws NotFoundException | ||
* @throws InvalidElementTypeException | ||
* @throws UserNotFoundException | ||
*/ | ||
#[Route( | ||
'/assets/{id}/image/stream', | ||
name: 'pimcore_studio_api_stream_image', | ||
methods: ['GET'] | ||
)] | ||
#[IsGranted(UserPermissions::ASSETS->value)] | ||
#[Get( | ||
path: self::PREFIX . '/assets/{id}/image/stream', | ||
operationId: 'asset_image_stream', | ||
description: 'asset_image_stream_description', | ||
summary: 'asset_image_stream_summary', | ||
tags: [Tags::Assets->name] | ||
)] | ||
#[IdParameter(type: 'image')] | ||
#[SuccessResponse( | ||
description: 'asset_image_stream_success_response', | ||
content: [new MediaType('image/*')], | ||
headers: [new ContentDisposition(HttpResponseHeaders::INLINE_TYPE->value)] | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::BAD_REQUEST, | ||
HttpResponseCodes::UNAUTHORIZED, | ||
HttpResponseCodes::NOT_FOUND, | ||
])] | ||
public function streamOriginalImage( | ||
int $id, | ||
): StreamedResponse { | ||
$asset = $this->assetService->getAssetElement( | ||
$this->securityService->getCurrentUser(), | ||
$id | ||
); | ||
|
||
return $this->binaryService->streamImage($asset); | ||
} | ||
} |
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
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
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
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
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
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
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
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
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.