91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller\Api\Stations\Podcasts\Episodes\Art;
|
|
|
|
use App\Controller\SingleActionInterface;
|
|
use App\Entity\Podcast;
|
|
use App\Entity\PodcastEpisode;
|
|
use App\Entity\Repository\StationRepository;
|
|
use App\Flysystem\StationFilesystems;
|
|
use App\Http\Response;
|
|
use App\Http\ServerRequest;
|
|
use App\OpenApi;
|
|
use OpenApi\Attributes as OA;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
#[OA\Get(
|
|
path: '/station/{station_id}/podcast/{podcast_id}/episode/{episode_id}/art',
|
|
operationId: 'getPodcastEpisodeArt',
|
|
description: 'Gets the album art for a podcast episode.',
|
|
security: OpenApi::API_KEY_SECURITY,
|
|
tags: ['Stations: Podcasts'],
|
|
parameters: [
|
|
new OA\Parameter(ref: OpenApi::REF_STATION_ID_REQUIRED),
|
|
new OA\Parameter(
|
|
name: 'podcast_id',
|
|
description: 'Podcast ID',
|
|
in: 'path',
|
|
required: true,
|
|
schema: new OA\Schema(type: 'string')
|
|
),
|
|
new OA\Parameter(
|
|
name: 'episode_id',
|
|
description: 'Podcast Episode ID',
|
|
in: 'path',
|
|
required: true,
|
|
schema: new OA\Schema(type: 'string')
|
|
),
|
|
],
|
|
responses: [
|
|
new OA\Response(
|
|
response: 200,
|
|
description: 'Success'
|
|
),
|
|
new OA\Response(ref: OpenApi::REF_RESPONSE_ACCESS_DENIED, response: 403),
|
|
new OA\Response(ref: OpenApi::REF_RESPONSE_NOT_FOUND, response: 404),
|
|
new OA\Response(ref: OpenApi::REF_RESPONSE_GENERIC_ERROR, response: 500),
|
|
]
|
|
)]
|
|
final class GetArtAction implements SingleActionInterface
|
|
{
|
|
public function __construct(
|
|
private readonly StationRepository $stationRepo,
|
|
private readonly StationFilesystems $stationFilesystems
|
|
) {
|
|
}
|
|
|
|
public function __invoke(
|
|
ServerRequest $request,
|
|
Response $response,
|
|
array $params
|
|
): ResponseInterface {
|
|
/** @var string $podcastId */
|
|
$podcastId = $params['podcast_id'];
|
|
|
|
/** @var string $episodeId */
|
|
$episodeId = $params['episode_id'];
|
|
|
|
$station = $request->getStation();
|
|
|
|
$episodeArtPath = PodcastEpisode::getArtPath($episodeId);
|
|
|
|
$fsPodcasts = $this->stationFilesystems->getPodcastsFilesystem($station);
|
|
if ($fsPodcasts->fileExists($episodeArtPath)) {
|
|
return $response->streamFilesystemFile($fsPodcasts, $episodeArtPath, null, 'inline', false);
|
|
}
|
|
|
|
$podcastArtPath = Podcast::getArtPath($podcastId);
|
|
|
|
if ($fsPodcasts->fileExists($podcastArtPath)) {
|
|
return $response->streamFilesystemFile($fsPodcasts, $podcastArtPath, null, 'inline', false);
|
|
}
|
|
|
|
return $response->withRedirect(
|
|
(string)$this->stationRepo->getDefaultAlbumArtUrl($station),
|
|
302
|
|
);
|
|
}
|
|
}
|