Compare commits
1 Commits
v0.33.5
...
dev-preven
| Author | SHA1 | Date | |
|---|---|---|---|
| 709dc07cf6 |
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Download\Action\Handler\Exception;
|
||||||
|
|
||||||
|
class RealDebridBadUrlException extends \Exception
|
||||||
|
{
|
||||||
|
public function __construct(string $type)
|
||||||
|
{
|
||||||
|
$messages = [
|
||||||
|
'file_downloading' => 'This file appears to be Real Debrid\'s "Torrent is downloading..." video.',
|
||||||
|
'file_removed' => 'This file appears to be Real Debrid\'s "File is removed..." video.',
|
||||||
|
];
|
||||||
|
|
||||||
|
parent::__construct($messages[$type]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Download\Framework\Controller;
|
namespace App\Download\Framework\Controller;
|
||||||
|
|
||||||
|
use App\Download\Action\Handler\Exception\RealDebridBadUrlException;
|
||||||
use App\Download\Action\Input\DownloadMediaInput;
|
use App\Download\Action\Input\DownloadMediaInput;
|
||||||
use App\Download\Framework\Repository\DownloadRepository;
|
use App\Download\Framework\Repository\DownloadRepository;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
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;
|
||||||
@@ -18,6 +20,7 @@ class ApiController extends AbstractController
|
|||||||
private DownloadRepository $downloadRepository,
|
private DownloadRepository $downloadRepository,
|
||||||
private MessageBusInterface $bus,
|
private MessageBusInterface $bus,
|
||||||
private readonly HubInterface $hub,
|
private readonly HubInterface $hub,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route('/api/download', name: 'api_download', methods: ['POST'])]
|
#[Route('/api/download', name: 'api_download', methods: ['POST'])]
|
||||||
@@ -25,6 +28,12 @@ class ApiController extends AbstractController
|
|||||||
Request $request,
|
Request $request,
|
||||||
DownloadMediaInput $input,
|
DownloadMediaInput $input,
|
||||||
): Response {
|
): Response {
|
||||||
|
try {
|
||||||
|
$this->validateUrl($input->url);
|
||||||
|
} catch (RealDebridBadUrlException $e) {
|
||||||
|
return $this->json(['error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
|
||||||
$download = $this->downloadRepository->insert(
|
$download = $this->downloadRepository->insert(
|
||||||
$this->getUser(),
|
$this->getUser(),
|
||||||
$input->url,
|
$input->url,
|
||||||
@@ -56,4 +65,22 @@ class ApiController extends AbstractController
|
|||||||
|
|
||||||
return $this->json(['status' => 200, 'message' => 'Added to Queue']);
|
return $this->json(['status' => 200, 'message' => 'Added to Queue']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function validateUrl(string $url): bool
|
||||||
|
{
|
||||||
|
$knownLengths = [
|
||||||
|
'2119075' => 'file_removed', // 'File is removed by copyright owners' Real Debrid video
|
||||||
|
'1184727' => 'file_downloading', // 'Torrent is Downloading' Real Debrid video
|
||||||
|
];
|
||||||
|
|
||||||
|
$contentLength = get_headers($url)['Content-Length'];
|
||||||
|
|
||||||
|
if (array_key_exists($contentLength, $knownLengths)) {
|
||||||
|
$exception = new RealDebridBadUrlException($knownLengths[$contentLength]);
|
||||||
|
$this->logger->error($exception->getMessage());
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user