From a868b677f04d1d7d4b9a2139511577013dfcee49 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Sun, 4 Sep 2022 09:24:09 +0800 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0=20=D0=B8=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20?= =?UTF-8?q?=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8?= =?UTF-8?q?=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/.env.example | 2 ++ src/app/Controllers/HomeController.php | 20 +++++++++++++++----- src/app/Core/PlaylistProcessor.php | 2 +- src/config/app.php | 2 ++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/.env.example b/src/.env.example index de4c437..1d980e5 100644 --- a/src/.env.example +++ b/src/.env.example @@ -5,3 +5,5 @@ TWIG_DEBUG=0 FLIGHT_CASE_SENSITIVE=0 FLIGHT_HANDLE_ERRORS=1 FLIGHT_LOG_ERRORS=1 +PAGE_SIZE=10 +SORT_BY= diff --git a/src/app/Controllers/HomeController.php b/src/app/Controllers/HomeController.php index 4ff37e0..dcba566 100644 --- a/src/app/Controllers/HomeController.php +++ b/src/app/Controllers/HomeController.php @@ -18,6 +18,15 @@ class HomeController extends Controller $this->ini = new PlaylistProcessor(); } + /** + * @return int + */ + protected function getPageSize(): int + { + $size = config('app.page_size'); + return empty($size) || $size < 5 || $size > 100 ? 10 : $size; + } + /** * @throws Exception */ @@ -28,11 +37,12 @@ class HomeController extends Controller Flight::redirect(base_url($id)); die; } - $per_page = 10; - $list = $this->ini->playlists - ->where('redirect_id', null) - // ->sortBy('id') - ->forPage($page, $per_page); + $per_page = $this->getPageSize(); + $list = $this->ini->playlists->where('redirect_id', null); + if (config('app.sort_by')) { + $list = $list->sortBy(config('app.sort_by')); + } + $list = $list->forPage($page, $per_page); view('list', [ 'updated_at' => $this->ini->updatedAt(), 'count' => $this->ini->playlists->count(), diff --git a/src/app/Core/PlaylistProcessor.php b/src/app/Core/PlaylistProcessor.php index c8ed6d8..954845b 100644 --- a/src/app/Core/PlaylistProcessor.php +++ b/src/app/Core/PlaylistProcessor.php @@ -49,7 +49,7 @@ final class PlaylistProcessor return $code < 400; } - protected function fetch(string $id) + protected function fetch(string $id): array { $curl = curl_init(); curl_setopt_array($curl, [ diff --git a/src/config/app.php b/src/config/app.php index 00cec23..0d4554b 100644 --- a/src/config/app.php +++ b/src/config/app.php @@ -26,5 +26,7 @@ return [ // 'CP866', // 'ISO-8859-5', ], + 'page_size' => (int)(env('PAGE_SIZE', 10)), + 'sort_by' => env('SORT_BY'), ], ];