|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * This source file is available under the terms of the |
| 6 | + * Pimcore Open Core License (POCL) |
| 7 | + * Full copyright and license information is available in |
| 8 | + * LICENSE.md which is distributed with this source code. |
| 9 | + * |
| 10 | + * @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com) |
| 11 | + * @license Pimcore Open Core License (POCL) |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Video; |
| 15 | + |
| 16 | +use OpenApi\Attributes\Get; |
| 17 | +use OpenApi\Attributes\JsonContent; |
| 18 | +use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Path\ThumbnailNameParameter; |
| 19 | +use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Video\VideoThumbnailStatus; |
| 20 | +use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; |
| 21 | +use Pimcore\Bundle\StudioBackendBundle\Asset\Service\VideoServiceInterface; |
| 22 | +use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; |
| 23 | +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ForbiddenException; |
| 24 | +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidElementTypeException; |
| 25 | +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidThumbnailException; |
| 26 | +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; |
| 27 | +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; |
| 28 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; |
| 29 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; |
| 30 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; |
| 31 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; |
| 32 | +use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; |
| 33 | +use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes; |
| 34 | +use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions; |
| 35 | +use Symfony\Component\HttpFoundation\JsonResponse; |
| 36 | +use Symfony\Component\Routing\Attribute\Route; |
| 37 | +use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 38 | +use Symfony\Component\Serializer\SerializerInterface; |
| 39 | + |
| 40 | +/** |
| 41 | + * @internal |
| 42 | + */ |
| 43 | +final class ThumbnailStatusController extends AbstractApiController |
| 44 | +{ |
| 45 | + public function __construct( |
| 46 | + SerializerInterface $serializer, |
| 47 | + private readonly AssetServiceInterface $assetService, |
| 48 | + private readonly SecurityServiceInterface $securityService, |
| 49 | + private readonly VideoServiceInterface $videoService, |
| 50 | + ) { |
| 51 | + parent::__construct($serializer); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @throws ForbiddenException |
| 56 | + * @throws InvalidElementTypeException |
| 57 | + * @throws InvalidThumbnailException |
| 58 | + * @throws NotFoundException |
| 59 | + * @throws UserNotFoundException |
| 60 | + */ |
| 61 | + #[Route( |
| 62 | + '/assets/{id}/video/thumbnail/{thumbnailName}/status', |
| 63 | + name: 'pimcore_studio_api_video_thumbnail_status', |
| 64 | + methods: ['GET'] |
| 65 | + )] |
| 66 | + #[IsGranted(UserPermissions::ASSETS->value)] |
| 67 | + #[Get( |
| 68 | + path: self::PREFIX . '/assets/{id}/video/thumbnail/{thumbnailName}/status', |
| 69 | + operationId: 'asset_video_thumbnail_status', |
| 70 | + description: 'asset_video_thumbnail_status_description', |
| 71 | + summary: 'asset_video_thumbnail_status_summary', |
| 72 | + tags: [Tags::Assets->name] |
| 73 | + )] |
| 74 | + #[IdParameter(type: 'video')] |
| 75 | + #[ThumbnailNameParameter] |
| 76 | + #[SuccessResponse( |
| 77 | + description: 'asset_video_thumbnail_status_success_response', |
| 78 | + content: new JsonContent(ref: VideoThumbnailStatus::class) |
| 79 | + )] |
| 80 | + #[DefaultResponses([ |
| 81 | + HttpResponseCodes::BAD_REQUEST, |
| 82 | + HttpResponseCodes::FORBIDDEN, |
| 83 | + HttpResponseCodes::UNAUTHORIZED, |
| 84 | + HttpResponseCodes::NOT_FOUND, |
| 85 | + ])] |
| 86 | + public function getVideoThumbnailStatus(int $id, string $thumbnailName): JsonResponse |
| 87 | + { |
| 88 | + $asset = $this->assetService->getAssetElement( |
| 89 | + $this->securityService->getCurrentUser(), |
| 90 | + $id |
| 91 | + ); |
| 92 | + |
| 93 | + return $this->jsonResponse( |
| 94 | + $this->videoService->getThumbnailStatus($asset, $thumbnailName) |
| 95 | + ); |
| 96 | + } |
| 97 | +} |
0 commit comments