diff --git a/app/Livewire/DownloadsSearch.php b/app/Livewire/DownloadsSearch.php index 1a54313..b0d08ba 100644 --- a/app/Livewire/DownloadsSearch.php +++ b/app/Livewire/DownloadsSearch.php @@ -5,15 +5,37 @@ namespace App\Livewire; use App\Models\Downloads; use Livewire\Component; use Livewire\WithPagination; +use Livewire\Attributes\Url; class DownloadsSearch extends Component { use WithPagination; + #[Url(history: true)] public $fileSearch; public $order = 'created_at_desc'; + public $options = [ + 'FHD' => true, + 'FHD 48fps' => true, + ]; + + public $isOpen = false; + + // To toggle individual option selection + public function toggleOption($option) + { + $this->options[$option] = !$this->options[$option]; + $this->resetPage(); + } + + // To toggle dropdown visibility + public function toggleDropdown() + { + $this->isOpen = !$this->isOpen; + } + protected $queryString = [ 'fileSearch' => ['except' => '', 'as' => 'fS'], 'order' => ['except' => '', 'as' => 'order'], @@ -24,6 +46,29 @@ class DownloadsSearch extends Component $this->resetPage(); } + // Map the selected options to database types + private function getSelectedTypes() + { + $types = []; + + // Map the options to their corresponding database values + foreach ($this->options as $label => $selected) { + if ($selected) { + if ($label === 'FHD') { + $types[] = 'FHD'; + } elseif ($label === 'FHD 48fps') { + $types[] = 'FHDi'; + } elseif ($label === 'UHD' && auth()->user()->is_patreon) { + $types[] = 'UHD'; + } elseif ($label === 'UHD 48fps' && auth()->user()->is_patreon) { + $types[] = 'UHDi'; + } + } + } + + return $types; + } + public function clicked($downloadId) { $download = Downloads::find($downloadId); @@ -36,6 +81,17 @@ class DownloadsSearch extends Component cache()->forget("episode_{$download->episode->id}_download_{$download->type}"); } + public function mount() + { + if (!auth()->user()->is_patreon) { + return; + } + + // Add patreon options + $this->options['UHD'] = true; + $this->options['UHD 48fps'] = true; + } + public function render() { $orderby = 'created_at'; @@ -72,7 +128,7 @@ class DownloadsSearch extends Component } $downloads = Downloads::when($this->fileSearch != '', fn ($query) => $query->where('url', 'like', '%'.$this->fileSearch.'%')) - ->when(!auth()->user()->is_patreon, fn ($query) => $query->whereIn('type', ['FHD', 'FHDi'])) + ->whereIn('type', $this->getSelectedTypes()) ->whereNotNull('size') ->orderBy($orderby, $orderdirection) ->paginate(20); diff --git a/resources/views/livewire/downloads-search.blade.php b/resources/views/livewire/downloads-search.blade.php index 242b352..95654d6 100644 --- a/resources/views/livewire/downloads-search.blade.php +++ b/resources/views/livewire/downloads-search.blade.php @@ -1,8 +1,8 @@ -
-
+
+
-
-
+
+
@@ -36,6 +36,42 @@
+
+
+ +
+ + + + @if ($isOpen) +
+
+ @foreach ($options as $label => $selected) + + @endforeach +
+
+ @endif +
+ +
@@ -56,7 +92,8 @@
-
+
@@ -73,7 +110,7 @@
Download
- @php + @php $dldomains = config('hstream.download_domain'); $dlpdomains = config('hstream.download_domain_4k'); @endphp @@ -94,7 +131,7 @@
- Size: + Size: {{ $download->getFileSize() }}
@@ -102,7 +139,7 @@
- Date: + Date: {{ $download->created_at->format('Y-m-d') }}
@@ -111,15 +148,26 @@
@php if (in_array($download->type, ['FHD', 'FHDi'])) { - $downloadURL = $dldomains[array_rand($dldomains)].'/'.$download->url; + $downloadURL = + $dldomains[array_rand($dldomains)] . '/' . $download->url; } else { $now = \Illuminate\Support\Carbon::now(); - $expire = \Illuminate\Support\Facades\Crypt::encryptString($now->addHours(6)); - $file = \Illuminate\Support\Facades\Crypt::encryptString('hentai/'.$download->url); - $downloadURL = $dlpdomains[array_rand($dlpdomains)].'/download/'.$file.'/'.$expire; + $expire = \Illuminate\Support\Facades\Crypt::encryptString( + $now->addHours(6), + ); + $file = \Illuminate\Support\Facades\Crypt::encryptString( + 'hentai/' . $download->url, + ); + $downloadURL = + $dlpdomains[array_rand($dlpdomains)] . + '/download/' . + $file . + '/' . + $expire; } @endphp - +