mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-28 14:31:10 -05:00
fix: movie wishlist system
This commit is contained in:
@@ -49,7 +49,7 @@ class TorrentHelper
|
||||
|
||||
$uploader = $torrent->uploader;
|
||||
|
||||
$wishes = Wish::where('imdb', '=', 'tt'.$torrent->imdb)->whereNull('source')->get();
|
||||
$wishes = Wish::where('tmdb', '=', $torrent->tmdb)->whereNull('source')->get();
|
||||
if ($wishes) {
|
||||
foreach ($wishes as $wish) {
|
||||
$wish->source = \sprintf('%s/torrents/%s', $appurl, $torrent->id);
|
||||
|
||||
@@ -17,6 +17,8 @@ use App\Interfaces\WishInterface;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Services\Tmdb\TMDBScraper;
|
||||
use App\Services\Tmdb\Client\Movie;
|
||||
|
||||
/**
|
||||
* @see \Tests\Todo\Feature\Http\Controllers\WishControllerTest
|
||||
@@ -48,8 +50,6 @@ class WishController extends Controller
|
||||
*/
|
||||
public function index(Request $request, $username)
|
||||
{
|
||||
abort(307);
|
||||
|
||||
$user = User::with('wishes')->where('username', '=', $username)->firstOrFail();
|
||||
|
||||
\abort_unless(($request->user()->group->is_modo || $request->user()->id == $user->id), 403);
|
||||
@@ -73,33 +73,35 @@ class WishController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
if ($request->get('imdb') == 0) {
|
||||
if ($request->get('tmdb') === 0) {
|
||||
return \redirect()
|
||||
->route('wishes.index', ['username' => $user->username])
|
||||
->withErrors('IMDB Entry Required');
|
||||
->withErrors('TMDB ID Required');
|
||||
}
|
||||
|
||||
$imdb = Str::startsWith($request->get('imdb'), 'tt') ? $request->get('imdb') : 'tt'.$request->get('imdb');
|
||||
$tmdb = $request->get('tmdb');
|
||||
|
||||
if ($this->wish->exists($user->id, $imdb)) {
|
||||
if ($this->wish->exists($user->id, $tmdb)) {
|
||||
return \redirect()
|
||||
->route('wishes.index', ['username' => $user->username])
|
||||
->withErrors('Wish already exists!');
|
||||
}
|
||||
|
||||
$omdb = $this->wish->omdbRequest($imdb);
|
||||
if ($omdb === null || $omdb === false) {
|
||||
$client = new Movie($tmdb);
|
||||
$meta = $client->index();
|
||||
|
||||
if ($meta === null || $meta === false) {
|
||||
return \redirect()
|
||||
->route('wishes.index', ['username' => $user->username])
|
||||
->withErrors('IMDB Bad Request!');
|
||||
->withErrors('TMDM Bad Request!');
|
||||
}
|
||||
|
||||
$source = $this->wish->getSource($imdb);
|
||||
$source = $this->wish->getSource($tmdb);
|
||||
|
||||
$this->wish->create([
|
||||
'title' => $omdb['Title'].' ('.$omdb['Year'].')',
|
||||
'type' => $omdb['Type'],
|
||||
'imdb' => $imdb,
|
||||
'title' => $meta['title'].' ('.$meta['release_date'].')',
|
||||
'type' => 'Movie',
|
||||
'tmdb' => $tmdb,
|
||||
'source' => $source,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
@@ -99,7 +99,7 @@ class WishRepository implements WishInterface
|
||||
{
|
||||
return (bool) $this->user->find($uid)
|
||||
->wishes()
|
||||
->where('imdb', '=', $id)
|
||||
->where('tmdb', '=', $id)
|
||||
->first();
|
||||
}
|
||||
|
||||
@@ -110,10 +110,8 @@ class WishRepository implements WishInterface
|
||||
*/
|
||||
public function isGranted($id)
|
||||
{
|
||||
$id = \str_replace('tt', '', $id);
|
||||
|
||||
return (bool) $this->torrent
|
||||
->where('imdb', '=', $id)
|
||||
->where('tmdb', '=', $id)
|
||||
->where('seeders', '>', 0)
|
||||
->where('status', '=', 1)
|
||||
->first();
|
||||
@@ -127,9 +125,8 @@ class WishRepository implements WishInterface
|
||||
public function getSource($id)
|
||||
{
|
||||
if ($this->isGranted($id)) {
|
||||
$id = \str_replace('tt', '', $id);
|
||||
$source = $this->torrent
|
||||
->where('imdb', '=', $id)
|
||||
->where('tmdb', '=', $id)
|
||||
->where('seeders', '>', 0)
|
||||
->where('status', '=', 1)
|
||||
->first();
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateWishesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('wishes', function (Blueprint $table) {
|
||||
$table->renameColumn('imdb', 'tmdb');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@
|
||||
@csrf
|
||||
|
||||
<div class="form-group mt-5">
|
||||
<label for="imdb"></label><input type="text" class="form-control" name="imdb" id="imdb"
|
||||
placeholder="IMDB ID">
|
||||
<label for="tmdb"></label><input type="text" class="form-control" name="tmdb" id="tmdb"
|
||||
placeholder="TMDB ID">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success mt-10">
|
||||
@@ -53,7 +53,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>@lang('torrent.title')</th>
|
||||
<th>IMDB</th>
|
||||
<th>TMDB</th>
|
||||
<th>@lang('common.status')</th>
|
||||
<th>@lang('common.delete')</th>
|
||||
</tr>
|
||||
@@ -73,8 +73,8 @@
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
<a href="http://www.imdb.com/title/{{ $wish->imdb }}" target="_blank">
|
||||
Link
|
||||
<a href="{{ route('mediahub.movies.show', ['id' => $wish->tmdb]) }}" target="_blank">
|
||||
MediaHub
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user