Browse Source

add torrents FS storage #11

main
ghost 1 year ago
parent
commit
1c1e5b02c1
  1. 35
      src/Service/TorrentService.php

35
src/Service/TorrentService.php

@ -10,18 +10,23 @@ use App\Repository\TorrentRepository;
use App\Repository\TorrentLocalesRepository; use App\Repository\TorrentLocalesRepository;
use App\Repository\TorrentSensitiveRepository; use App\Repository\TorrentSensitiveRepository;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Filesystem\Filesystem;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
class TorrentService class TorrentService
{ {
private EntityManagerInterface $entityManager; private KernelInterface $kernelInterface;
private ParameterBagInterface $parameterBagInterface; private EntityManagerInterface $entityManagerInterface;
public function __construct( public function __construct(
EntityManagerInterface $entityManager, KernelInterface $kernelInterface,
EntityManagerInterface $entityManagerInterface
) )
{ {
$this->entityManager = $entityManager; $this->kernelInterface = $kernelInterface;
$this->entityManagerInterface = $entityManagerInterface;
} }
public function decodeTorrentByFilepath(string $filepath): array public function decodeTorrentByFilepath(string $filepath): array
@ -79,6 +84,16 @@ class TorrentService
$this->getTorrentKeywordsByFilepath($filepath) $this->getTorrentKeywordsByFilepath($filepath)
); );
$filesystem = new Filesystem();
$filesystem->copy(
$filepath,
sprintf(
'%s/var/torrents/%s.torrent',
$this->kernelInterface->getProjectDir(),
implode('/', str_split($torrent->getId()))
)
);
if (!empty($locales)) if (!empty($locales))
{ {
$this->saveTorrentLocales( $this->saveTorrentLocales(
@ -111,8 +126,8 @@ class TorrentService
$torrent->setFilename($filepath); $torrent->setFilename($filepath);
$torrent->setKeywords($keywords); $torrent->setKeywords($keywords);
$this->entityManager->persist($torrent); $this->entityManagerInterface->persist($torrent);
$this->entityManager->flush(); $this->entityManagerInterface->flush();
return $torrent; return $torrent;
} }
@ -133,8 +148,8 @@ class TorrentService
$torrentLocales->setValue($value); $torrentLocales->setValue($value);
$torrentLocales->setApproved($approved); $torrentLocales->setApproved($approved);
$this->entityManager->persist($torrentLocales); $this->entityManagerInterface->persist($torrentLocales);
$this->entityManager->flush(); $this->entityManagerInterface->flush();
return $torrentLocales; return $torrentLocales;
} }
@ -155,8 +170,8 @@ class TorrentService
$torrentSensitive->setValue($value); $torrentSensitive->setValue($value);
$torrentSensitive->setApproved($approved); $torrentSensitive->setApproved($approved);
$this->entityManager->persist($torrentSensitive); $this->entityManagerInterface->persist($torrentSensitive);
$this->entityManager->flush(); $this->entityManagerInterface->flush();
return $torrentSensitive; return $torrentSensitive;
} }

Loading…
Cancel
Save