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
3 changes: 3 additions & 0 deletions config/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\Setting\Service\ElementServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Setting\Service\ElementService

Pimcore\Bundle\StudioBackendBundle\Setting\Service\ThumbnailServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Setting\Service\ThumbnailService

#
# Hydrators
#
Expand Down
12 changes: 12 additions & 0 deletions config/thumbnails.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ services:
# Repositories
#

Pimcore\Bundle\StudioBackendBundle\Thumbnail\Repository\ThumbnailConfigRepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Thumbnail\Repository\ThumbnailConfigRepository

Pimcore\Bundle\StudioBackendBundle\Thumbnail\Repository\ImageThumbnailRepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Thumbnail\Repository\ImageThumbnailRepository

Expand All @@ -34,10 +37,19 @@ services:
Pimcore\Bundle\StudioBackendBundle\Thumbnail\Hydrator\Image\ConfigDetailHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Thumbnail\Hydrator\Image\ConfigDetailHydrator

Pimcore\Bundle\StudioBackendBundle\Thumbnail\Hydrator\Video\ConfigDetailHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Thumbnail\Hydrator\Video\ConfigDetailHydrator

#
# Services
#

Pimcore\Bundle\StudioBackendBundle\Thumbnail\Service\ThumbnailConfigServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Thumbnail\Service\ThumbnailConfigService

Pimcore\Bundle\StudioBackendBundle\Thumbnail\Service\ImageThumbnailServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Thumbnail\Service\ImageThumbnailService

Pimcore\Bundle\StudioBackendBundle\Thumbnail\Service\VideoThumbnailServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Thumbnail\Service\VideoThumbnailService

1 change: 1 addition & 0 deletions doc/05_Additional_Custom_Attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ final class AssetEvent extends AbstractPreResponseEvent
- `pre_response.thumbnail.image_config_detail`
- `pre_response.thumbnail.image_folder`
- `pre_response.thumbnail.video_config`
- `pre_response.thumbnail.video_config_detail`
- `pre_response.thumbnail.video_folder`
- `pre_response.translations`
- `pre_response.translations.import.csv-settings`
Expand Down
59 changes: 59 additions & 0 deletions src/Setting/Controller/ImageAdapterController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\Setting\Controller;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
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\Setting\Service\ThumbnailServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class ImageAdapterController extends AbstractApiController
{
private const string ROUTE = '/settings/adapter/image';

public function __construct(
private readonly ThumbnailServiceInterface $thumbnailService,
SerializerInterface $serializer
) {
parent::__construct($serializer);
}

#[Route(path: self::ROUTE, name: 'pimcore_studio_api_settings_image_adapter', methods: ['GET'])]
#[Get(
path: self::PREFIX . self::ROUTE,
operationId: 'settings_image_adapter_check',
description: 'settings_image_adapter_check_description',
summary: 'settings_image_adapter_check_summary',
tags: [Tags::Settings->value]
)]
#[SuccessResponse(
description: 'settings_image_adapter_check_success_response'
)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
])]
public function checkImageAdapter(): JsonResponse
{
return $this->jsonResponse($this->thumbnailService->isImageAdapterValid());
}
}
63 changes: 63 additions & 0 deletions src/Setting/Controller/VideoAdapterController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\Setting\Controller;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
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\Setting\Service\ThumbnailServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class VideoAdapterController extends AbstractApiController
{
private const string ROUTE = '/settings/adapter/video';

public function __construct(
private readonly ThumbnailServiceInterface $thumbnailService,
SerializerInterface $serializer
) {
parent::__construct($serializer);
}

#[Route(
path: self::ROUTE,
name: 'pimcore_studio_api_settings_video_adapter',
methods: ['GET']
)]
#[Get(
path: self::ROUTE,
operationId: 'settings_video_adapter_check',
description: 'settings_video_adapter_check_description',
summary: 'settings_video_adapter_check_summary',
tags: [Tags::Settings->value]
)]
#[SuccessResponse(
description: 'settings_video_adapter_check_success_response'
)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
])]
public function checkVideoAdapter(): JsonResponse
{
return $this->jsonResponse($this->thumbnailService->isVideoAdapterValid());
}
}
40 changes: 40 additions & 0 deletions src/Setting/Service/ThumbnailService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\Setting\Service;

