From 888a030680e73593f4d9460646d0f0bc8e4ebb03 Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Mon, 12 May 2025 11:23:03 -0500 Subject: [PATCH] fix: broken download, added to queue alert, download list component; feat: monitor list --- compose.yml | 2 +- src/Controller/AlertController.php | 2 +- src/Controller/DownloadController.php | 15 ++++ src/Controller/TorrentioController.php | 2 +- .../Action/Handler/DownloadMediaHandler.php | 2 + .../Action/Input/DownloadMediaInput.php | 2 +- .../Framework/Controller/ApiController.php | 2 +- src/Twig/Components/ActiveDownloadList.php | 25 ------- src/Twig/Components/DownloadList.php | 23 ++++++ src/Twig/Components/MonitorList.php | 20 ++++++ src/User/Framework/Entity/User.php | 34 +++++---- .../Framework/Security/LdapUserProvider.php | 2 +- ...Alert.html.twig => Alert.stream.html.twig} | 0 templates/broadcast/Download.stream.html.twig | 36 ++++++---- ...dList.html.twig => DownloadList.html.twig} | 25 ++++--- templates/components/MonitorList.html.twig | 71 +++++++++++++++++++ templates/index/index.html.twig | 49 ++----------- 17 files changed, 205 insertions(+), 107 deletions(-) delete mode 100644 src/Twig/Components/ActiveDownloadList.php create mode 100644 src/Twig/Components/DownloadList.php create mode 100644 src/Twig/Components/MonitorList.php rename templates/broadcast/{Alert.html.twig => Alert.stream.html.twig} (100%) rename templates/components/{ActiveDownloadList.html.twig => DownloadList.html.twig} (54%) create mode 100644 templates/components/MonitorList.html.twig diff --git a/compose.yml b/compose.yml index 0fba679..e750ecb 100755 --- a/compose.yml +++ b/compose.yml @@ -29,7 +29,7 @@ services: volumes: - ./:/var/www - ./var/download:/var/download - command: php ./bin/console messenger:consume async -vv --time-limit=3600 + command: php ./bin/console messenger:consume async -vvv --time-limit=3600 scheduler: build: . diff --git a/src/Controller/AlertController.php b/src/Controller/AlertController.php index 91204ff..62068bb 100644 --- a/src/Controller/AlertController.php +++ b/src/Controller/AlertController.php @@ -22,7 +22,7 @@ final class AlertController extends AbstractController { $update = new Update( 'alerts', - $this->renderer->render('broadcast/Alert.html.twig', [ + $this->renderer->render('Alert.stream.html.twig', [ 'alert_id' => 1, 'title' => 'Added to queue', 'message' => 'This is a testy test!', diff --git a/src/Controller/DownloadController.php b/src/Controller/DownloadController.php index fbf9f60..d0e9589 100644 --- a/src/Controller/DownloadController.php +++ b/src/Controller/DownloadController.php @@ -7,6 +7,7 @@ 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\Mercure\Update; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Routing\Attribute\Route; @@ -15,6 +16,7 @@ class DownloadController extends AbstractController public function __construct( private DownloadRepository $downloadRepository, private MessageBusInterface $bus, + private readonly HubInterface $hub, ) {} #[Route('/download', name: 'app_download', methods: ['POST'])] @@ -30,13 +32,26 @@ class DownloadController extends AbstractController $input->mediaType, "", ); + $this->downloadRepository->getEntityManager()->persist($download); + $this->downloadRepository->getEntityManager()->flush(); $input->downloadId = $download->getId(); + $input->userId = $this->getUser()->getId(); + try { $this->bus->dispatch($input->toCommand()); } catch (\Throwable $exception) { return $this->json(['error' => $exception->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR); } + $this->hub->publish(new Update( + 'alerts', + $this->renderView('broadcast/Alert.stream.html.twig', [ + 'alert_id' => uniqid(), + 'title' => 'Success', + 'message' => 'Added to Queue', + ]) + )); + return $this->json(['status' => 200, 'message' => 'Added to Queue']); } } diff --git a/src/Controller/TorrentioController.php b/src/Controller/TorrentioController.php index bfe38ae..9a71efa 100644 --- a/src/Controller/TorrentioController.php +++ b/src/Controller/TorrentioController.php @@ -76,7 +76,7 @@ final class TorrentioController extends AbstractController $this->hub->publish(new Update( 'alerts', - $this->renderer->render('broadcast/Alert.html.twig', [ + $this->renderer->render('Alert.stream.html.twig', [ 'alert_id' => uniqid(), 'title' => 'Success', 'message' => 'Torrentio cache Cleared.', diff --git a/src/Download/Action/Handler/DownloadMediaHandler.php b/src/Download/Action/Handler/DownloadMediaHandler.php index 6207f51..4e27337 100644 --- a/src/Download/Action/Handler/DownloadMediaHandler.php +++ b/src/Download/Action/Handler/DownloadMediaHandler.php @@ -37,6 +37,8 @@ readonly class DownloadMediaHandler implements HandlerInterface $download = $this->downloadRepository->find($command->downloadId); } + dump($download); + try { $this->downloadRepository->updateStatus($download->getId(), 'In Progress'); diff --git a/src/Download/Action/Input/DownloadMediaInput.php b/src/Download/Action/Input/DownloadMediaInput.php index 37b17cb..ebb6a4d 100644 --- a/src/Download/Action/Input/DownloadMediaInput.php +++ b/src/Download/Action/Input/DownloadMediaInput.php @@ -39,8 +39,8 @@ class DownloadMediaInput implements InputInterface $this->filename, $this->mediaType, $this->imdbId, + $this->userId, $this->downloadId, - $this->userId ); } } \ No newline at end of file diff --git a/src/Monitor/Framework/Controller/ApiController.php b/src/Monitor/Framework/Controller/ApiController.php index d8d41bb..a9cd133 100644 --- a/src/Monitor/Framework/Controller/ApiController.php +++ b/src/Monitor/Framework/Controller/ApiController.php @@ -33,7 +33,7 @@ class ApiController extends AbstractController $hub->publish(new Update( 'alerts', - $this->renderer->render('broadcast/Alert.html.twig', [ + $this->renderer->render('Alert.stream.html.twig', [ 'alert_id' => uniqid(), 'title' => 'Success', 'message' => "New monitor added for {$input->title}", diff --git a/src/Twig/Components/ActiveDownloadList.php b/src/Twig/Components/ActiveDownloadList.php deleted file mode 100644 index 273354b..0000000 --- a/src/Twig/Components/ActiveDownloadList.php +++ /dev/null @@ -1,25 +0,0 @@ -getUser()->getActiveDownloads(); - } -} diff --git a/src/Twig/Components/DownloadList.php b/src/Twig/Components/DownloadList.php new file mode 100644 index 0000000..cf5a67c --- /dev/null +++ b/src/Twig/Components/DownloadList.php @@ -0,0 +1,23 @@ +type === "active") { + return $this->getUser()->queryDownloads('in-progress', 5); + } elseif ($this->type === "complete") { + return $this->getUser()->queryDownloads('complete', 5); + } + + return []; + } +} diff --git a/src/Twig/Components/MonitorList.php b/src/Twig/Components/MonitorList.php new file mode 100644 index 0000000..a8a203b --- /dev/null +++ b/src/Twig/Components/MonitorList.php @@ -0,0 +1,20 @@ +getUser()->getMonitors(); + } +} diff --git a/src/User/Framework/Entity/User.php b/src/User/Framework/Entity/User.php index 2226705..20c0f23 100644 --- a/src/User/Framework/Entity/User.php +++ b/src/User/Framework/Entity/User.php @@ -48,7 +48,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface * @var Collection */ #[ORM\OneToMany(targetEntity: Monitor::class, mappedBy: 'user', orphanRemoval: true)] - private Collection $yes; + private Collection $monitors; /** * @var Collection @@ -59,7 +59,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface public function __construct() { $this->userPreferences = new ArrayCollection(); - $this->yes = new ArrayCollection(); + $this->monitors = new ArrayCollection(); $this->downloads = new ArrayCollection(); } @@ -226,27 +226,27 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface /** * @return Collection */ - public function getYes(): Collection + public function getMonitors(): Collection { - return $this->yes; + return $this->monitors; } - public function addYe(Monitor $ye): static + public function addMonitor(Monitor $monitor): static { - if (!$this->yes->contains($ye)) { - $this->yes->add($ye); - $ye->setUser($this); + if (!$this->monitors->contains($monitor)) { + $this->monitors->add($monitor); + $monitor->setUser($this); } return $this; } - public function removeYe(Monitor $ye): static + public function removeMonitor(Monitor $monitor): static { - if ($this->yes->removeElement($ye)) { + if ($this->monitors->removeElement($monitor)) { // set the owning side to null (unless already changed) - if ($ye->getUser() === $this) { - $ye->setUser(null); + if ($monitor->getUser() === $this) { + $monitor->setUser(null); } } @@ -302,4 +302,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + + public function queryDownloads(string $type = 'complete', int $limit = 5) + { + if ($type === 'complete') { + return $this->downloads->filter(fn($item) => in_array($item->getStatus(), ['Complete']))->slice(0, $limit); + } elseif ($type === 'in-progress') { + return $this->downloads->filter(fn($item) => in_array($item->getStatus(), ['New', 'In Progress']))->slice(0, $limit); + } + return []; + } } diff --git a/src/User/Framework/Security/LdapUserProvider.php b/src/User/Framework/Security/LdapUserProvider.php index 6218939..6164e42 100644 --- a/src/User/Framework/Security/LdapUserProvider.php +++ b/src/User/Framework/Security/LdapUserProvider.php @@ -167,7 +167,7 @@ class LdapUserProvider implements UserProviderInterface, PasswordUpgraderInterfa ->setName( $this->getAttributeValue($entry, $this->displayNameAttribute)[0] ?? null) ->setEmail($this->getAttributeValue($entry, $this->emailAttribute)[0] ?? null) ->setUsername($this->getAttributeValue($entry, $this->usernameAttribute) ?? null); - + $this->userRepository->getEntityManager()->persist($dbUser); $this->userRepository->getEntityManager()->flush(); diff --git a/templates/broadcast/Alert.html.twig b/templates/broadcast/Alert.stream.html.twig similarity index 100% rename from templates/broadcast/Alert.html.twig rename to templates/broadcast/Alert.stream.html.twig diff --git a/templates/broadcast/Download.stream.html.twig b/templates/broadcast/Download.stream.html.twig index 8ee5ddb..4fcfb39 100644 --- a/templates/broadcast/Download.stream.html.twig +++ b/templates/broadcast/Download.stream.html.twig @@ -1,21 +1,28 @@ {# Learn how to use Turbo Streams: https://github.com/symfony/ux-turbo#broadcast-doctrine-entities-update #} {% block create %} + + + - - {% endblock %} {% block update %} @@ -33,6 +40,9 @@ {% else %} + + + @@ -42,16 +52,16 @@ - + diff --git a/templates/components/ActiveDownloadList.html.twig b/templates/components/DownloadList.html.twig similarity index 54% rename from templates/components/ActiveDownloadList.html.twig rename to templates/components/DownloadList.html.twig index 908de9e..e31078c 100644 --- a/templates/components/ActiveDownloadList.html.twig +++ b/templates/components/DownloadList.html.twig @@ -1,9 +1,10 @@ - + {% set table_body_id = (type == "complete") ? "complete_downloads" : "active_downloads" %} +
- + - - {% if this.getDownloads()|length > 0 %} - {% for download in this.getDownloads() %} + + {% if this.downloads|length > 0 %} + {% for download in this.downloads %} - {% endfor %} {% else %} - + {% endif %} diff --git a/templates/components/MonitorList.html.twig b/templates/components/MonitorList.html.twig new file mode 100644 index 0000000..51da7ad --- /dev/null +++ b/templates/components/MonitorList.html.twig @@ -0,0 +1,71 @@ + +

The items you're currently monitoring to automatically download.

+
+ class="px-6 py-3 text-start text-xs font-medium text-stone-500 uppercase dark:text-stone-800 min-w-[45ch] max-w-[45ch] truncate"> Title
{{ download.title }} + + {% if download.progress < 100 %} {{ download.progress }} + {% else %} + + Complete + + {% endif %}
- No active downloads + No downloads
+ + + + + + + + + + + {% if this.userMonitors()|length > 0 %} + {% for monitor in this.userMonitors() %} + + + + + + + + {% endfor %} + {% else %} + + + + {% endif %} + +
+ Title + + Search Count + + Created at + + Last Search Date + + Status +
+ {{ monitor.title }} + + {{ monitor.searchCount }} + + {{ monitor.createdAt|date('m/d/Y h:i a') }} + + {{ monitor.lastSearch|date('m/d/Y h:i a') }} + + {% if monitor.status == "New" %} + + {{ monitor.status }} + + {% elseif monitor.status == "In Progress" or monitor.status == "Active" %} + + {{ monitor.status }} + + {% else %} + + {{ monitor.status }} + + {% endif %} +
+ No monitors +
+ + diff --git a/templates/index/index.html.twig b/templates/index/index.html.twig index e640928..82e0f75 100644 --- a/templates/index/index.html.twig +++ b/templates/index/index.html.twig @@ -7,51 +7,16 @@

Dashboard

- + - - - - - - - - - {% if recent_downloads|length > 0 %} - {% for download in recent_downloads %} - - - - - {% endfor %} - - - - {% else %} - - - - {% endif %} - -
- Title - - Status -
- {{ download.title }} - - - Complete - -
- View all downloads -
- No recent downloads -
+ +
+
+
+ +