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'), ], ];