feat: add configurable HLS CORS allowlists
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plugin\AzuraCastOnDemandHls\Command;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(name: 'azuracast:ondemand-hls:cors:add', description: 'Add one allowed cross-site HLS origin for a station.')]
|
||||
final class AddCorsOriginCommand extends AbstractCorsCommand
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->configureStationArgument();
|
||||
$this->addArgument('origin', InputArgument::REQUIRED, 'An HTTP(S) origin.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$station = $this->findStation($input, $io);
|
||||
if (null === $station) {
|
||||
return self::FAILURE;
|
||||
}
|
||||
try {
|
||||
$origins = $this->corsConfiguration->addAllowedOrigin($station->id, (string)$input->getArgument('origin'));
|
||||
$this->reloadNginx($station, $io);
|
||||
$io->success('Allowed HLS CORS origin added.');
|
||||
$this->renderOrigins($io, $origins);
|
||||
return self::SUCCESS;
|
||||
} catch (InvalidArgumentException $exception) {
|
||||
$io->error($exception->getMessage());
|
||||
return self::INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user