File tree Expand file tree Collapse file tree 2 files changed +43
-21
lines changed
Expand file tree Collapse file tree 2 files changed +43
-21
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Actions ;
4+
5+ use Illuminate \Http \Client \RequestException ;
6+ use Illuminate \Http \Client \Response ;
7+ use Illuminate \Support \Facades \Http ;
8+ use Illuminate \Support \Facades \Log ;
9+ use Lorisleiva \Actions \Concerns \AsAction ;
10+
11+ class GetOoklaSpeedtestServers
12+ {
13+ use AsAction;
14+
15+ public function handle (): array
16+ {
17+ $ query = [
18+ 'engine ' => 'js ' ,
19+ 'https_functional ' => true ,
20+ 'limit ' => 20 ,
21+ ];
22+
23+ $ response = Http::retry (3 , 250 )
24+ ->timeout (5 )
25+ ->get (url: 'https://www.speedtest.net/api/js/servers ' , query: $ query )
26+ ->throw (function (Response $ response , RequestException $ e ) {
27+ Log::error ($ e );
28+
29+ return [
30+ '0 ' => 'There was an issue retrieving Ookla speedtest servers, check the logs for more info. ' ,
31+ ];
32+ })
33+ ->collect ();
34+
35+ return $ response ->mapWithKeys (function (array $ item , int $ key ) {
36+ return [
37+ $ item ['id ' ] => $ item ['id ' ].': ' .$ item ['name ' ].' ( ' .$ item ['sponsor ' ].') ' ,
38+ ];
39+ })->toArray ();
40+ }
41+ }
Original file line number Diff line number Diff line change 22
33namespace App \Filament \Pages \Settings ;
44
5+ use App \Actions \GetOoklaSpeedtestServers ;
56use App \Helpers \TimeZoneHelper ;
67use App \Rules \Cron ;
78use App \Settings \GeneralSettings ;
@@ -97,28 +98,8 @@ public function form(Form $form): Form
9798 ->maxItems (10 )
9899 ->multiple ()
99100 ->nullable ()
100- ->preload (false )
101101 ->searchable ()
102- ->options (function (): array {
103- $ response = Http::get (
104- url: 'https://www.speedtest.net/api/js/servers ' ,
105- query: [
106- 'engine ' => 'js ' ,
107- 'https_functional ' => true ,
108- 'limit ' => 20 ,
109- ]
110- );
111-
112- if ($ response ->failed ()) {
113- return [
114- '' => 'There was an error retrieving Speedtest servers ' ,
115- ];
116- }
117-
118- return $ response ->collect ()->mapWithKeys (function (array $ item , int $ key ) {
119- return [$ item ['id ' ] => $ item ['id ' ].': ' .$ item ['name ' ].' ( ' .$ item ['sponsor ' ].') ' ];
120- })->toArray ();
121- })
102+ ->options (GetOoklaSpeedtestServers::run ())
122103 ->getSearchResultsUsing (fn (string $ search ): array => $ this ->getServerSearchOptions ($ search ))
123104 ->getOptionLabelsUsing (fn (array $ values ): array => $ this ->getServerLabels ($ values ))
124105 ->columnSpan ('full ' ),
You can’t perform that action at this time.
0 commit comments