4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-14 21:26:37 +00:00
AzuraCast/src/Controller/Api/Stations/Streamers/Art/GetArtAction.php
2022-05-30 23:23:03 -05:00

45 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Controller\Api\Stations\Streamers\Art;
use App\Entity;
use App\Flysystem\StationFilesystems;
use App\Http\Response;
use App\Http\ServerRequest;
use Psr\Http\Message\ResponseInterface;
final class GetArtAction
{
public function __construct(
private readonly Entity\Repository\StationRepository $stationRepo,
) {
}
public function __invoke(
ServerRequest $request,
Response $response,
string $station_id,
string $streamer_id
): ResponseInterface {
// If a timestamp delimiter is added, strip it automatically.
$streamer_id = explode('|', $streamer_id, 2)[0];
$station = $request->getStation();
$artworkPath = Entity\StationStreamer::getArtworkPath($streamer_id);
$fsConfig = (new StationFilesystems($station))->getConfigFilesystem();
if ($fsConfig->fileExists($artworkPath)) {
return $response->withCacheLifetime(Response::CACHE_ONE_YEAR)
->streamFilesystemFile($fsConfig, $artworkPath, null, 'inline');
}
return $response->withRedirect(
(string)$this->stationRepo->getDefaultAlbumArtUrl($station),
302
);
}
}