mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-02-02 01:54:13 +00:00
prevend duplicates upload by md5 file check #11
This commit is contained in:
parent
bd772f87d1
commit
1f7d8d0810
@ -257,6 +257,12 @@ class TorrentController extends AbstractController
|
|||||||
$form['torrent']['error'][] = $translator->trans('Torrent file out of size limit');
|
$form['torrent']['error'][] = $translator->trans('Torrent file out of size limit');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// Check for duplicates
|
||||||
|
if ($torrentService->findTorrentByMd5File(md5_file($file->getPathName())))
|
||||||
|
{
|
||||||
|
$form['torrent']['error'][] = $translator->trans('Torrent file already exists');
|
||||||
|
}
|
||||||
|
|
||||||
//// Validate torrent format
|
//// Validate torrent format
|
||||||
if (!$torrentService->readTorrentFileByFilepath($file->getPathName()))
|
if (!$torrentService->readTorrentFileByFilepath($file->getPathName()))
|
||||||
{
|
{
|
||||||
|
@ -28,6 +28,9 @@ class Torrent
|
|||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
private ?bool $approved = null;
|
private ?bool $approved = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 32)]
|
||||||
|
private ?string $md5file = null;
|
||||||
|
|
||||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||||
private ?string $keywords = null;
|
private ?string $keywords = null;
|
||||||
|
|
||||||
@ -88,6 +91,18 @@ class Torrent
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMd5file(): ?string
|
||||||
|
{
|
||||||
|
return $this->md5file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMd5file(string $md5file): static
|
||||||
|
{
|
||||||
|
$this->md5file = $md5file;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getKeywords(): ?string
|
public function getKeywords(): ?string
|
||||||
{
|
{
|
||||||
return $this->keywords;
|
return $this->keywords;
|
||||||
|
@ -209,6 +209,7 @@ class TorrentService
|
|||||||
$torrent = $this->addTorrent(
|
$torrent = $this->addTorrent(
|
||||||
$userId,
|
$userId,
|
||||||
$added,
|
$added,
|
||||||
|
md5_file($filepath),
|
||||||
$this->generateTorrentKeywordsByTorrentFilepath(
|
$this->generateTorrentKeywordsByTorrentFilepath(
|
||||||
$filepath
|
$filepath
|
||||||
),
|
),
|
||||||
@ -256,6 +257,7 @@ class TorrentService
|
|||||||
public function addTorrent(
|
public function addTorrent(
|
||||||
int $userId,
|
int $userId,
|
||||||
int $added,
|
int $added,
|
||||||
|
string $md5file,
|
||||||
string $keywords,
|
string $keywords,
|
||||||
bool $approved
|
bool $approved
|
||||||
): ?Torrent
|
): ?Torrent
|
||||||
@ -264,6 +266,7 @@ class TorrentService
|
|||||||
|
|
||||||
$torrent->setUserId($userId);
|
$torrent->setUserId($userId);
|
||||||
$torrent->setAdded($added);
|
$torrent->setAdded($added);
|
||||||
|
$torrent->setMd5File($md5file);
|
||||||
$torrent->setKeywords($keywords);
|
$torrent->setKeywords($keywords);
|
||||||
$torrent->setApproved($approved);
|
$torrent->setApproved($approved);
|
||||||
|
|
||||||
@ -294,6 +297,17 @@ class TorrentService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findTorrentByMd5File(string $md5file) : ?Torrent
|
||||||
|
{
|
||||||
|
return $this->entityManagerInterface
|
||||||
|
->getRepository(Torrent::class)
|
||||||
|
->findOneBy(
|
||||||
|
[
|
||||||
|
'md5file' => $md5file
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function setTorrentsApprovedByUserId(
|
public function setTorrentsApprovedByUserId(
|
||||||
int $userId,
|
int $userId,
|
||||||
bool $value
|
bool $value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user