replace bencode library to rhilip/bencode, fix files tree builder #11

This commit is contained in:
ghost 2023-10-07 04:37:43 +03:00
parent 387acb59b6
commit 86e1455c6b
9 changed files with 175 additions and 130 deletions

View file

@ -189,7 +189,7 @@ class PageController extends AbstractController
continue;
}
if (empty($torrentService->getTorrentFilenameByFilepath($file->getPathName())))
if (empty($torrentService->getTorrentInfoNameByFilepath($file->getPathName())))
{
$form['torrent']['error'][] = $translator->trans('Could not parse torrent file');

View file

@ -40,28 +40,63 @@ class TorrentController extends AbstractController
$request->getClientIp()
);
// Init torrent
if (!$torrent = $torrentService->getTorrent($request->get('id')))
{
throw $this->createNotFoundException();
}
// Init file
try
{
$file = \Rhilip\Bencode\TorrentFile::load(
$torrentService->getStoragePathById(
$torrent->getId()
)
);
}
catch (ParseException $e)
{
throw $this->createNotFoundException();
}
/*
if (!$torrent = $torrentService->getTorrentLocales($request->get('id')))
{
throw $this->createNotFoundException();
}
*/
//print_r($file->getFileTree());exit;
return $this->render('default/torrent/info.html.twig', [
'torrent' =>
[
'id' => $torrent->getId(),
'added' => 0, // @TODO
'locales' => [], //$torrent->getLocales(),
'pages' => []
],
'file' => $torrentService->decodeTorrentById(
$torrent->getId()
),
'file' =>
[
'name' => $file->getName(),
'size' => $file->getSize(),
'count' => $file->getFileCount(),
'pieces' => $file->getPieceLength(),
'created' => $file->getCreationDate(),
'software' => $file->getCreatedBy(),
'protocol' => $file->getProtocol(),
'private' => $file->isPrivate(),
'source' => $file->getSource(),
'comment' => $file->getComment(),
'tree' => $file->getFileTree(),
'trackers' => $file->getAnnounceList(),
'hash' =>
[
'v1' => $file->getInfoHashV1(false),
'v2' => $file->getInfoHashV2(false)
],
'magnet' => $file->getMagnetLink()
],
'trackers' => explode('|', $this->getParameter('app.trackers')),
]);
}
@ -158,7 +193,7 @@ class TorrentController extends AbstractController
$form['torrent']['error'][] = $translator->trans('Torrent file out of size limit');
}
if (empty($torrentService->getTorrentFilenameByFilepath($file->getPathName())))
if (empty($torrentService->getTorrentInfoNameByFilepath($file->getPathName())))
{
$form['torrent']['error'][] = $translator->trans('Could not parse torrent file');
}