mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-02-02 01:54:13 +00:00
add wanted raw file with download feature
This commit is contained in:
parent
2d2c6be016
commit
a128cb7cb3
@ -1874,6 +1874,126 @@ class TorrentController extends AbstractController
|
|||||||
return $response->setContent($data);
|
return $response->setContent($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Torrent download wanted file
|
||||||
|
#[Route(
|
||||||
|
'/torrent/{torrentId}/file/wanted',
|
||||||
|
name: 'torrent_file_wanted',
|
||||||
|
requirements:
|
||||||
|
[
|
||||||
|
'torrentId' => '\d+'
|
||||||
|
],
|
||||||
|
methods:
|
||||||
|
[
|
||||||
|
'GET'
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
public function downloadFileWanted(
|
||||||
|
Request $request,
|
||||||
|
TranslatorInterface $translator,
|
||||||
|
UserService $userService,
|
||||||
|
TorrentService $torrentService,
|
||||||
|
ActivityService $activityService
|
||||||
|
): Response
|
||||||
|
{
|
||||||
|
// Init user
|
||||||
|
$user = $this->initUser(
|
||||||
|
$request,
|
||||||
|
$userService,
|
||||||
|
$activityService
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$user->isStatus())
|
||||||
|
{
|
||||||
|
// @TODO
|
||||||
|
throw new \Exception(
|
||||||
|
$translator->trans('Access denied')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Block crawler requests
|
||||||
|
if (in_array($request->getClientIp(), explode('|', $this->getParameter('app.crawlers'))))
|
||||||
|
{
|
||||||
|
throw $this->createNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init torrent
|
||||||
|
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
|
||||||
|
{
|
||||||
|
throw $this->createNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$file = $torrentService->readTorrentFileByTorrentId($torrent->getId()))
|
||||||
|
{
|
||||||
|
throw $this->createNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sensitive filter
|
||||||
|
if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && $user->isSensitive())
|
||||||
|
{
|
||||||
|
throw $this->createNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Approved filter
|
||||||
|
if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && !$torrent->isApproved())
|
||||||
|
{
|
||||||
|
throw $this->createNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register download
|
||||||
|
$torrentService->addTorrentDownloadFile(
|
||||||
|
$torrent->getId(),
|
||||||
|
$user->getId(),
|
||||||
|
time()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Register download event
|
||||||
|
$activityService->addEventTorrentDownloadFileAdd(
|
||||||
|
$user->getId(),
|
||||||
|
time(),
|
||||||
|
$torrent->getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Apply filters
|
||||||
|
$file = $this->filterYggdrasil(
|
||||||
|
$file,
|
||||||
|
false // wanted file downloading with original trackers
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get data
|
||||||
|
$data = $file->dumpToString();
|
||||||
|
|
||||||
|
// Set headers
|
||||||
|
$response = new Response();
|
||||||
|
|
||||||
|
$response->headers->set(
|
||||||
|
'Content-type',
|
||||||
|
'application/x-bittorrent'
|
||||||
|
);
|
||||||
|
|
||||||
|
$response->headers->set(
|
||||||
|
'Content-length',
|
||||||
|
strlen($data)
|
||||||
|
);
|
||||||
|
|
||||||
|
$response->headers->set(
|
||||||
|
'Content-Disposition',
|
||||||
|
sprintf(
|
||||||
|
'attachment; filename="%s.wanted.%s.torrent";',
|
||||||
|
mb_strtolower(
|
||||||
|
$this->getParameter('app.name')
|
||||||
|
),
|
||||||
|
mb_strtolower(
|
||||||
|
$file->getName()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$response->sendHeaders();
|
||||||
|
|
||||||
|
// Return file content
|
||||||
|
return $response->setContent($data);
|
||||||
|
}
|
||||||
|
|
||||||
// Torrent download magnet
|
// Torrent download magnet
|
||||||
#[Route(
|
#[Route(
|
||||||
'/torrent/{torrentId}/magnet',
|
'/torrent/{torrentId}/magnet',
|
||||||
|
@ -33,10 +33,11 @@
|
|||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
{% if torrent.scrape.leechers > 0 and torrent.scrape.seeders == 0 %}
|
{% if torrent.scrape.leechers > 0 and torrent.scrape.seeders == 0 %}
|
||||||
<span class="label label-green margin-l-4-px font-size-10-px position-relative top--2 cursor-default"
|
<a href="{{ path('torrent_file_wanted', { torrentId : torrent.id }) }}"
|
||||||
title="{{ 'Active leechers waiting for seeders' | trans }}">
|
class="label label-green margin-l-4-px font-size-10-px position-relative top--2"
|
||||||
|
title="{{ 'Active leechers waiting for seeders' | trans }}">
|
||||||
{{ 'wanted' | trans }}
|
{{ 'wanted' | trans }}
|
||||||
</span>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if torrent.approved == false %}
|
{% if torrent.approved == false %}
|
||||||
<sub class="margin-l-8-px float-right opacity-06 hover-opacity-1" title="{{ 'Waiting for approve' | trans }}">
|
<sub class="margin-l-8-px float-right opacity-06 hover-opacity-1" title="{{ 'Waiting for approve' | trans }}">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user