From 908a17bf2d3ec7dedce9e70f65c15257e6b2e243 Mon Sep 17 00:00:00 2001 From: pkly Date: Thu, 14 Nov 2024 19:24:13 +0100 Subject: [PATCH] Fix SOME SITES being smelly app-build --- src/Controller/DefaultController.php | 6 ++++-- src/Service/RewriteService.php | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/Service/RewriteService.php diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index f06820a..e5635c4 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -5,6 +5,7 @@ use App\Entity\Rss\Result; use App\Service\MascotService; use App\Service\QBitTorrentService; +use App\Service\RewriteService; use App\Traits\EntityManagerTrait; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\Attribute\Autowire; @@ -51,9 +52,10 @@ public function recache( #[Route('/proxy/{file}', name: 'front.file_proxy')] public function proxy( - Result $file + Result $file, + RewriteService $rewriteService ): Response { - $response = $this->client->request('GET', $file->getUrl()); + $response = $this->client->request('GET', $rewriteService->rewrite($file->getUrl())); if (Response::HTTP_OK !== $response->getStatusCode()) { return new Response('Failed to download file', 500); diff --git a/src/Service/RewriteService.php b/src/Service/RewriteService.php new file mode 100644 index 0000000..6c20542 --- /dev/null +++ b/src/Service/RewriteService.php @@ -0,0 +1,20 @@ + 'nyaa.iss.one', + ]; + + public function rewrite( + string $input + ): string { + foreach (self::REWRITE_MAP as $from => $to) { + $input = str_replace($from, $to, $input); + } + + return $input; + } +}