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
} }
// Read file // Read file
if (!$file = $torrentService->readTorrentFileById($torrent->getId())) if (!$file = $torrentService->readTorrentFileByTorrentId($torrent->getId()))
{ {
throw $this->createNotFoundException(); throw $this->createNotFoundException();
} }

18
src/Service/TorrentService.php

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

Loading…
Cancel
Save