Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 044df00982 | |||
| 92015feaac | |||
| 5b704d9b36 |
@@ -2,34 +2,25 @@
|
|||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Util\Broadcaster;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Mercure\HubInterface;
|
|
||||||
use Symfony\Component\Mercure\Update;
|
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Twig\Environment;
|
|
||||||
|
|
||||||
final class AlertController extends AbstractController
|
final class AlertController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire(service: 'twig')] private readonly Environment $renderer,
|
private readonly Broadcaster $broadcaster,
|
||||||
private readonly HubInterface $hub,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/alert', name: 'app_alert')]
|
#[Route('/alert', name: 'app_alert')]
|
||||||
public function index(): Response
|
public function index(): Response
|
||||||
{
|
{
|
||||||
$update = new Update(
|
$this->broadcaster->alert(
|
||||||
'alerts',
|
'Added to queue',
|
||||||
$this->renderer->render('Alert.stream.html.twig', [
|
'This is a testy test!'
|
||||||
'alert_id' => 1,
|
|
||||||
'title' => 'Added to queue',
|
|
||||||
'message' => 'This is a testy test!',
|
|
||||||
])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->hub->publish($update);
|
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'Success' => 'Published'
|
'Success' => 'Published'
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ use App\Torrentio\Action\Handler\GetMovieOptionsHandler;
|
|||||||
use App\Torrentio\Action\Handler\GetTvShowOptionsHandler;
|
use App\Torrentio\Action\Handler\GetTvShowOptionsHandler;
|
||||||
use App\Torrentio\Action\Input\GetMovieOptionsInput;
|
use App\Torrentio\Action\Input\GetMovieOptionsInput;
|
||||||
use App\Torrentio\Action\Input\GetTvShowOptionsInput;
|
use App\Torrentio\Action\Input\GetTvShowOptionsInput;
|
||||||
|
use App\Util\Broadcaster;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Mercure\HubInterface;
|
|
||||||
use Symfony\Component\Mercure\Update;
|
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Symfony\Contracts\Cache\CacheInterface;
|
use Symfony\Contracts\Cache\CacheInterface;
|
||||||
use Symfony\Contracts\Cache\ItemInterface;
|
use Symfony\Contracts\Cache\ItemInterface;
|
||||||
@@ -21,8 +20,7 @@ final class TorrentioController extends AbstractController
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly GetMovieOptionsHandler $getMovieOptionsHandler,
|
private readonly GetMovieOptionsHandler $getMovieOptionsHandler,
|
||||||
private readonly GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
private readonly GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
||||||
private readonly HubInterface $hub,
|
private readonly Broadcaster $broadcaster,
|
||||||
private readonly \Twig\Environment $renderer,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/torrentio/movies/{tmdbId}/{imdbId}', name: 'app_torrentio_movies')]
|
#[Route('/torrentio/movies/{tmdbId}/{imdbId}', name: 'app_torrentio_movies')]
|
||||||
@@ -75,14 +73,10 @@ final class TorrentioController extends AbstractController
|
|||||||
);
|
);
|
||||||
$cache->delete($cacheId);
|
$cache->delete($cacheId);
|
||||||
|
|
||||||
$this->hub->publish(new Update(
|
$this->broadcaster->alert(
|
||||||
$request->getSession()->get('mercure_alert_topic'),
|
title: 'Success',
|
||||||
$this->renderer->render('Alert.stream.html.twig', [
|
message: 'Torrentio cache Cleared.'
|
||||||
'alert_id' => uniqid(),
|
);
|
||||||
'title' => 'Success',
|
|
||||||
'message' => 'Torrentio cache Cleared.',
|
|
||||||
])
|
|
||||||
));
|
|
||||||
|
|
||||||
return $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
return $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
||||||
$item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0));
|
$item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0));
|
||||||
|
|||||||
@@ -6,11 +6,9 @@ use App\Download\Action\Handler\DeleteDownloadHandler;
|
|||||||
use App\Download\Action\Input\DeleteDownloadInput;
|
use App\Download\Action\Input\DeleteDownloadInput;
|
||||||
use App\Download\Action\Input\DownloadMediaInput;
|
use App\Download\Action\Input\DownloadMediaInput;
|
||||||
use App\Download\Framework\Repository\DownloadRepository;
|
use App\Download\Framework\Repository\DownloadRepository;
|
||||||
|
use App\Util\Broadcaster;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Mercure\HubInterface;
|
|
||||||
use Symfony\Component\Mercure\Update;
|
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
@@ -19,12 +17,11 @@ class ApiController extends AbstractController
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private DownloadRepository $downloadRepository,
|
private DownloadRepository $downloadRepository,
|
||||||
private MessageBusInterface $bus,
|
private MessageBusInterface $bus,
|
||||||
private readonly HubInterface $hub,
|
private readonly Broadcaster $broadcaster,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/api/download', name: 'api_download', methods: ['POST'])]
|
#[Route('/api/download', name: 'api_download', methods: ['POST'])]
|
||||||
public function download(
|
public function download(
|
||||||
Request $request,
|
|
||||||
DownloadMediaInput $input,
|
DownloadMediaInput $input,
|
||||||
): Response {
|
): Response {
|
||||||
$download = $this->downloadRepository->insert(
|
$download = $this->downloadRepository->insert(
|
||||||
@@ -47,33 +44,24 @@ class ApiController extends AbstractController
|
|||||||
return $this->json(['error' => $exception->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
|
return $this->json(['error' => $exception->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hub->publish(new Update(
|
$this->broadcaster->alert(
|
||||||
$request->getSession()->get('mercure_alert_topic'),
|
title: 'Success',
|
||||||
$this->renderView('broadcast/Alert.stream.html.twig', [
|
message: "$input->title added to Queue."
|
||||||
'alert_id' => uniqid(),
|
);
|
||||||
'title' => 'Success',
|
|
||||||
'message' => '"' . $input->title . '" added to Queue',
|
|
||||||
])
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this->json(['status' => 200, 'message' => 'Added to Queue']);
|
return $this->json(['status' => 200, 'message' => 'Added to Queue']);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/api/download/{downloadId}', name: 'api_download_delete', methods: ['DELETE'])]
|
#[Route('/api/download/{downloadId}', name: 'api_download_delete', methods: ['DELETE'])]
|
||||||
public function deleteDownload(
|
public function deleteDownload(
|
||||||
Request $request,
|
|
||||||
DeleteDownloadInput $input,
|
DeleteDownloadInput $input,
|
||||||
DeleteDownloadHandler $handler,
|
DeleteDownloadHandler $handler,
|
||||||
): Response {
|
): Response {
|
||||||
$result = $handler->handle($input->toCommand());
|
$result = $handler->handle($input->toCommand());
|
||||||
$this->hub->publish(new Update(
|
$this->broadcaster->alert(
|
||||||
$request->getSession()->get('mercure_alert_topic'),
|
title: 'Success',
|
||||||
$this->renderView('broadcast/Alert.stream.html.twig', [
|
message: "{$result->download->getTitle()} has been deleted.",
|
||||||
'alert_id' => uniqid(),
|
);
|
||||||
'title' => 'Success',
|
|
||||||
'message' => '"' . $result->download->getTitle() . '" has been deleted.',
|
|
||||||
])
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this->json(['status' => 200, 'message' => 'Download Deleted']);
|
return $this->json(['status' => 200, 'message' => 'Download Deleted']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,19 +7,18 @@ use App\Monitor\Action\Handler\AddMonitorHandler;
|
|||||||
use App\Monitor\Action\Handler\DeleteMonitorHandler;
|
use App\Monitor\Action\Handler\DeleteMonitorHandler;
|
||||||
use App\Monitor\Action\Input\AddMonitorInput;
|
use App\Monitor\Action\Input\AddMonitorInput;
|
||||||
use App\Monitor\Action\Input\DeleteMonitorInput;
|
use App\Monitor\Action\Input\DeleteMonitorInput;
|
||||||
|
use App\Util\Broadcaster;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Component\Mercure\HubInterface;
|
use Symfony\Component\Mercure\HubInterface;
|
||||||
use Symfony\Component\Mercure\Update;
|
use Symfony\Component\Mercure\Update;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Twig\Environment;
|
|
||||||
|
|
||||||
class ApiController extends AbstractController
|
class ApiController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire(service: 'twig')]
|
private readonly Broadcaster $broadcaster,
|
||||||
private readonly Environment $renderer,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/api/monitor', name: 'api_monitor', methods: ['POST'])]
|
#[Route('/api/monitor', name: 'api_monitor', methods: ['POST'])]
|
||||||
@@ -32,14 +31,10 @@ class ApiController extends AbstractController
|
|||||||
$command->userId = $this->getUser()->getId();
|
$command->userId = $this->getUser()->getId();
|
||||||
$response = $handler->handle($command);
|
$response = $handler->handle($command);
|
||||||
|
|
||||||
$hub->publish(new Update(
|
$this->broadcaster->alert(
|
||||||
'alerts',
|
title: 'Success',
|
||||||
$this->renderer->render('broadcast/Alert.stream.html.twig', [
|
message: "New monitor added for {$input->title}",
|
||||||
'alert_id' => uniqid(),
|
);
|
||||||
'title' => 'Success',
|
|
||||||
'message' => "New monitor added for {$input->title}",
|
|
||||||
])
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'status' => 200,
|
'status' => 200,
|
||||||
|
|||||||
@@ -9,23 +9,20 @@ use App\User\Action\Handler\SaveUserMediaPreferencesHandler;
|
|||||||
use App\User\Action\Input\SaveUserDownloadPreferencesInput;
|
use App\User\Action\Input\SaveUserDownloadPreferencesInput;
|
||||||
use App\User\Action\Input\SaveUserMediaPreferencesInput;
|
use App\User\Action\Input\SaveUserMediaPreferencesInput;
|
||||||
use App\User\Framework\Repository\PreferencesRepository;
|
use App\User\Framework\Repository\PreferencesRepository;
|
||||||
|
use App\Util\Broadcaster;
|
||||||
use App\Util\CountryLanguages;
|
use App\Util\CountryLanguages;
|
||||||
use App\Util\ProviderList;
|
use App\Util\ProviderList;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Mercure\HubInterface;
|
|
||||||
use Symfony\Component\Mercure\Update;
|
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
class PreferencesController extends AbstractController
|
class PreferencesController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly PreferencesRepository $preferencesRepository,
|
private readonly PreferencesRepository $preferencesRepository,
|
||||||
private readonly SaveUserMediaPreferencesHandler $saveUserMediaPreferencesHandler,
|
private readonly Broadcaster $broadcaster,
|
||||||
private readonly HubInterface $hub,
|
|
||||||
private readonly SaveUserDownloadPreferencesHandler $saveUserDownloadPreferencesHandler,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/user/preferences', 'app_user_preferences', methods: ['GET'])]
|
#[Route('/user/preferences', 'app_user_preferences', methods: ['GET'])]
|
||||||
public function mediaPreferences(): Response
|
public function mediaPreferences(): Response
|
||||||
{
|
{
|
||||||
@@ -48,25 +45,21 @@ class PreferencesController extends AbstractController
|
|||||||
|
|
||||||
#[Route('/user/preferences/media', 'app_save_media_preferences', methods: ['POST'])]
|
#[Route('/user/preferences/media', 'app_save_media_preferences', methods: ['POST'])]
|
||||||
public function saveMediaPreferences(
|
public function saveMediaPreferences(
|
||||||
Request $request,
|
|
||||||
SaveUserMediaPreferencesInput $input,
|
SaveUserMediaPreferencesInput $input,
|
||||||
|
SaveUserMediaPreferencesHandler $saveUserMediaPreferencesHandler,
|
||||||
): Response
|
): Response
|
||||||
{
|
{
|
||||||
$this->saveUserMediaPreferencesHandler->handle($input->toCommand());
|
$saveUserMediaPreferencesHandler->handle($input->toCommand());
|
||||||
$mediaPreferences = $this->getUser()->getMediaPreferences();
|
$mediaPreferences = $this->getUser()->getMediaPreferences();
|
||||||
$downloadPreferences = $this->getUser()->getDownloadPreferences();
|
$downloadPreferences = $this->getUser()->getDownloadPreferences();
|
||||||
|
|
||||||
$languages = CountryLanguages::$languages;
|
$languages = CountryLanguages::$languages;
|
||||||
sort($languages);
|
sort($languages);
|
||||||
|
|
||||||
$this->hub->publish(new Update(
|
$this->broadcaster->alert(
|
||||||
$request->getSession()->get('mercure_alert_topic'),
|
title: 'Success',
|
||||||
$this->renderView('broadcast/Alert.stream.html.twig', [
|
message: 'Your media preferences have been saved.'
|
||||||
'alert_id' => uniqid(),
|
);
|
||||||
'title' => 'Success',
|
|
||||||
'message' => 'Your media preferences have been saved.',
|
|
||||||
])
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this->render(
|
return $this->render(
|
||||||
'user/preferences.html.twig',
|
'user/preferences.html.twig',
|
||||||
@@ -82,24 +75,20 @@ class PreferencesController extends AbstractController
|
|||||||
|
|
||||||
#[Route('/user/preferences/download', 'app_save_download_preferences', methods: ['POST'])]
|
#[Route('/user/preferences/download', 'app_save_download_preferences', methods: ['POST'])]
|
||||||
public function saveDownloadPreferences(
|
public function saveDownloadPreferences(
|
||||||
Request $request,
|
|
||||||
SaveUserDownloadPreferencesInput $input,
|
SaveUserDownloadPreferencesInput $input,
|
||||||
|
SaveUserDownloadPreferencesHandler $saveUserDownloadPreferencesHandler,
|
||||||
): Response
|
): Response
|
||||||
{
|
{
|
||||||
$downloadPreferences = $this->saveUserDownloadPreferencesHandler->handle($input->toCommand())->downloadPreferences;
|
$downloadPreferences = $saveUserDownloadPreferencesHandler->handle($input->toCommand())->downloadPreferences;
|
||||||
$mediaPreferences = $this->getUser()->getMediaPreferences();
|
$mediaPreferences = $this->getUser()->getMediaPreferences();
|
||||||
|
|
||||||
$languages = CountryLanguages::$languages;
|
$languages = CountryLanguages::$languages;
|
||||||
sort($languages);
|
sort($languages);
|
||||||
|
|
||||||
$this->hub->publish(new Update(
|
$this->broadcaster->alert(
|
||||||
$request->getSession()->get('mercure_alert_topic'),
|
title: 'Success',
|
||||||
$this->renderView('broadcast/Alert.stream.html.twig', [
|
message: 'Your download preferences have been saved.'
|
||||||
'alert_id' => uniqid(),
|
);
|
||||||
'title' => 'Success',
|
|
||||||
'message' => 'Your download preferences have been saved.',
|
|
||||||
])
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this->render(
|
return $this->render(
|
||||||
'user/preferences.html.twig',
|
'user/preferences.html.twig',
|
||||||
|
|||||||
33
src/Util/Broadcaster.php
Normal file
33
src/Util/Broadcaster.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Util;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
use Symfony\Component\Mercure\HubInterface;
|
||||||
|
use Symfony\Component\Mercure\Update;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
readonly class Broadcaster
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[Autowire(service: 'twig')]
|
||||||
|
private Environment $renderer,
|
||||||
|
private HubInterface $hub,
|
||||||
|
private RequestStack $requestStack,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function alert(string $title, string $message): void
|
||||||
|
{
|
||||||
|
$userAlertTopic = $this->requestStack->getCurrentRequest()->getSession()->get('mercure_alert_topic');
|
||||||
|
$update = new Update(
|
||||||
|
$userAlertTopic,
|
||||||
|
$this->renderer->render('broadcast/Alert.stream.html.twig', [
|
||||||
|
'alert_id' => uniqid(),
|
||||||
|
'title' => $title,
|
||||||
|
'message' => $message,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
$this->hub->publish($update);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,4 +82,10 @@
|
|||||||
|
|
||||||
{% block remove %}
|
{% block remove %}
|
||||||
<turbo-stream action="remove" target="monitor_{{ id }}"></turbo-stream>
|
<turbo-stream action="remove" target="monitor_{{ id }}"></turbo-stream>
|
||||||
|
|
||||||
|
<turbo-stream action="prepend" target="alert_list">
|
||||||
|
<template>
|
||||||
|
<twig:Alert title="Success" message="Your Monitor for '{{ entity.title }}' has been removed." alert_id="monitor_alert_{{ entity.id }}" data-controller="alert" />
|
||||||
|
</template>
|
||||||
|
</turbo-stream>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user