Skip to content

Commit

Permalink
Fix SOME SITES being smelly app-build
Browse files Browse the repository at this point in the history
  • Loading branch information
pkly committed Nov 14, 2024
1 parent fb7e6c4 commit 908a17b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions src/Service/RewriteService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Service;

class RewriteService
{
public const array REWRITE_MAP = [
'nyaa.si' => 'nyaa.iss.one',
];

public function rewrite(
string $input
): string {
foreach (self::REWRITE_MAP as $from => $to) {
$input = str_replace($from, $to, $input);
}

return $input;
}
}

0 comments on commit 908a17b

Please sign in to comment.