use Pimcore\Bundle\StaticResolverBundle\Lib\VideoResolverInterface;
use Pimcore\Image\Adapter\GD;
use Pimcore\Image\AdapterInterface;

/**
* @internal
*/
final readonly class ThumbnailService implements ThumbnailServiceInterface
{
public function __construct(
private AdapterInterface $imageAdapter,
private VideoResolverInterface $videoResolver
) {
}

public function isImageAdapterValid(): bool
{
return !$this->imageAdapter instanceof GD;
}

public function isVideoAdapterValid(): bool
{
return $this->videoResolver->isAvailable();
}
}
29 changes: 29 additions & 0 deletions src/Setting/Service/ThumbnailServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\Setting\Service;

interface ThumbnailServiceInterface
{
/**
* Returns true if the image adapter is valid (Imagick).
* Returns false if using GD (fallback with less quality).
*/
public function isImageAdapterValid(): bool;

/**
* Returns true if video processing is available (FFmpeg configured).
* Returns false if video processing is not configured.
*/
public function isVideoAdapterValid(): bool;
}
6 changes: 3 additions & 3 deletions src/Thumbnail/Controller/Video/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Thumbnail\Attribute\Response\Content\ThumbnailsJson;
use Pimcore\Bundle\StudioBackendBundle\Thumbnail\Repository\VideoThumbnailRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\Thumbnail\Service\VideoThumbnailServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
Expand All @@ -38,7 +38,7 @@ final class CollectionController extends AbstractApiController

public function __construct(
SerializerInterface $serializer,
private readonly VideoThumbnailRepositoryInterface $repository,
private readonly VideoThumbnailServiceInterface $service,
) {
parent::__construct($serializer);
}
Expand All @@ -65,7 +65,7 @@ public function __construct(
])]
public function getVideoThumbnails(): JsonResponse
{
$collection = $this->repository->listVideoThumbnails();
$collection = $this->service->listThumbnails();

return $this->jsonResponse(
[
Expand Down
78 changes: 78 additions & 0 deletions src/Thumbnail/Controller/Video/CreateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\Thumbnail\Controller\Video;

use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ElementExistsException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotWriteableException;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Request\ReferenceRequestBody;
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\Thumbnail\Schema\CreateThumbnailConfig;
use Pimcore\Bundle\StudioBackendBundle\Thumbnail\Schema\VideoThumbnailConfigDetail;
use Pimcore\Bundle\StudioBackendBundle\Thumbnail\Service\VideoThumbnailServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class CreateController extends AbstractApiController
{
private const string ROUTE = '/thumbnails/video/config';

public function __construct(
SerializerInterface $serializer,
private readonly VideoThumbnailServiceInterface $videoThumbnailService,
) {
parent::__construct($serializer);
}

/**
* @throws ElementExistsException|NotWriteableException
*/
#[Route(self::ROUTE, name: 'pimcore_studio_api_thumbnails_video_create', methods: ['POST'])]
#[IsGranted(UserPermissions::THUMBNAILS->value)]
#[Post(
path: self::PREFIX . self::ROUTE,
operationId: 'thumbnail_video_create',
description: 'thumbnail_video_create_description',
summary: 'thumbnail_video_create_summary',
tags: [Tags::AssetThumbnails->value]
)]
#[ReferenceRequestBody(CreateThumbnailConfig::class)]
#[SuccessResponse(
description: 'thumbnail_video_create_success_response',
content: new JsonContent(ref: VideoThumbnailConfigDetail::class, type: 'object')
)]
#[DefaultResponses([
HttpResponseCodes::CONFLICT,
HttpResponseCodes::INTERNAL_SERVER_ERROR,
HttpResponseCodes::UNAUTHORIZED,
])]
public function createThumbnail(#[MapRequestPayload] CreateThumbnailConfig $parameters): JsonResponse
{
return $this->jsonResponse(
$this->videoThumbnailService->addThumbnail($parameters->getName())
);
}
}
Loading
Loading