|
|
|
|
@@ -2,8 +2,10 @@
|
|
|
|
|
|
|
|
|
|
namespace App\Download\Framework\Controller;
|
|
|
|
|
|
|
|
|
|
use App\Download\Action\Handler\Exception\RealDebridBadUrlException;
|
|
|
|
|
use App\Download\Action\Input\DownloadMediaInput;
|
|
|
|
|
use App\Download\Framework\Repository\DownloadRepository;
|
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
@@ -18,6 +20,7 @@ class ApiController extends AbstractController
|
|
|
|
|
private DownloadRepository $downloadRepository,
|
|
|
|
|
private MessageBusInterface $bus,
|
|
|
|
|
private readonly HubInterface $hub,
|
|
|
|
|
private readonly LoggerInterface $logger,
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
#[Route('/api/download', name: 'api_download', methods: ['POST'])]
|
|
|
|
|
@@ -25,6 +28,12 @@ class ApiController extends AbstractController
|
|
|
|
|
Request $request,
|
|
|
|
|
DownloadMediaInput $input,
|
|
|
|
|
): Response {
|
|
|
|
|
try {
|
|
|
|
|
$this->validateUrl($input->url);
|
|
|
|
|
} catch (RealDebridBadUrlException $e) {
|
|
|
|
|
return $this->json(['error' => $e->getMessage()]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$download = $this->downloadRepository->insert(
|
|
|
|
|
$this->getUser(),
|
|
|
|
|
$input->url,
|
|
|
|
|
@@ -56,4 +65,22 @@ class ApiController extends AbstractController
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|