4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-12 20:26:43 +00:00
AzuraCast/src/Controller/Api/Stations/MediaController.php

69 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Controller\Api\Stations;
use App\Radio\Filesystem;
use App\Customization;
use App\Http\Request;
use App\Http\Response;
use Psr\Http\Message\ResponseInterface;
class MediaController
{
/** @var Customization */
protected $customization;
/** @var Filesystem */
protected $filesystem;
/**
2018-08-19 10:40:05 +00:00
* @param Customization $customization
* @param Filesystem $filesystem
*
* @see \App\Provider\ApiProvider
*/
public function __construct(Customization $customization, Filesystem $filesystem)
{
$this->customization = $customization;
$this->filesystem = $filesystem;
}
/**
2018-09-18 14:09:48 +00:00
* @OA\Get(path="/station/{station_id}/art/{media_id}",
* tags={"Stations: Media"},
* description="Returns the album art for a song, or a generic image.",
2018-09-18 14:09:48 +00:00
* @OA\Parameter(ref="#/components/parameters/station_id_required"),
* @OA\Parameter(
* name="media_id",
* description="The station media unique ID",
* in="path",
2018-09-18 14:09:48 +00:00
* required=true,
* @OA\Schema(
* type="string"
2018-09-18 14:09:48 +00:00
* )
* ),
* @OA\Response(response=200, description="The requested album artwork"),
* @OA\Response(response=404, description="Image not found; generic filler image.")
* )
*/
public function artAction(Request $request, Response $response, $station_id, $media_id): ResponseInterface
{
$station = $request->getStation();
$filesystem = $this->filesystem->getForStation($station);
$media_path = 'albumart://'.$media_id.'.jpg';
if ($filesystem->has($media_path)) {
$file_meta = $filesystem->getMetadata($media_path);
$art = $filesystem->read($media_path);
2019-02-07 02:57:49 +00:00
return $response
->withHeader('Content-Type', 'image/jpeg')
->withHeader('Content-Length', $file_meta['size'])
->withCacheLifetime(Response::CACHE_ONE_YEAR)
->write($art);
}
return $response->withRedirect($this->customization->getDefaultAlbumArtUrl(), 302);
}
}