diff --git a/src/Controller/DownloadController.php b/src/Controller/DownloadController.php index d0e9589..b83ba9a 100644 --- a/src/Controller/DownloadController.php +++ b/src/Controller/DownloadController.php @@ -5,6 +5,7 @@ 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\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Mercure\HubInterface; use Symfony\Component\Mercure\Update; @@ -21,6 +22,7 @@ class DownloadController extends AbstractController #[Route('/download', name: 'app_download', methods: ['POST'])] public function download( + Request $request, DownloadMediaInput $input, ): Response { $download = $this->downloadRepository->insert( @@ -44,11 +46,11 @@ class DownloadController extends AbstractController } $this->hub->publish(new Update( - 'alerts', + $request->getSession()->get('mercure_alert_topic'), $this->renderView('broadcast/Alert.stream.html.twig', [ 'alert_id' => uniqid(), 'title' => 'Success', - 'message' => 'Added to Queue', + 'message' => '"' . $input->title . '" added to Queue', ]) )); diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index b85a4eb..80e3efe 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -5,6 +5,7 @@ namespace App\Controller; use App\Download\Framework\Repository\DownloadRepository; use App\Tmdb\Tmdb; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; @@ -16,9 +17,10 @@ final class IndexController extends AbstractController ) {} #[Route('/', name: 'app_index')] - public function index(): Response + public function index(Request $request): Response { -// dd($this->getUser()->getActiveDownloads()); + $request->getSession()->set('mercure_alert_topic', 'alerts_' . uniqid()); + return $this->render('index/index.html.twig', [ 'active_downloads' => $this->getUser()->getActiveDownloads(), 'recent_downloads' => $this->getUser()->getDownloads(), diff --git a/src/Controller/TorrentioController.php b/src/Controller/TorrentioController.php index 9a71efa..8218274 100644 --- a/src/Controller/TorrentioController.php +++ b/src/Controller/TorrentioController.php @@ -8,6 +8,7 @@ use App\Torrentio\Action\Input\GetMovieOptionsInput; use App\Torrentio\Action\Input\GetTvShowOptionsInput; use Carbon\Carbon; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Mercure\HubInterface; use Symfony\Component\Mercure\Update; @@ -63,7 +64,7 @@ final class TorrentioController extends AbstractController } #[Route('/torrentio/tvshows/clear/{tmdbId}/{imdbId}/{season?}/{episode?}', name: 'app_clear_torrentio_tvshows')] - public function clearTvShowOptions(GetTvShowOptionsInput $input, CacheInterface $cache): Response + public function clearTvShowOptions(GetTvShowOptionsInput $input, CacheInterface $cache, Request $request): Response { $cacheId = sprintf( "page.torrentio.tvshows.%s.%s.%s.%s", @@ -75,7 +76,7 @@ final class TorrentioController extends AbstractController $cache->delete($cacheId); $this->hub->publish(new Update( - 'alerts', + $request->getSession()->get('mercure_alert_topic'), $this->renderer->render('Alert.stream.html.twig', [ 'alert_id' => uniqid(), 'title' => 'Success', diff --git a/src/Download/Framework/Repository/DownloadRepository.php b/src/Download/Framework/Repository/DownloadRepository.php index b2b6a3f..5b32f74 100644 --- a/src/Download/Framework/Repository/DownloadRepository.php +++ b/src/Download/Framework/Repository/DownloadRepository.php @@ -25,23 +25,27 @@ class DownloadRepository extends ServiceEntityRepository $this->paginator = $paginator; } - public function getCompletePaginated(int $pageNumber = 1, int $perPage = 10) + public function getCompletePaginated(UserInterface $user, int $pageNumber = 1, int $perPage = 10) { $query = $this->createQueryBuilder('d') ->andWhere('d.status IN (:statuses)') + ->andWhere('d.user = :user') ->orderBy('d.id', 'DESC') ->setParameter('statuses', ['Complete']) + ->setParameter('user', $user) ->getQuery(); return $this->paginator->paginate($query, $pageNumber, $perPage); } - public function getActivePaginated(int $pageNumber = 1, int $perPage = 5) + public function getActivePaginated(UserInterface $user, int $pageNumber = 1, int $perPage = 5) { $query = $this->createQueryBuilder('d') ->andWhere('d.status IN (:statuses)') + ->andWhere('d.user = :user') ->orderBy('d.id', 'ASC') ->setParameter('statuses', ['New', 'In Progress']) + ->setParameter('user', $user) ->getQuery(); return $this->paginator->paginate($query, $pageNumber, $perPage); diff --git a/src/Twig/Components/DownloadList.php b/src/Twig/Components/DownloadList.php index d16eacb..f40f84a 100644 --- a/src/Twig/Components/DownloadList.php +++ b/src/Twig/Components/DownloadList.php @@ -22,9 +22,9 @@ final class DownloadList extends AbstractController public function getDownloads() { if ($this->type === "active") { - return $this->downloadRepository->getActivePaginated(); + return $this->downloadRepository->getActivePaginated($this->getUser()); } elseif ($this->type === "complete") { - return $this->downloadRepository->getCompletePaginated(); + return $this->downloadRepository->getCompletePaginated($this->getUser()); } return []; diff --git a/templates/components/Header.html.twig b/templates/components/Header.html.twig index 5771bac..48e98af 100644 --- a/templates/components/Header.html.twig +++ b/templates/components/Header.html.twig @@ -16,7 +16,7 @@ -