From 5fd8ac873367c4ae83fce807838444ee1baee3ab Mon Sep 17 00:00:00 2001 From: Roardom Date: Mon, 1 Jan 2024 17:03:21 +0000 Subject: [PATCH] update: enforce max torrents per page --- app/Http/Controllers/API/TorrentController.php | 2 +- app/Http/Livewire/TorrentSearch.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/API/TorrentController.php b/app/Http/Controllers/API/TorrentController.php index 2539cc8913..0f3421b0c5 100644 --- a/app/Http/Controllers/API/TorrentController.php +++ b/app/Http/Controllers/API/TorrentController.php @@ -447,7 +447,7 @@ public function filter(Request $request): TorrentsResource|\Illuminate\Http\Json ->when($request->filled('episodeNumber'), fn ($query) => $query->ofEpisode((int) $request->episodeNumber)) ->latest('sticky') ->orderBy($request->input('sortField') ?? $this->sortField, $request->input('sortDirection') ?? $this->sortDirection) - ->cursorPaginate($request->input('perPage') ?? $this->perPage); + ->cursorPaginate(min($request->input('perPage') ?? $this->perPage, 100)); $movieIds = $torrents->getCollection()->where('meta', '=', 'movie')->pluck('tmdb'); $tvIds = $torrents->getCollection()->where('meta', '=', 'tv')->pluck('tmdb'); diff --git a/app/Http/Livewire/TorrentSearch.php b/app/Http/Livewire/TorrentSearch.php index 15a027422b..3cf21729b6 100644 --- a/app/Http/Livewire/TorrentSearch.php +++ b/app/Http/Livewire/TorrentSearch.php @@ -310,7 +310,7 @@ final public function getTorrentsProperty(): \Illuminate\Contracts\Pagination\Le ->where($this->filters()) ->latest('sticky') ->orderBy($this->sortField, $this->sortDirection) - ->paginate($this->perPage); + ->paginate(min($this->perPage, 100)); $movieIds = $torrents->getCollection()->where('meta', '=', 'movie')->pluck('tmdb'); $tvIds = $torrents->getCollection()->where('meta', '=', 'tv')->pluck('tmdb'); @@ -362,7 +362,7 @@ final public function getGroupedTorrentsProperty() ->groupBy('tmdb', 'meta') ->latest('sticky') ->orderBy($this->sortField, $this->sortDirection) - ->paginate($this->perPage); + ->paginate(min($this->perPage, 100)); $movieIds = $groups->getCollection()->where('meta', '=', 'movie')->pluck('tmdb'); $tvIds = $groups->getCollection()->where('meta', '=', 'tv')->pluck('tmdb'); @@ -602,7 +602,7 @@ final public function getGroupedPostersProperty() ->groupBy('tmdb', 'meta') ->latest('sticky') ->orderBy($this->sortField, $this->sortDirection) - ->paginate($this->perPage); + ->paginate(min($this->perPage, 100)); $movieIds = $groups->getCollection()->where('meta', '=', 'movie')->pluck('tmdb'); $tvIds = $groups->getCollection()->where('meta', '=', 'tv')->pluck('tmdb');