/** /* @ORM\PrePersist() /* @ORM\PreUpdate() */ public function preUpload() { //@todo filetype validation if (null !== $this->torrent_file) { $this->torrent_url = uniqid() . '.torrent'; // set torrent file size $torrent = new \Torrent_Torrent($this->torrent_file); $this->info_hash = $torrent->hash_info(); $this->size = $torrent->size(); } if (null !== $this->poster_file) { $this->poster_url = uniqid() . '.' . $this->poster_file->guessExtension(); } }
/** * Sends torrent file with current user passkey * * @Route("/{id}/download", name="torrent_download") * @Template() * @Secure(roles="ROLE_USER") */ public function downloadAction($id) { $em = $this->getDoctrine()->getEntityManager(); $entity = $em->getRepository('RootyTorrentBundle:Torrent')->find($id); $user = $this->get('security.context')->getToken()->getUser(); if (!$entity) { throw $this->createNotFoundException('Unable to find Torrent entity'); } /* Set the announce url and user passkey */ $announce_url = $this->container->getParameter('announce_url') . '?passkey=' . $user->getPasskey(); $torrent = new \Torrent_Torrent($entity->getTorrentAbsolutePath()); $torrent->announce($announce_url); $torrent->send(); }