|
|
@ -29,39 +29,76 @@ class TorrentService |
|
|
|
$this->entityManagerInterface = $entityManagerInterface; |
|
|
|
$this->entityManagerInterface = $entityManagerInterface; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getStoragePathById(int $id): string |
|
|
|
// Tools |
|
|
|
|
|
|
|
public function readTorrentFileByFilepath( |
|
|
|
|
|
|
|
string $filepath |
|
|
|
|
|
|
|
): \Rhilip\Bencode\TorrentFile |
|
|
|
{ |
|
|
|
{ |
|
|
|
return sprintf( |
|
|
|
return \Rhilip\Bencode\TorrentFile::load( |
|
|
|
'%s/var/torrents/%s.torrent', |
|
|
|
$filepath |
|
|
|
$this->kernelInterface->getProjectDir(), |
|
|
|
); |
|
|
|
implode('/', str_split($id)) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function readTorrentFileById( |
|
|
|
|
|
|
|
int $id |
|
|
|
|
|
|
|
): \Rhilip\Bencode\TorrentFile |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $this->readTorrentFileByFilepath( |
|
|
|
|
|
|
|
$this->getStorageFilepathById($id) |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
public function generateTorrentKeywordsByTorrentFilepath( |
|
|
|
public function getTorrentKeywordsByFilepath(string $filepath): string |
|
|
|
string $filepath, |
|
|
|
|
|
|
|
int $minLength = 3 |
|
|
|
|
|
|
|
): string |
|
|
|
{ |
|
|
|
{ |
|
|
|
$data = $this->decodeTorrentByFilepath($filepath); |
|
|
|
$keywords = []; |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($data['info']['name'])) |
|
|
|
foreach ($this->readTorrentFileByFilepath($filepath)->getFileList() as $file) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return mb_strtolower( |
|
|
|
$words = explode( |
|
|
|
|
|
|
|
' ', |
|
|
|
preg_replace( |
|
|
|
preg_replace( |
|
|
|
'/[\s]+/', |
|
|
|
'/[\s]+/', |
|
|
|
' ', |
|
|
|
' ', |
|
|
|
preg_replace( |
|
|
|
preg_replace( |
|
|
|
'/[\W]+/', |
|
|
|
'/[\W]+/', |
|
|
|
' ', |
|
|
|
' ', |
|
|
|
$data['info']['name'] |
|
|
|
$file['path'] |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($words as $key => $value) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (mb_strlen($value) < $minLength) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
unset($words[$key]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$keywords = array_merge($keywords, $words); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return mb_strtolower( |
|
|
|
|
|
|
|
implode( |
|
|
|
|
|
|
|
',', |
|
|
|
|
|
|
|
array_unique($keywords) |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ''; |
|
|
|
public function getStorageFilepathById(int $id): string |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return sprintf( |
|
|
|
|
|
|
|
'%s/var/torrents/%s.torrent', |
|
|
|
|
|
|
|
$this->kernelInterface->getProjectDir(), |
|
|
|
|
|
|
|
implode('/', str_split($id)) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Getters |
|
|
|
public function getTorrent(int $id): ?Torrent |
|
|
|
public function getTorrent(int $id): ?Torrent |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->entityManagerInterface |
|
|
|
return $this->entityManagerInterface |
|
|
@ -69,6 +106,7 @@ class TorrentService |
|
|
|
->findOneByIdField($id); |
|
|
|
->findOneByIdField($id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Locales |
|
|
|
public function getTorrentLocales(int $id): ?TorrentLocales |
|
|
|
public function getTorrentLocales(int $id): ?TorrentLocales |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->entityManagerInterface |
|
|
|
return $this->entityManagerInterface |
|
|
@ -90,6 +128,29 @@ class TorrentService |
|
|
|
->findTorrentLocales($torrentId); |
|
|
|
->findTorrentLocales($torrentId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Sensitive |
|
|
|
|
|
|
|
public function getTorrentSensitive(int $id): ?TorrentSensitive |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $this->entityManagerInterface |
|
|
|
|
|
|
|
->getRepository(TorrentSensitive::class) |
|
|
|
|
|
|
|
->getTorrentLocales($id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function findLastTorrentSensitive(int $torrentId): ?TorrentSensitive |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $this->entityManagerInterface |
|
|
|
|
|
|
|
->getRepository(TorrentSensitive::class) |
|
|
|
|
|
|
|
->findLastTorrentSensitive($torrentId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function findTorrentSensitive(int $torrentId): array |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $this->entityManagerInterface |
|
|
|
|
|
|
|
->getRepository(TorrentSensitive::class) |
|
|
|
|
|
|
|
->findTorrentSensitive($torrentId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Setters |
|
|
|
public function add( |
|
|
|
public function add( |
|
|
|
string $filepath, |
|
|
|
string $filepath, |
|
|
|
int $userId, |
|
|
|
int $userId, |
|
|
@ -100,14 +161,18 @@ class TorrentService |
|
|
|
): ?Torrent |
|
|
|
): ?Torrent |
|
|
|
{ |
|
|
|
{ |
|
|
|
$torrent = $this->addTorrent( |
|
|
|
$torrent = $this->addTorrent( |
|
|
|
$this->getTorrentInfoNameByFilepath($filepath), |
|
|
|
$userId, |
|
|
|
$this->getTorrentKeywordsByFilepath($filepath) |
|
|
|
$added, |
|
|
|
|
|
|
|
$this->generateTorrentKeywordsByTorrentFilepath( |
|
|
|
|
|
|
|
$filepath |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
$approved |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$filesystem = new Filesystem(); |
|
|
|
$filesystem = new Filesystem(); |
|
|
|
$filesystem->copy( |
|
|
|
$filesystem->copy( |
|
|
|
$filepath, |
|
|
|
$filepath, |
|
|
|
$this->getStoragePathById( |
|
|
|
$this->getStorageFilepathById( |
|
|
|
$torrent->getId() |
|
|
|
$torrent->getId() |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
@ -135,14 +200,18 @@ class TorrentService |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function addTorrent( |
|
|
|
public function addTorrent( |
|
|
|
string $filepath, |
|
|
|
int $userId, |
|
|
|
string $keywords |
|
|
|
int $added, |
|
|
|
|
|
|
|
string $keywords, |
|
|
|
|
|
|
|
bool $approved |
|
|
|
): ?Torrent |
|
|
|
): ?Torrent |
|
|
|
{ |
|
|
|
{ |
|
|
|
$torrent = new Torrent(); |
|
|
|
$torrent = new Torrent(); |
|
|
|
|
|
|
|
|
|
|
|
$torrent->setFilename($filepath); |
|
|
|
$torrent->setUserId($userId); |
|
|
|
|
|
|
|
$torrent->setAdded($added); |
|
|
|
$torrent->setKeywords($keywords); |
|
|
|
$torrent->setKeywords($keywords); |
|
|
|
|
|
|
|
$torrent->setApproved($approved); |
|
|
|
|
|
|
|
|
|
|
|
$this->entityManagerInterface->persist($torrent); |
|
|
|
$this->entityManagerInterface->persist($torrent); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|