From 2f19f94005624d5ffd11485d73a8c78753196e85 Mon Sep 17 00:00:00 2001 From: "Buster \"Silver Eagle\" Neece" Date: Thu, 30 Jun 2022 01:21:27 -0500 Subject: [PATCH] Expand StationFeatures. --- config/menus/station.php | 2 +- config/routes/api_station.php | 76 +++++++++++-------- .../Api/Stations/RequestsController.php | 12 --- src/Controller/Stations/FilesAction.php | 4 +- src/Controller/Stations/PlaylistsAction.php | 5 -- src/Controller/Stations/SftpUsersAction.php | 8 -- src/Controller/Stations/StreamersAction.php | 12 +-- src/Enums/StationFeatures.php | 2 + src/Service/SftpGo.php | 15 ---- 9 files changed, 51 insertions(+), 85 deletions(-) delete mode 100644 src/Service/SftpGo.php diff --git a/config/menus/station.php b/config/menus/station.php index 5582befa6..bbbfe3aa0 100644 --- a/config/menus/station.php +++ b/config/menus/station.php @@ -100,7 +100,7 @@ return function (App\Event\BuildStationMenu $e) { 'label' => __('SFTP Users'), 'class' => 'text-muted', 'url' => (string)$router->fromHere('stations:sftp_users:index'), - 'visible' => App\Service\SftpGo::isSupportedForStation($station), + 'visible' => StationFeatures::Sftp->supportedForStation($station), 'permission' => StationPermissions::Media, ], 'bulk_media' => [ diff --git a/config/routes/api_station.php b/config/routes/api_station.php index b75938b2e..884e5fd21 100644 --- a/config/routes/api_station.php +++ b/config/routes/api_station.php @@ -20,8 +20,7 @@ return static function (RouteCollectorProxy $group) { ['GET', 'POST'], '/nowplaying/update', Controller\Api\Stations\UpdateMetadataAction::class - ) - ->add(new Middleware\Permissions(StationPermissions::Broadcasting, true)); + )->add(new Middleware\Permissions(StationPermissions::Broadcasting, true)); $group->get('/profile', Controller\Api\Stations\ProfileAction::class) ->setName('api:stations:profile') @@ -38,17 +37,12 @@ return static function (RouteCollectorProxy $group) { Controller\Api\Stations\ProfileEditController::class . ':putProfileAction' )->add(new Middleware\Permissions(StationPermissions::Profile, true)); - $group->get('/quota[/{type}]', Controller\Api\Stations\GetQuotaAction::class) - ->setName('api:stations:quota') - ->add(new Middleware\Permissions(StationPermissions::View, true)); - $group->get('/schedule', Controller\Api\Stations\ScheduleAction::class) ->setName('api:stations:schedule'); - $group->get('/history', Controller\Api\Stations\HistoryController::class) - ->setName('api:stations:history') - ->add(new Middleware\Permissions(StationPermissions::Reports, true)); - + /* + * Upcoming Song Queue + */ $group->group( '/queue', function (RouteCollectorProxy $group) { @@ -63,7 +57,11 @@ return static function (RouteCollectorProxy $group) { } )->add(new Middleware\Permissions(StationPermissions::Broadcasting, true)); + /* + * Song Requests + */ $group->get('/requests', Controller\Api\Stations\RequestsController::class . ':listAction') + ->add(new Middleware\StationSupportsFeature(StationFeatures::Requests)) ->setName('api:requests:list'); $group->map( @@ -72,8 +70,12 @@ return static function (RouteCollectorProxy $group) { Controller\Api\Stations\RequestsController::class . ':submitAction' ) ->setName('api:requests:submit') + ->add(new Middleware\StationSupportsFeature(StationFeatures::Requests)) ->add(new Middleware\RateLimit('api', 5, 2)); + /* + * On-Demand Streaming + */ $group->get('/ondemand', Controller\Api\Stations\OnDemand\ListAction::class) ->setName('api:stations:ondemand:list'); @@ -81,27 +83,6 @@ return static function (RouteCollectorProxy $group) { ->setName('api:stations:ondemand:download') ->add(new Middleware\RateLimit('ondemand', 1, 2)); - $group->get('/listeners', Controller\Api\Stations\ListenersAction::class) - ->setName('api:listeners:index') - ->add(new Middleware\Permissions(StationPermissions::Reports, true)); - - $group->get( - '/waveform/{media_id:[a-zA-Z0-9\-]+}.json', - Controller\Api\Stations\Waveform\GetWaveformAction::class - )->setName('api:stations:media:waveform'); - - $group->get('/art/{media_id:[a-zA-Z0-9\-]+}.jpg', Controller\Api\Stations\Art\GetArtAction::class) - ->setName('api:stations:media:art'); - - $group->get('/art/{media_id:[a-zA-Z0-9\-]+}', Controller\Api\Stations\Art\GetArtAction::class) - ->setName('api:stations:media:art-internal'); - - $group->post('/art/{media_id:[a-zA-Z0-9]+}', Controller\Api\Stations\Art\PostArtAction::class) - ->add(new Middleware\Permissions(StationPermissions::Media, true)); - - $group->delete('/art/{media_id:[a-zA-Z0-9]+}', Controller\Api\Stations\Art\DeleteArtAction::class) - ->add(new Middleware\Permissions(StationPermissions::Media, true)); - /* * Podcast Public Pages */ @@ -231,6 +212,28 @@ return static function (RouteCollectorProxy $group) { /* * Files/Media */ + + $group->get('/quota[/{type}]', Controller\Api\Stations\GetQuotaAction::class) + ->setName('api:stations:quota') + ->add(new Middleware\Permissions(StationPermissions::View, true)); + + $group->get( + '/waveform/{media_id:[a-zA-Z0-9\-]+}.json', + Controller\Api\Stations\Waveform\GetWaveformAction::class + )->setName('api:stations:media:waveform'); + + $group->get('/art/{media_id:[a-zA-Z0-9\-]+}.jpg', Controller\Api\Stations\Art\GetArtAction::class) + ->setName('api:stations:media:art'); + + $group->get('/art/{media_id:[a-zA-Z0-9\-]+}', Controller\Api\Stations\Art\GetArtAction::class) + ->setName('api:stations:media:art-internal'); + + $group->post('/art/{media_id:[a-zA-Z0-9]+}', Controller\Api\Stations\Art\PostArtAction::class) + ->add(new Middleware\Permissions(StationPermissions::Media, true)); + + $group->delete('/art/{media_id:[a-zA-Z0-9]+}', Controller\Api\Stations\Art\DeleteArtAction::class) + ->add(new Middleware\Permissions(StationPermissions::Media, true)); + $group->group( '', function (RouteCollectorProxy $group) { @@ -561,6 +564,15 @@ return static function (RouteCollectorProxy $group) { /* * Reports */ + + $group->get('/history', Controller\Api\Stations\HistoryController::class) + ->setName('api:stations:history') + ->add(new Middleware\Permissions(StationPermissions::Reports, true)); + + $group->get('/listeners', Controller\Api\Stations\ListenersAction::class) + ->setName('api:listeners:index') + ->add(new Middleware\Permissions(StationPermissions::Reports, true)); + $group->group( '/reports', function (RouteCollectorProxy $group) { @@ -627,7 +639,7 @@ return static function (RouteCollectorProxy $group) { )->add(new Middleware\Permissions(StationPermissions::Reports, true)); /* - * Streamers Extras + * Streamers */ $group->get( '/streamer/{id}/art', diff --git a/src/Controller/Api/Stations/RequestsController.php b/src/Controller/Api/Stations/RequestsController.php index 633c6a679..70243737c 100644 --- a/src/Controller/Api/Stations/RequestsController.php +++ b/src/Controller/Api/Stations/RequestsController.php @@ -80,12 +80,6 @@ final class RequestsController ): ResponseInterface { $station = $request->getStation(); - // Verify that the station supports requests. - if (!$station->getBackendTypeEnum()->isEnabled() || !$station->getEnableRequests()) { - return $response->withStatus(403) - ->withJson(new Entity\Api\Error(403, __('This station does not accept requests currently.'))); - } - $playlistIds = $this->getRequestablePlaylists($station); $qb = $this->em->createQueryBuilder(); @@ -188,12 +182,6 @@ final class RequestsController ): ResponseInterface { $station = $request->getStation(); - // Verify that the station supports requests. - if (!$station->getBackendTypeEnum()->isEnabled() || !$station->getEnableRequests()) { - return $response->withStatus(403) - ->withJson(new Entity\Api\Error(403, __('This station does not accept requests currently.'))); - } - try { $user = $request->getUser(); } catch (Exception\InvalidRequestAttribute) { diff --git a/src/Controller/Stations/FilesAction.php b/src/Controller/Stations/FilesAction.php index 6b357320f..5dd121377 100644 --- a/src/Controller/Stations/FilesAction.php +++ b/src/Controller/Stations/FilesAction.php @@ -5,10 +5,10 @@ declare(strict_types=1); namespace App\Controller\Stations; use App\Entity; +use App\Enums\StationFeatures; use App\Http\Response; use App\Http\ServerRequest; use App\Media\MimeType; -use App\Service\SftpGo; use Doctrine\ORM\EntityManagerInterface; use Psr\Http\Message\ResponseInterface; @@ -61,7 +61,7 @@ final class FilesAction 'customFields' => $this->customFieldRepo->fetchArray(), 'validMimeTypes' => MimeType::getProcessableTypes(), 'stationTimeZone' => $station->getTimezone(), - 'showSftp' => SftpGo::isSupportedForStation($station), + 'showSftp' => StationFeatures::Sftp->supportedForStation($station), 'sftpUrl' => (string)$router->fromHere('stations:sftp_users:index'), 'supportsImmediateQueue' => $backendEnum->isEnabled(), ], diff --git a/src/Controller/Stations/PlaylistsAction.php b/src/Controller/Stations/PlaylistsAction.php index b57867c6d..59825fe40 100644 --- a/src/Controller/Stations/PlaylistsAction.php +++ b/src/Controller/Stations/PlaylistsAction.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace App\Controller\Stations; use App\Entity\Repository\SettingsRepository; -use App\Exception; use App\Http\Response; use App\Http\ServerRequest; use Psr\Http\Message\ResponseInterface; @@ -24,10 +23,6 @@ final class PlaylistsAction ): ResponseInterface { $station = $request->getStation(); - if (!$station->getBackendTypeEnum()->isEnabled()) { - throw new Exception(__('This feature is not currently supported on this station.')); - } - $settings = $this->settingsRepo->readSettings(); $router = $request->getRouter(); diff --git a/src/Controller/Stations/SftpUsersAction.php b/src/Controller/Stations/SftpUsersAction.php index 7715c1cda..fbae19c01 100644 --- a/src/Controller/Stations/SftpUsersAction.php +++ b/src/Controller/Stations/SftpUsersAction.php @@ -5,11 +5,9 @@ declare(strict_types=1); namespace App\Controller\Stations; use App\Environment; -use App\Exception\StationUnsupportedException; use App\Http\Response; use App\Http\ServerRequest; use App\Service\AzuraCastCentral; -use App\Service\SftpGo; use Psr\Http\Message\ResponseInterface; final class SftpUsersAction @@ -25,12 +23,6 @@ final class SftpUsersAction Response $response, string $station_id ): ResponseInterface { - $station = $request->getStation(); - - if (!SftpGo::isSupportedForStation($station)) { - throw new StationUnsupportedException(__('This feature is not currently supported on this station.')); - } - $baseUrl = $request->getRouter()->getBaseUrl() ->withScheme('sftp') ->withPort(null); diff --git a/src/Controller/Stations/StreamersAction.php b/src/Controller/Stations/StreamersAction.php index bb0eda76f..fa13025b7 100644 --- a/src/Controller/Stations/StreamersAction.php +++ b/src/Controller/Stations/StreamersAction.php @@ -5,10 +5,8 @@ declare(strict_types=1); namespace App\Controller\Stations; use App\Entity; -use App\Exception\StationUnsupportedException; use App\Http\Response; use App\Http\ServerRequest; -use App\Radio\Adapters; use App\Service\AzuraCastCentral; use Psr\Http\Message\ResponseInterface; @@ -16,8 +14,7 @@ final class StreamersAction { public function __construct( private readonly AzuraCastCentral $acCentral, - private readonly Entity\Repository\SettingsRepository $settingsRepo, - private readonly Adapters $adapters, + private readonly Entity\Repository\SettingsRepository $settingsRepo ) { } @@ -27,11 +24,6 @@ final class StreamersAction string $station_id ): ResponseInterface { $station = $request->getStation(); - $backend = $this->adapters->getBackendAdapter($station); - - if (null === $backend || !$station->getEnableStreamers()) { - throw new StationUnsupportedException(); - } $settings = $this->settingsRepo->readSettings(); $backendConfig = $station->getBackendConfig(); @@ -50,7 +42,7 @@ final class StreamersAction 'stationTimeZone' => $station->getTimezone(), 'connectionInfo' => [ 'serverUrl' => $settings->getBaseUrl(), - 'streamPort' => $backend->getStreamPort($station), + 'streamPort' => $backendConfig->getDjPort(), 'ip' => $this->acCentral->getIp(), 'djMountPoint' => $backendConfig->getDjMountPoint(), ], diff --git a/src/Enums/StationFeatures.php b/src/Enums/StationFeatures.php index 9435ab38d..261d1fdbd 100644 --- a/src/Enums/StationFeatures.php +++ b/src/Enums/StationFeatures.php @@ -17,6 +17,7 @@ enum StationFeatures case Streamers; case Webhooks; case Podcasts; + case Requests; public function supportedForStation(Station $station): bool { @@ -28,6 +29,7 @@ enum StationFeatures self::Sftp => $backendEnabled && $station->getMediaStorageLocation()->isLocal(), self::MountPoints => $station->getFrontendTypeEnum()->supportsMounts(), self::HlsStreams => $backendEnabled && $station->getEnableHls(), + self::Requests => $backendEnabled && $station->getEnableRequests(), self::Webhooks, self::Podcasts => true, }; } diff --git a/src/Service/SftpGo.php b/src/Service/SftpGo.php deleted file mode 100644 index 2fb56db5f..000000000 --- a/src/Service/SftpGo.php +++ /dev/null @@ -1,15 +0,0 @@ -getMediaStorageLocation()->isLocal(); - } -}