Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Add) Ability to pull torrents via RSS #490

Merged
merged 18 commits into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
401 changes: 351 additions & 50 deletions app/Http/Controllers/RssController.php

Large diffs are not rendered by default.

227 changes: 227 additions & 0 deletions app/Http/Controllers/Staff/RssController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
*
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
* @author singularity43
*/

namespace App\Http\Controllers\Staff;

use Illuminate\Http\Request;
use App\Rss;
use App\Category;
use App\Type;
use Brian2694\Toastr\Toastr;
use App\Repositories\TorrentFacetedRepository;
use App\Http\Controllers\Controller;

class RssController extends Controller
{
/**
* @var TorrentFacetedRepository
*/
private $torrent_faceted;

/**
* @var Toastr
*/
private $toastr;

/**
* RssController Constructor
*
* @param TorrentFacetedRepository $torrent_faceted
* @param Toastr $toastr
*/
public function __construct(TorrentFacetedRepository $torrent_faceted, Toastr $toastr)
{
$this->torrent_faceted = $torrent_faceted;
$this->toastr = $toastr;
}

/**
* @param Toastr $toastr
*/
public function setToastr($toastr)
HDVinnie marked this conversation as resolved.
Show resolved Hide resolved
{
$this->toastr = $toastr;
}

/**
* Display a listing of the RSS resource.
*
* @param string $hash
* @return \Illuminate\Http\Response
*/
public function index($hash = null)
{
$public_rss = Rss::public()->orderBy('position', 'ASC')->get();

return view('Staff.rss.index', [
'hash' => $hash,
'public_rss' => $public_rss
]);
}

/**
* Show the form for creating a new RSS resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$user = auth()->user();
$torrent_repository = $this->torrent_faceted;

return view('Staff.rss.create', [
'torrent_repository' => $torrent_repository,
'categories' => Category::all()->sortBy('position'),
'types' => Type::all()->sortBy('position'),
'user' => $user ]);
}
/**
* Store a newly created RSS resource in storage.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$user = auth()->user();

$v = validator($request->all(), [
'name' => 'required|min:3|max:255',
'search' => 'max:255',
'description' => 'max:255',
'uploader' => 'max:255',
'categories' => "sometimes|array|max:999",
'types' => 'sometimes|array|max:999',
'genres' => 'sometimes|array|max:999',
'position' => 'sometimes|integer|max:9999',
]);

$params = $request->only(['type', 'name', 'position', 'search', 'description', 'uploader', 'imdb', 'tvdb', 'tmdb', 'mal', 'categories',
'types', 'genres', 'freeleech' ,'doubleupload','featured','stream','highspeed','sd','internal','alive','dying','dead']);

$error = null;
$success = null;

if ($v->passes()) {
$rss = new Rss();
$rss->name = $request->input('name');
$rss->user_id = $user->id;
$expected = $rss->expected;
$rss->json_torrent = array_merge($expected,$params);
$rss->is_private = 0;
$rss->staff_id = $user->id;
$rss->position = (int) $request->input('position');
$rss->save();
$success = "Public RSS Feed Created";
}
if(!$success) {
$error = "Unable To Process Request";
if ($v->errors()) {
$error = $v->errors();
}
return redirect()->route('Staff.rss.create')
->with($this->toastr->error($error, 'Uhoh!', ['options']));
}
return redirect()->route('Staff.rss.index')
->with($this->toastr->success($success, 'Congratulations!', ['options']));
}

/**
* Show the form for editing the specified RSS resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$user = auth()->user();
$rss = $user->rss()->where('is_private',0)->findOrFail($id);
$torrent_repository = $this->torrent_faceted;

return view('Staff.rss.edit', [
'torrent_repository' => $torrent_repository,
'categories' => Category::all()->sortBy('position'),
'types' => Type::all()->sortBy('position'),
'user' => $user,
'rss' => $rss,
]);
}

/**
* Update the specified RSS resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$user = auth()->user();
$rss = $user->rss()->where('is_private',0)->findOrFail($id);

$v = validator($request->all(), [
'name' => 'required|min:3|max:255',
'search' => 'max:255',
'description' => 'max:255',
'uploader' => 'max:255',
'categories' => "sometimes|array|max:999",
'types' => 'sometimes|array|max:999',
'genres' => 'sometimes|array|max:999',
'position' => 'sometimes|integer|max:9999',
]);

$params = $request->only(['type', 'position', 'search', 'description', 'uploader', 'imdb', 'tvdb', 'tmdb', 'mal', 'categories',
'types', 'genres', 'freeleech' ,'doubleupload','featured','stream','highspeed','sd','internal','alive','dying','dead']);

$error = null;
$success = null;
$redirect = null;

if ($v->passes()) {
$expected = $rss->expected;
$push = array_merge($expected,$params);
$rss->json_torrent = array_merge($rss->json_torrent,$push);
$rss->is_private = 0;
$rss->name = $request->input('name');
$rss->position = (int) $request->input('position');
$rss->save();
$success = "Public RSS Feed Updated";
}
if(!$success) {
$error = "Unable To Process Request";
if ($v->errors()) {
$error = $v->errors();
}
return redirect()->route('Staff.rss.edit', ['id' => $id])
->with($this->toastr->error($error, 'Uhoh!', ['options']));
}
return redirect()->route('Staff.rss.index')
->with($this->toastr->success($success, 'Congratulations!', ['options']));
}

/**
* Remove the specified RSS resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$rss = auth()->user()->rss()->where('is_private',0)->findOrFail($id);
$rss->delete();

return redirect()->route('Staff.rss.index')
->with($this->toastr->success('RSS Feed Deleted!', 'Yay!', ['options']));
}
}
21 changes: 14 additions & 7 deletions app/Http/Controllers/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use App\Type;
use App\User;
use App\History;
use App\Rss;
use App\Torrent;
use App\Warning;
use App\Category;
Expand Down Expand Up @@ -61,7 +62,7 @@ class TorrentController extends Controller
/**
* RequestController Constructor.
*
* @param RequestFacetedRepository $faceted
* @param TorrentFacetedRepository $faceted
* @param ChatRepository $chat
* @param Toastr $toastr
*/
Expand Down Expand Up @@ -166,11 +167,11 @@ public function groupingResults($category_id, $imdb)
->get();

return view('torrent.grouping_results', [
'user' => $user,
'user' => $user,
'personal_freeleech' => $personal_freeleech,
'torrents' => $torrents,
'imdb' => $imdb,
'category' => $category,
'torrents' => $torrents,
'imdb' => $imdb,
'category' => $category,
]);
}

Expand Down Expand Up @@ -866,13 +867,19 @@ public function downloadCheck($slug, $id)
*
* @param $slug
* @param $id
* @param $rsskey
*
* @return TorrentFile
*/
public function download($slug, $id)
public function download($slug, $id, $rsskey = null)
{
$torrent = Torrent::withAnyStatus()->findOrFail($id);

$user = auth()->user();
if(!$user && $rsskey) {
$user = User::where('rsskey','=',$rsskey)->firstOrFail();
}

$torrent = Torrent::withAnyStatus()->findOrFail($id);

// User's ratio is too low
if ($user->getRatio() < config('other.ratio')) {
Expand Down
Loading