From 5cf61e1df696fe6f1ef566d66f962c21eb438695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=86=E3=82=AF=E3=83=8B=E3=82=AB=E3=83=AB=E8=AB=8F?= =?UTF-8?q?=E8=A8=AA=E5=AD=90?= Date: Wed, 15 Dec 2021 10:39:11 +0900 Subject: [PATCH] =?UTF-8?q?CURL=E3=81=AF=E4=B8=80=E8=87=B4=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Peertube/Common.php | 36 +++------------ app/Http/Controllers/Peertube/Watch.php | 46 ++----------------- resources/views/pages/peertube/w.blade.php | 10 +--- .../peertube/parts/manifest.blade.php | 13 +++++- .../component/peertube/parts/meta.blade.php | 15 ++++-- .../peertube/parts/stylelink.blade.php | 11 ++++- .../views/theme/techsuwa/peertube.blade.php | 8 +++- 7 files changed, 53 insertions(+), 86 deletions(-) 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') - -
- @include('theme.'.env('THEME').'.component.peertube.parts.header') -
- @include('theme.'.env('THEME').'.component.peertube.parts.menu') - @include('theme.'.env('THEME').'.component.peertube.w') -
-
- + @include('theme.'.env('THEME').'.component.peertube.w') @endsection diff --git a/resources/views/theme/techsuwa/component/peertube/parts/manifest.blade.php b/resources/views/theme/techsuwa/component/peertube/parts/manifest.blade.php index 6c21683..5a89a25 100644 --- a/resources/views/theme/techsuwa/component/peertube/parts/manifest.blade.php +++ b/resources/views/theme/techsuwa/component/peertube/parts/manifest.blade.php @@ -1,3 +1,12 @@ +name; + else if ($res['page'] == 'account') $name = $res['owner']->displayName.'さんのチャンネル一覧'; + } +?> + @@ -12,5 +21,7 @@ -{{ $res['detail']->name }} - 076動画 + + {{ $name }} - 076動画 + \ No newline at end of file diff --git a/resources/views/theme/techsuwa/component/peertube/parts/meta.blade.php b/resources/views/theme/techsuwa/component/peertube/parts/meta.blade.php index 6a910cf..a5bf89c 100644 --- a/resources/views/theme/techsuwa/component/peertube/parts/meta.blade.php +++ b/resources/views/theme/techsuwa/component/peertube/parts/meta.blade.php @@ -1,6 +1,15 @@ +name; + else if ($res['page'] == 'account') $name = $res['owner']->displayName.'さんのチャンネル一覧'; + } +?> + - + @@ -9,11 +18,11 @@ - + - + \ No newline at end of file diff --git a/resources/views/theme/techsuwa/component/peertube/parts/stylelink.blade.php b/resources/views/theme/techsuwa/component/peertube/parts/stylelink.blade.php index d1a8702..2fc5611 100644 --- a/resources/views/theme/techsuwa/component/peertube/parts/stylelink.blade.php +++ b/resources/views/theme/techsuwa/component/peertube/parts/stylelink.blade.php @@ -1,4 +1,13 @@ - +name; + else if ($res['page'] == 'account') $name = $res['owner']->displayName.'さんのチャンネル一覧'; + } +?> + + diff --git a/resources/views/theme/techsuwa/peertube.blade.php b/resources/views/theme/techsuwa/peertube.blade.php index c6d958f..0714cfc 100644 --- a/resources/views/theme/techsuwa/peertube.blade.php +++ b/resources/views/theme/techsuwa/peertube.blade.php @@ -8,6 +8,12 @@ - @yield('content') +
+ @include('theme.'.env('THEME').'.component.peertube.parts.header') +
+ @include('theme.'.env('THEME').'.component.peertube.parts.menu') + @yield('content') +
+
\ No newline at end of file