chore: cleanup

This commit is contained in:
2025-07-13 21:27:54 -05:00
parent accfa9c9bf
commit b42981b2a1
8 changed files with 27 additions and 31 deletions

View File

@@ -140,7 +140,7 @@ class MediaFiles
return $path; return $path;
} }
public function episodeExists(string $tvshowTitle, int $seasonNumber, int $episodeNumber) public function episodeExists(string $tvshowTitle, int $seasonNumber, int $episodeNumber): SplFileInfo|false
{ {
$existingEpisodes = $this->getEpisodes($tvshowTitle, false); $existingEpisodes = $this->getEpisodes($tvshowTitle, false);

View File

@@ -4,7 +4,7 @@ namespace App\Library\Action\Command;
use OneToMany\RichBundle\Contract\CommandInterface; use OneToMany\RichBundle\Contract\CommandInterface;
class SearchCommand implements CommandInterface class LibrarySearchCommand implements CommandInterface
{ {
public function __construct( public function __construct(
public ?string $term = null, public ?string $term = null,

View File

@@ -3,16 +3,16 @@
namespace App\Library\Action\Handler; namespace App\Library\Action\Handler;
use App\Base\Service\MediaFiles; use App\Base\Service\MediaFiles;
use App\Library\Action\Command\SearchCommand; use App\Library\Action\Command\LibrarySearchCommand;
use App\Library\Action\Result\SearchResult; use App\Library\Action\Result\LibrarySearchResult;
use OneToMany\RichBundle\Contract\CommandInterface; use OneToMany\RichBundle\Contract\CommandInterface;
use OneToMany\RichBundle\Contract\HandlerInterface; use OneToMany\RichBundle\Contract\HandlerInterface;
use OneToMany\RichBundle\Contract\ResultInterface; use OneToMany\RichBundle\Contract\ResultInterface;
/** /**
* @implements HandlerInterface<SearchCommand,SearchHandler> * @implements HandlerInterface<LibrarySearchCommand,LibrarySearchHandler>
*/ */
class SearchHandler implements HandlerInterface class LibrarySearchHandler implements HandlerInterface
{ {
private array $searchTypes = [ private array $searchTypes = [
'episode_by_title' => 'episodeByTitle', 'episode_by_title' => 'episodeByTitle',
@@ -40,7 +40,7 @@ class SearchHandler implements HandlerInterface
return null; return null;
} }
private function episodeByTitle(CommandInterface $command): ?SearchResult private function episodeByTitle(CommandInterface $command): ?LibrarySearchResult
{ {
$result = $this->mediaFiles->episodeExists( $result = $this->mediaFiles->episodeExists(
$command->title, $command->title,
@@ -50,14 +50,11 @@ class SearchHandler implements HandlerInterface
$exists = $result instanceof \SplFileInfo; $exists = $result instanceof \SplFileInfo;
return new SearchResult(
return new LibrarySearchResult(
input: $command, input: $command,
message: 'Success', exists: $exists,
code: 200, file: true === $exists ? $result->getFileInfo() : null,
data: [
'exists' => $exists,
'file' => true === $exists ? ['filename' => $result->getFilename(), 'size' => $result->getSize()] : null,
]
); );
} }
} }

View File

@@ -2,15 +2,15 @@
namespace App\Library\Action\Input; namespace App\Library\Action\Input;
use App\Library\Action\Command\SearchCommand; use App\Library\Action\Command\LibrarySearchCommand;
use OneToMany\RichBundle\Attribute\SourceQuery; use OneToMany\RichBundle\Attribute\SourceQuery;
use OneToMany\RichBundle\Contract\CommandInterface; use OneToMany\RichBundle\Contract\CommandInterface;
use OneToMany\RichBundle\Contract\InputInterface; use OneToMany\RichBundle\Contract\InputInterface;
/** /**
* @implements InputInterface<SearchInput, SearchCommand> * @implements InputInterface<LibrarySearchInput, LibrarySearchCommand>
*/ */
class SearchInput implements InputInterface class LibrarySearchInput implements InputInterface
{ {
public function __construct( public function __construct(
#[SourceQuery('term', nullify: true)] #[SourceQuery('term', nullify: true)]
@@ -27,7 +27,7 @@ class SearchInput implements InputInterface
public function toCommand(): CommandInterface public function toCommand(): CommandInterface
{ {
return new SearchCommand( return new LibrarySearchCommand(
term: $this->term, term: $this->term,
title: $this->title, title: $this->title,
imdbId: $this->imdbId, imdbId: $this->imdbId,

View File

@@ -4,12 +4,12 @@ namespace App\Library\Action\Result;
use OneToMany\RichBundle\Contract\ResultInterface; use OneToMany\RichBundle\Contract\ResultInterface;
class SearchResult implements ResultInterface class LibrarySearchResult implements ResultInterface
{ {
public function __construct( public function __construct(
public object|array $input, public object|array $input,
public string $message, public bool $exists,
public int $code, public ?\SplFileInfo $file = null,
public ?array $data, public ?object $ptn = null,
) {} ) {}
} }

View File

@@ -2,9 +2,9 @@
namespace App\Library\Framework\Controller; namespace App\Library\Framework\Controller;
use App\Library\Action\Handler\SearchHandler; use App\Library\Action\Handler\LibrarySearchHandler;
use App\Library\Action\Input\SearchInput; use App\Library\Action\Input\LibrarySearchInput;
use App\Library\Action\Result\SearchResult; use App\Library\Action\Result\LibrarySearchResult;
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;
@@ -14,7 +14,7 @@ use Symfony\UX\Turbo\TurboBundle;
class Api extends AbstractController class Api extends AbstractController
{ {
#[Route('/api/library/search', name: 'api.library.search', methods: ['GET'])] #[Route('/api/library/search', name: 'api.library.search', methods: ['GET'])]
public function search(SearchInput $input, SearchHandler $handler, Request $request): Response public function search(LibrarySearchInput $input, LibrarySearchHandler $handler, Request $request): Response
{ {
$result = $handler->handle($input->toCommand()); $result = $handler->handle($input->toCommand());
@@ -25,7 +25,7 @@ class Api extends AbstractController
return $this->json($handler->handle($input->toCommand())); return $this->json($handler->handle($input->toCommand()));
} }
private function sendFragmentResponse(SearchResult $result, Request $request): Response private function sendFragmentResponse(LibrarySearchResult $result, Request $request): Response
{ {
$request->setRequestFormat(TurboBundle::STREAM_FORMAT); $request->setRequestFormat(TurboBundle::STREAM_FORMAT);
return $this->renderBlock( return $this->renderBlock(

View File

@@ -2,7 +2,6 @@
namespace App\Search\Action\Handler; namespace App\Search\Action\Handler;
use App\Base\Service\MediaFiles;
use App\Search\Action\Command\GetMediaInfoCommand; use App\Search\Action\Command\GetMediaInfoCommand;
use App\Search\Action\Result\GetMediaInfoResult; use App\Search\Action\Result\GetMediaInfoResult;
use App\Tmdb\Tmdb; use App\Tmdb\Tmdb;

View File

@@ -1,14 +1,14 @@
{% block media_exists_badge %} {% block media_exists_badge %}
<turbo-stream action="replace" targets="#{{ target }}"> <turbo-stream action="replace" targets="#{{ target }}">
<template> <template>
{% if result.data['exists'] == true %} {% if result.exists == true %}
<span data-controller="popover"> <span data-controller="popover">
<template data-popover-target="content"> <template data-popover-target="content">
<div data-popover-target="card" <div data-popover-target="card"
class="absolute z-40 p-1 bg-stone-400 p-1 text-black rounded-md m-1 animate-fade"> class="absolute z-40 p-1 bg-stone-400 p-1 text-black rounded-md m-1 animate-fade">
<p class="font-bold text-sm text-left">Existing file(s) for this episode:</p> <p class="font-bold text-sm text-left">Existing file(s) for this episode:</p>
<ul class="list-disc ml-3"> <ul class="list-disc ml-3">
<li class="font-normal">{{ result.data['file']['filename']|strip_media_path }} &mdash; <strong>{{ result.data['file']['size']|filesize }}</strong></li> <li class="font-normal">{{ result.file.filename|strip_media_path }} &mdash; <strong>{{ result.file.size|filesize }}</strong></li>
</ul> </ul>
</div> </div>
</template> </template>
@@ -21,7 +21,7 @@
</span> </span>
{% endif %} {% endif %}
{% if result.data['exists'] == false %} {% if result.exists == false %}
<small class="py-1 px-1.5 mr-1 grow-0 font-bold bg-rose-600 rounded-lg text-white" <small class="py-1 px-1.5 mr-1 grow-0 font-bold bg-rose-600 rounded-lg text-white"
title="Episode has not been downloaded yet."> title="Episode has not been downloaded yet.">
missing missing