fix: broken download, added to queue alert, download list component; feat: monitor list

This commit is contained in:
2025-05-12 11:23:03 -05:00
parent a628d85ef2
commit 888a030680
17 changed files with 205 additions and 107 deletions

View File

@@ -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!',

View File

@@ -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']);
}
}

View File

@@ -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.',

View File

@@ -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');

View File

@@ -39,8 +39,8 @@ class DownloadMediaInput implements InputInterface
$this->filename,
$this->mediaType,
$this->imdbId,
$this->userId,
$this->downloadId,
$this->userId
);
}
}

View File

@@ -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}",

View File

@@ -1,25 +0,0 @@
<?php
namespace App\Twig\Components;
use App\Download\Framework\Repository\DownloadRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveAction;
use Symfony\UX\LiveComponent\DefaultActionTrait;
#[AsLiveComponent]
final class ActiveDownloadList extends AbstractController
{
use DefaultActionTrait;
public function __construct(
private DownloadRepository $downloadRepository,
) {}
#[LiveAction]
public function getDownloads()
{
return $this->getUser()->getActiveDownloads();
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Twig\Components;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
#[AsTwigComponent]
final class DownloadList extends AbstractController
{
public string $type;
public function getDownloads()
{
if ($this->type === "active") {
return $this->getUser()->queryDownloads('in-progress', 5);
} elseif ($this->type === "complete") {
return $this->getUser()->queryDownloads('complete', 5);
}
return [];
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Twig\Components;
use App\Monitor\Framework\Repository\MonitorRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
#[AsTwigComponent]
final class MonitorList extends AbstractController
{
public function __construct(
private MonitorRepository $monitorRepository,
) {}
public function getUserMonitors()
{
return $this->getUser()->getMonitors();
}
}

View File

@@ -48,7 +48,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
* @var Collection<int, Monitor>
*/
#[ORM\OneToMany(targetEntity: Monitor::class, mappedBy: 'user', orphanRemoval: true)]
private Collection $yes;
private Collection $monitors;
/**
* @var Collection<int, Download>
@@ -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<int, Monitor>
*/
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 [];
}
}

View File

@@ -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();