43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Download\Action\Input\DownloadMediaInput;
|
|
use App\Download\Framework\Repository\DownloadRepository;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Mercure\HubInterface;
|
|
use Symfony\Component\Messenger\MessageBusInterface;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
class DownloadController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private DownloadRepository $downloadRepository,
|
|
private MessageBusInterface $bus,
|
|
) {}
|
|
|
|
#[Route('/download', name: 'app_download', methods: ['POST'])]
|
|
public function download(
|
|
DownloadMediaInput $input,
|
|
): Response {
|
|
$download = $this->downloadRepository->insert(
|
|
$this->getUser(),
|
|
$input->url,
|
|
$input->title,
|
|
$input->filename,
|
|
$input->imdbId,
|
|
$input->mediaType,
|
|
"",
|
|
);
|
|
$input->downloadId = $download->getId();
|
|
try {
|
|
$this->bus->dispatch($input->toCommand());
|
|
} catch (\Throwable $exception) {
|
|
return $this->json(['error' => $exception->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
return $this->json(['status' => 200, 'message' => 'Added to Queue']);
|
|
}
|
|
}
|