diff --git a/app/Http/Controllers/Peertube/Common.php b/app/Http/Controllers/Peertube/Common.php index 1c4e8b3..afbf66f 100644 --- a/app/Http/Controllers/Peertube/Common.php +++ b/app/Http/Controllers/Peertube/Common.php @@ -17,42 +17,20 @@ class Common extends Engine { } public function getLocal () { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, env('PEER_URI').'/api/v1/oauth-clients/local'); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - $get = curl_exec($ch); - $err = curl_error($ch); - curl_close($ch); - - if (!$get) return $err; - $get = json_decode($get); - if (isset($get->status) && $get->status == 404) return []; - - return $get; + return $this->ptapi_get('/api/v1/oauth-clients/local'); } public function getMe () { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, env('PEER_URI').'/api/v1/users/me'); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - $get = curl_exec($ch); - $err = curl_error($ch); - curl_close($ch); - - if (!$get) return $err; - $get = json_decode($get); - if (isset($get->status) && $get->status == 404) return []; - - return $get; + return $this->ptapi_get('/api/v1/users/me'); } public function getNotify () { + return $this->ptapi_get('/api/v1/users/me/notifications?start=0&count=0&unread=true'); + } + + public function ptapi_get ($url) { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, env('PEER_URI').'/api/v1/users/me/notifications?start=0&count=0&unread=true'); + curl_setopt($ch, CURLOPT_URL, env('PEER_URI').$url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); diff --git a/app/Http/Controllers/Peertube/Watch.php b/app/Http/Controllers/Peertube/Watch.php index 97b60a2..87d99cb 100644 --- a/app/Http/Controllers/Peertube/Watch.php +++ b/app/Http/Controllers/Peertube/Watch.php @@ -15,6 +15,7 @@ class Watch extends Common { public function index ($id) { $res = []; + $res['page'] = 'watch'; $res['detail'] = $this->getDetail($id); $res['comment'] = $this->getComment($id); $res['recommend'] = $this->getRecommend($res['detail']->tags); @@ -22,57 +23,18 @@ class Watch extends Common { } function getDetail ($id) { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, env('PEER_URI').'/api/v1/videos/'.$id); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - $get = curl_exec($ch); - $err = curl_error($ch); - curl_close($ch); - - if (!$get) return $err; - $get = json_decode($get); - - return $get; + return $this->ptapi_get('/api/v1/videos/'.$id); } public function getRecommend ($tags) { - $ch = curl_init(); $tag = ''; foreach ($tags as $t) { $tag .= 'tagsOneOf='.urlencode($t).'&'; } - - curl_setopt($ch, CURLOPT_URL, env('PEER_URI').'/api/v1/search/videos?start=0&count=6&nsfw=both&'.$tag.'sort=-publishedAt&searchTarget=local'); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - $get = curl_exec($ch); - $err = curl_error($ch); - curl_close($ch); - - if (!$get) return $err; - $get = json_decode($get); - if (isset($get->status) && $get->status == 404) return []; - - return $get; + return $this->ptapi_get('/api/v1/search/videos?start=0&count=6&nsfw=both&'.$tag.'sort=-publishedAt&searchTarget=local'); } public function getComment ($id) { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, env('PEER_URI').'/api/v1/videos/'.$id.'/comment-threads'); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - $get = curl_exec($ch); - $err = curl_error($ch); - curl_close($ch); - - if (!$get) return $err; - $get = json_decode($get); - if (isset($get->status) && $get->status == 404) return []; - - return $get; + return $this->ptapi_get('/api/v1/videos/'.$id.'/comment-threads'); } } diff --git a/resources/views/pages/peertube/w.blade.php b/resources/views/pages/peertube/w.blade.php index 686e2d2..9c4d463 100644 --- a/resources/views/pages/peertube/w.blade.php +++ b/resources/views/pages/peertube/w.blade.php @@ -1,13 +1,5 @@ @extends('theme.'.env('THEME').'.peertube') @section('content') - -