demo/app/Modules/Torrent/UI/Web/Handlers/DownloadHandler.php
2023-03-23 18:50:47 +01:00

27 lines
757 B
PHP

<?php
namespace LaraBB\Torrent\UI\Web\Handlers;
use LaraBB\Torrent\Actions\DownloadAction;
use LaraBB\Torrent\UI\Web\Requests\DownloadRequest;
use Rhilip\Bencode\TorrentFile;
class DownloadHandler
{
public function __construct(
private readonly DownloadAction $downloadAction
) {
}
public function __invoke(DownloadRequest $request)
{
$return = $this->downloadAction->run($request);
if(!is_null($return)) {
return response($return['torrentFile']->dumpToString())->header('Content-Type', 'application/x-bittorrent')
->header('Content-Disposition', 'attachment; filename="' . $return['filename'] . '.torrent"');
}
}
}