4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-14 05:06:37 +00:00
AzuraCast/src/Controller/Api/Stations/Art/PostArtAction.php
Buster "Silver Eagle" Neece c81ff62b5c
Remove the Song entity and restructure dependent tables accordingly (#3231)
* Song database and entity overhaul, part 1.
* Remove Songs table from a number of qeries and reports.
* Fix references to Songs table; rewrite StationMedia processing.
* Remove song reference in queue page.
* Allow custom log level via environment variable.
2020-10-04 17:35:41 -05:00

47 lines
1.4 KiB
PHP

<?php
namespace App\Controller\Api\Stations\Art;
use App\Entity;
use App\Flysystem\Filesystem;
use App\Http\Response;
use App\Http\ServerRequest;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UploadedFileInterface;
class PostArtAction
{
public function __invoke(
ServerRequest $request,
Response $response,
Filesystem $filesystem,
Entity\Repository\StationMediaRepository $mediaRepo,
EntityManagerInterface $em,
$media_id
): ResponseInterface {
$station = $request->getStation();
$media = $mediaRepo->find($media_id, $station);
if (!($media instanceof Entity\StationMedia)) {
return $response->withStatus(404)
->withJson(new Entity\Api\Error(404, __('Record not found.')));
}
$files = $request->getUploadedFiles();
if (!empty($files['art'])) {
$file = $files['art'];
/** @var UploadedFileInterface $file */
if ($file->getError() === UPLOAD_ERR_OK) {
$mediaRepo->writeAlbumArt($media, $file->getStream()->getContents());
$em->flush();
} elseif ($file->getError() !== UPLOAD_ERR_NO_FILE) {
return $response->withStatus(500)
->withJson(new Entity\Api\Error(500, $file->getError()));
}
}
return $response->withJson(new Entity\Api\Status());
}
}