2017-11-04 02:13:41 +00:00
|
|
|
<?php
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Controller\Api\Stations;
|
2017-11-04 02:13:41 +00:00
|
|
|
|
2018-12-05 07:15:51 +00:00
|
|
|
use App\Radio\Filesystem;
|
2018-08-04 22:05:14 +00:00
|
|
|
use App\Customization;
|
2018-02-01 11:49:40 +00:00
|
|
|
use App\Http\Request;
|
|
|
|
use App\Http\Response;
|
2018-11-17 15:30:28 +00:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2017-11-04 02:13:41 +00:00
|
|
|
|
2018-02-01 11:49:40 +00:00
|
|
|
class MediaController
|
2017-11-04 02:13:41 +00:00
|
|
|
{
|
2018-03-17 02:40:34 +00:00
|
|
|
/** @var Customization */
|
|
|
|
protected $customization;
|
2018-02-01 11:49:40 +00:00
|
|
|
|
2018-12-05 07:15:51 +00:00
|
|
|
/** @var Filesystem */
|
|
|
|
protected $filesystem;
|
|
|
|
|
2018-02-01 11:49:40 +00:00
|
|
|
/**
|
2018-08-19 10:40:05 +00:00
|
|
|
* @param Customization $customization
|
2018-12-05 07:15:51 +00:00
|
|
|
* @param Filesystem $filesystem
|
|
|
|
*
|
|
|
|
* @see \App\Provider\ApiProvider
|
2018-02-01 11:49:40 +00:00
|
|
|
*/
|
2018-12-05 07:15:51 +00:00
|
|
|
public function __construct(Customization $customization, Filesystem $filesystem)
|
2018-02-01 11:49:40 +00:00
|
|
|
{
|
2018-03-17 02:40:34 +00:00
|
|
|
$this->customization = $customization;
|
2018-12-05 07:15:51 +00:00
|
|
|
$this->filesystem = $filesystem;
|
2018-02-01 11:49:40 +00:00
|
|
|
}
|
|
|
|
|
2017-11-04 02:13:41 +00:00
|
|
|
/**
|
2018-09-18 14:09:48 +00:00
|
|
|
* @OA\Get(path="/station/{station_id}/art/{media_id}",
|
2017-11-04 02:13:41 +00:00
|
|
|
* 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(
|
2018-02-17 17:57:40 +00:00
|
|
|
* name="media_id",
|
2018-12-05 07:15:51 +00:00
|
|
|
* description="The station media unique ID",
|
2018-02-17 17:57:40 +00:00
|
|
|
* in="path",
|
2018-09-18 14:09:48 +00:00
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
2018-12-05 07:15:51 +00:00
|
|
|
* type="string"
|
2018-09-18 14:09:48 +00:00
|
|
|
* )
|
2018-02-17 17:57:40 +00:00
|
|
|
* ),
|
2018-12-24 08:47:45 +00:00
|
|
|
* @OA\Response(response=200, description="The requested album artwork"),
|
|
|
|
* @OA\Response(response=404, description="Image not found; generic filler image.")
|
2017-11-04 02:13:41 +00:00
|
|
|
* )
|
|
|
|
*/
|
2018-11-17 15:30:28 +00:00
|
|
|
public function artAction(Request $request, Response $response, $station_id, $media_id): ResponseInterface
|
2017-11-04 02:13:41 +00:00
|
|
|
{
|
2018-12-05 07:15:51 +00:00
|
|
|
$station = $request->getStation();
|
|
|
|
$filesystem = $this->filesystem->getForStation($station);
|
2017-11-04 02:13:41 +00:00
|
|
|
|
2018-12-05 07:15:51 +00:00
|
|
|
$media_path = 'albumart://'.$media_id.'.jpg';
|
2017-11-04 02:13:41 +00:00
|
|
|
|
2018-12-05 07:15:51 +00:00
|
|
|
if ($filesystem->has($media_path)) {
|
2019-02-06 23:40:24 +00:00
|
|
|
$file_meta = $filesystem->getMetadata($media_path);
|
2019-02-07 02:54:18 +00:00
|
|
|
$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);
|
2017-11-04 02:13:41 +00:00
|
|
|
}
|
|
|
|
|
2018-03-17 02:40:34 +00:00
|
|
|
return $response->withRedirect($this->customization->getDefaultAlbumArtUrl(), 302);
|
2017-11-04 02:13:41 +00:00
|
|
|
}
|
2018-08-04 22:05:14 +00:00
|
|
|
}
|