Browse Source

add wanted raw file with download feature

main
ghost 1 year ago
parent
commit
a128cb7cb3
  1. 120
      src/Controller/TorrentController.php
  2. 7
      templates/default/torrent/list.html.twig

120
src/Controller/TorrentController.php

@ -1874,6 +1874,126 @@ class TorrentController extends AbstractController @@ -1874,6 +1874,126 @@ class TorrentController extends AbstractController
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
#[Route(
'/torrent/{torrentId}/magnet',

7
templates/default/torrent/list.html.twig

@ -33,10 +33,11 @@ @@ -33,10 +33,11 @@
</a>
</h2>
{% 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"
title="{{ 'Active leechers waiting for seeders' | trans }}">
<a href="{{ path('torrent_file_wanted', { torrentId : torrent.id }) }}"
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 }}
</span>
</a>
{% endif %}
{% if torrent.approved == false %}
<sub class="margin-l-8-px float-right opacity-06 hover-opacity-1" title="{{ 'Waiting for approve' | trans }}">

Loading…
Cancel
Save