From 1bce9ecfe547c759edcd5d6140340e1da09e0557 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Mon, 3 Mar 2025 14:01:10 +0800 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B4=D0=B8=D1=80=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/Controllers/BasicController.php | 26 ------------------------- src/app/Controllers/WebController.php | 19 +++++++++++++++--- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/app/Controllers/BasicController.php b/src/app/Controllers/BasicController.php index 9d96898..c4dc24c 100644 --- a/src/app/Controllers/BasicController.php +++ b/src/app/Controllers/BasicController.php @@ -55,30 +55,4 @@ class BasicController $view = Twig::fromRequest($request); return $view->render($response, $template, $data); } - - /** - * Возвращает плейлист по его ID для обработки - * - * @param string $id - * @param bool $asJson - * @return Playlist - * @throws Exception - */ - protected function getPlaylist(string $id, bool $asJson = false): Playlist - { - ini()->load(); - - if (ini()->getRedirection($id)) { - $redirectTo = base_url(ini()->getRedirection($id) . ($asJson ? '/json' : '/details')); - Flight::redirect($redirectTo); - die; - } - - try { - return ini()->getPlaylist($id); - } catch (PlaylistNotFoundException) { - $this->notFound($id, $asJson); - die; - } - } } diff --git a/src/app/Controllers/WebController.php b/src/app/Controllers/WebController.php index b11308e..b346865 100644 --- a/src/app/Controllers/WebController.php +++ b/src/app/Controllers/WebController.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Controllers; use App\Core\ChannelLogo; +use App\Errors\PlaylistNotFoundException; use Exception; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -67,9 +68,14 @@ class WebController extends BasicController */ public function redirect(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface { + ini()->load(); $code = $request->getAttributes()['code']; - $playlist = $this->getPlaylist($code); - return $response->withHeader('Location', $playlist->pls); + try { + $playlist = ini()->getPlaylist($code); + return $response->withHeader('Location', $playlist->pls); + } catch (PlaylistNotFoundException) { + return $this->notFound($request, $response); + } } /** @@ -83,8 +89,15 @@ class WebController extends BasicController */ public function details(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface { + ini()->load(); $code = $request->getAttributes()['code']; - $playlist = $this->getPlaylist($code); + try { + $playlist = ini()->getPlaylist($code); + $response->withHeader('Location', $playlist->pls); + } catch (PlaylistNotFoundException) { + return $this->notFound($request, $response); + } + $playlist->fetchContent(); $playlist->parse();