add torrent file validation

This commit is contained in:
ghost 2023-10-08 04:25:38 +03:00
parent 5aa20e6a22
commit f919a7ed85
2 changed files with 14 additions and 6 deletions

View File

@ -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();
}

View File

@ -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
{