60 lines
2.2 KiB
PHP
60 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Torrentio\Action\Handler\GetMovieOptionsHandler;
|
|
use App\Torrentio\Action\Handler\GetTvShowOptionsHandler;
|
|
use App\Torrentio\Action\Input\GetMovieOptionsInput;
|
|
use App\Torrentio\Action\Input\GetTvShowOptionsInput;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Contracts\Cache\CacheInterface;
|
|
use Symfony\Contracts\Cache\ItemInterface;
|
|
|
|
final class TorrentioController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly GetMovieOptionsHandler $getMovieOptionsHandler,
|
|
private readonly GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
|
) {}
|
|
|
|
#[Route('/torrentio/movies/{tmdbId}/{imdbId}', name: 'app_torrentio_movies')]
|
|
public function movieOptions(GetMovieOptionsInput $input, CacheInterface $cache): Response
|
|
{
|
|
$cacheId = sprintf(
|
|
"page.torrentio.movies.%s.%s",
|
|
$input->tmdbId,
|
|
$input->imdbId
|
|
);
|
|
|
|
return $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
|
$item->expiresAt(new \DateTimeImmutable("today 11:59 pm"));
|
|
$results = $this->getMovieOptionsHandler->handle($input->toCommand());
|
|
return $this->render('torrentio/movies.html.twig', [
|
|
'results' => $results,
|
|
]);
|
|
});
|
|
}
|
|
|
|
#[Route('/torrentio/tvshows/{tmdbId}/{imdbId}/{season?}/{episode?}', name: 'app_torrentio_tvshows')]
|
|
public function tvShowOptions(GetTvShowOptionsInput $input, CacheInterface $cache): Response
|
|
{
|
|
$cacheId = sprintf(
|
|
"page.torrentio.tvshows.%s.%s.%s.%s",
|
|
$input->tmdbId,
|
|
$input->imdbId,
|
|
$input->season,
|
|
$input->episode,
|
|
);
|
|
|
|
// return $cache->get($cacheId, function (ItemInterface $item) use ($input) {
|
|
// $item->expiresAt(new \DateTimeImmutable("today 11:59 pm"));
|
|
$results = $this->getTvShowOptionsHandler->handle($input->toCommand());
|
|
return $this->render('torrentio/tvshows.html.twig', [
|
|
'results' => $results,
|
|
]);
|
|
// });
|
|
}
|
|
}
|