Browse Source

add torrent file validation

main
ghost 1 year ago
parent
commit
f919a7ed85
  1. 2
      src/Controller/TorrentController.php
  2. 18
      src/Service/TorrentService.php

2
src/Controller/TorrentController.php

@ -45,7 +45,7 @@ class TorrentController extends AbstractController @@ -45,7 +45,7 @@ class TorrentController extends AbstractController
}
// Read file
if (!$file = $torrentService->readTorrentFileById($torrent->getId()))
if (!$file = $torrentService->readTorrentFileByTorrentId($torrent->getId()))
{
throw $this->createNotFoundException();
}

18
src/Service/TorrentService.php

@ -32,14 +32,22 @@ class TorrentService @@ -32,14 +32,22 @@ class TorrentService
// Tools
public function readTorrentFileByFilepath(
string $filepath
): \Rhilip\Bencode\TorrentFile
): ?\Rhilip\Bencode\TorrentFile
{
return \Rhilip\Bencode\TorrentFile::load(
$filepath
);
try
{
return \Rhilip\Bencode\TorrentFile::load(
$filepath
);
}
catch (\Rhilip\Bencode\ParseException $error)
{
return null;
}
}
public function readTorrentFileById(
public function readTorrentFileByTorrentId(
int $id
): \Rhilip\Bencode\TorrentFile
{

Loading…
Cancel
Save