diff --git a/config/services.yaml b/config/services.yaml index 6db8ab4..71fefcb 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -34,3 +34,9 @@ services: # add more service definitions when explicit configuration is needed # please note that last definitions always *replace* previous ones + + App\Twig\AppExtension: + arguments: + - '@service_container' + tags: + - { name: twig.extension} \ No newline at end of file diff --git a/public/asset/default/css/framework.css b/public/asset/default/css/framework.css index f758123..5f3f6cb 100644 --- a/public/asset/default/css/framework.css +++ b/public/asset/default/css/framework.css @@ -99,6 +99,12 @@ a.label-green:hover { background-color: #65916d; } +.button { + border: transparent 1px solid; + border-radius: 3px; + padding: 8px; +} + .button-green { color: #fff; background-color: #65916d; @@ -206,8 +212,12 @@ a:visited.background-color-hover-night-light:hover { cursor: help; } -.font-width-normal { - font-weight: normal; +.font-weight-normal { + font-weight: normal +} + +.font-weight-200 { + font-weight: 200 } .font-size-10 { diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index 7140055..af80317 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -11,6 +11,7 @@ use Symfony\Component\HttpFoundation\Request; use App\Service\UserService; use App\Service\TorrentService; +use App\Service\TimeService; class TorrentController extends AbstractController { @@ -28,8 +29,10 @@ class TorrentController extends AbstractController )] public function info( Request $request, + TranslatorInterface $translator, UserService $userService, - TorrentService $torrentService + TorrentService $torrentService, + TimeService $timeService ): Response { // Init user @@ -37,8 +40,29 @@ class TorrentController extends AbstractController $request->getClientIp() ); + if (!$torrent = $torrentService->getTorrent($request->get('id'))) + { + throw $this->createNotFoundException(); + } + + /* + if (!$torrent = $torrentService->getTorrentLocales($request->get('id'))) + { + throw $this->createNotFoundException(); + } + */ + return $this->render('default/torrent/info.html.twig', [ - 'title' => 'test' + 'torrent' => + [ + 'id' => $torrent->getId(), + 'locales' => [], //$torrent->getLocales(), + 'pages' => [] + ], + 'file' => $torrentService->decodeTorrentById( + $torrent->getId() + ), + 'trackers' => explode('|', $this->getParameter('app.trackers')), ]); } diff --git a/src/Repository/TorrentRepository.php b/src/Repository/TorrentRepository.php index 53b6358..60975fb 100644 --- a/src/Repository/TorrentRepository.php +++ b/src/Repository/TorrentRepository.php @@ -20,4 +20,14 @@ class TorrentRepository extends ServiceEntityRepository { parent::__construct($registry, Torrent::class); } + + public function findOneByIdField(int $id): ?Torrent + { + return $this->createQueryBuilder('t') + ->where('t.id = :id') + ->setParameter('id', $id) + ->getQuery() + ->getOneOrNullResult() + ; + } } diff --git a/src/Service/TorrentService.php b/src/Service/TorrentService.php index 1a195b0..d99dad5 100644 --- a/src/Service/TorrentService.php +++ b/src/Service/TorrentService.php @@ -29,6 +29,19 @@ class TorrentService $this->entityManagerInterface = $entityManagerInterface; } + public function decodeTorrentById(int $id): array + { + $decoder = new \BitTorrent\Decoder(); + + return $decoder->decodeFile( + sprintf( + '%s/var/torrents/%s.torrent', + $this->kernelInterface->getProjectDir(), + implode('/', str_split($id)) + ) + ); + } + public function decodeTorrentByFilepath(string $filepath): array { $decoder = new \BitTorrent\Decoder(); @@ -70,6 +83,13 @@ class TorrentService return ''; } + public function getTorrent(int $id): ?Torrent + { + return $this->entityManagerInterface + ->getRepository(Torrent::class) + ->findOneByIdField($id); + } + public function submit( string $filepath, int $userId, diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php new file mode 100644 index 0000000..757d40e --- /dev/null +++ b/src/Twig/AppExtension.php @@ -0,0 +1,55 @@ +container = $container; + } + + public function getFilters() + { + return + [ + new TwigFilter( + 'format_bytes', + [ + $this, + 'formatBytes' + ] + ), + ]; + } + + public function formatBytes( + int $bytes, + int $precision = 2 + ) : string + { + $size = [ + 'B', + 'Kb', + 'Mb', + 'Gb', + 'Tb', + 'Pb', + 'Eb', + 'Zb', + 'Yb' + ]; + + $factor = floor((strlen($bytes) - 1) / 3); + + return sprintf("%.{$precision}f", $bytes / pow(1024, $factor)) . ' ' . @$size[$factor]; + } +} \ No newline at end of file diff --git a/templates/default/torrent/info.html.twig b/templates/default/torrent/info.html.twig index 3389f18..be42910 100644 --- a/templates/default/torrent/info.html.twig +++ b/templates/default/torrent/info.html.twig @@ -1,2 +1,221 @@ {% extends 'default/layout.html.twig' %} -{% block title %}{{ title }} - {{ name }}{% endblock %} \ No newline at end of file +{% block title %}{{ 'Torrent'|trans }} #{{ torrent.id }} - {{ name }}{% endblock %} +{% block main_content %} +
+ {{ 'Name'|trans }} + | +|
+ {{ file.info.name }} + | +|
+ {{ 'Created'|trans }} + | +|
+ {{ file['creation date'] | format_date }} + | +|
+ {{ 'Generated'|trans }} + | +|
+ {{ file['created by'] }} + | +|
+ {{ 'Encoding'|trans }} + | +|
+ {{ file.encoding }} + | +|
+ {{ 'Comment'|trans }} + | +|
+ {{ file.comment }} + | +|
+ {{ 'Files'|trans }} + | +|
+ | |
+ /..+ |
+ |
+ {% for path in info.path %}
+ ../{{ path }}+ {% endfor %} + |
+
+ {{ info.length | format_bytes }}+ |
+
+ | |
+ {{ 'Trackers'|trans }} + | +|
+ | |
+ {{ tracker }} + | +|
+ {{ file.announce }} + | ++ {% if file.announce not in trackers %} + + + + {% endif %} + | +
+ {{ announce }} + | ++ {% if announce not in trackers %} + + + + {% endif %} + | +
+ | |
+ {{ 'Locales'|trans }} + | +|
+ | |
+ + {{'Edit'|trans }} + + | +|
+ + {{'Add'|trans }} + + | +|
+ | |
+ {{ 'Pages'|trans }} + | +|
+ | |
+ + {{'Edit'|trans }} + + | +|
+ + {{'Add'|trans }} + + | +