forked from mirror/pixelfed
Update DiscoverController
This commit is contained in:
parent
7869ee9a92
commit
a39f0e9d52
|
@ -13,21 +13,31 @@ use App\{
|
||||||
};
|
};
|
||||||
use Auth, DB, Cache;
|
use Auth, DB, Cache;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use App\Transformer\Api\StatusStatelessTransformer;
|
||||||
|
use League\Fractal;
|
||||||
|
use League\Fractal\Serializer\ArraySerializer;
|
||||||
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||||
|
|
||||||
class DiscoverController extends Controller
|
class DiscoverController extends Controller
|
||||||
{
|
{
|
||||||
|
protected $fractal;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->middleware('auth');
|
$this->fractal = new Fractal\Manager();
|
||||||
|
$this->fractal->setSerializer(new ArraySerializer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function home(Request $request)
|
public function home(Request $request)
|
||||||
{
|
{
|
||||||
|
abort_if(!Auth::check(), 403);
|
||||||
return view('discover.home');
|
return view('discover.home');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showTags(Request $request, $hashtag)
|
public function showTags(Request $request, $hashtag)
|
||||||
{
|
{
|
||||||
|
abort_if(!Auth::check(), 403);
|
||||||
|
|
||||||
$tag = Hashtag::whereSlug($hashtag)
|
$tag = Hashtag::whereSlug($hashtag)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
|
@ -81,6 +91,8 @@ class DiscoverController extends Controller
|
||||||
|
|
||||||
public function showCategory(Request $request, $slug)
|
public function showCategory(Request $request, $slug)
|
||||||
{
|
{
|
||||||
|
abort_if(!Auth::check(), 403);
|
||||||
|
|
||||||
$tag = DiscoverCategory::whereActive(true)
|
$tag = DiscoverCategory::whereActive(true)
|
||||||
->whereSlug($slug)
|
->whereSlug($slug)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
@ -99,6 +111,8 @@ class DiscoverController extends Controller
|
||||||
|
|
||||||
public function showPersonal(Request $request)
|
public function showPersonal(Request $request)
|
||||||
{
|
{
|
||||||
|
abort_if(!Auth::check(), 403);
|
||||||
|
|
||||||
$profile = Auth::user()->profile;
|
$profile = Auth::user()->profile;
|
||||||
|
|
||||||
$tags = Cache::remember('profile-'.$profile->id.':hashtags', now()->addMinutes(15), function() use ($profile){
|
$tags = Cache::remember('profile-'.$profile->id.':hashtags', now()->addMinutes(15), function() use ($profile){
|
||||||
|
@ -123,4 +137,35 @@ class DiscoverController extends Controller
|
||||||
}
|
}
|
||||||
return view('discover.loops.home');
|
return view('discover.loops.home');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loopsApi(Request $request)
|
||||||
|
{
|
||||||
|
abort_if(!config('exp.loops'), 403);
|
||||||
|
|
||||||
|
// todo proper pagination, maybe LoopService
|
||||||
|
$loops = Status::whereType('video')
|
||||||
|
->whereScope('public')
|
||||||
|
->latest()
|
||||||
|
->take(18)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$resource = new Fractal\Resource\Collection($loops, new StatusStatelessTransformer());
|
||||||
|
return $this->fractal->createData($resource)->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function loopWatch(Request $request)
|
||||||
|
{
|
||||||
|
abort_if(!Auth::check(), 403);
|
||||||
|
abort_if(!config('exp.loops'), 403);
|
||||||
|
|
||||||
|
$this->validate($request, [
|
||||||
|
'id' => 'integer|min:1'
|
||||||
|
]);
|
||||||
|
$id = $request->input('id');
|
||||||
|
|
||||||
|
// todo log loops
|
||||||
|
|
||||||
|
return response()->json(200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue