Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3e917d1
Initial commit
svenvg93 May 14, 2025
d0db93f
main
svenvg93 May 14, 2025
3189f10
Merge branch 'alexjustesen:main' into main
svenvg93 May 19, 2025
7becd71
Merge branch 'alexjustesen:main' into main
svenvg93 May 19, 2025
440c38f
Merge branch 'alexjustesen:main' into main
svenvg93 May 19, 2025
957f5cc
Merge branch 'alexjustesen:main' into main
svenvg93 May 19, 2025
acfea02
Merge branch 'alexjustesen:main' into main
svenvg93 May 20, 2025
e2cf081
Merge branch 'alexjustesen:main' into main
svenvg93 May 20, 2025
b7ae31e
Merge branch 'main' of https://github.com/svenvg93/speedtest-tracker
svenvg93 May 22, 2025
1fe60f1
Merge branch 'main' of https://github.com/svenvg93/speedtest-tracker
svenvg93 May 27, 2025
ec5d0c0
Merge branch 'main' of https://github.com/svenvg93/speedtest-tracker
svenvg93 May 28, 2025
05e7d0e
add controllers
svenvg93 May 28, 2025
4789718
split GetOoklaServers response
svenvg93 May 28, 2025
fdca730
removed to much
svenvg93 May 28, 2025
c51b2c1
lint
svenvg93 May 28, 2025
32f45a6
.
svenvg93 May 28, 2025
75097af
lint
svenvg93 May 28, 2025
9ef456b
update route
svenvg93 Jun 2, 2025
9c93a99
Merge branch 'main' into refactor-api
alexjustesen Jun 2, 2025
ada3cc4
move /healthcheck
svenvg93 Jun 2, 2025
91adde0
Merge branch 'main' into refactor-api
svenvg93 Jun 12, 2025
627cc9d
Merge branch 'alexjustesen:main' into refactor-api
svenvg93 Jun 14, 2025
5fd39c1
Merge branch 'alexjustesen:main' into refactor-api
svenvg93 Jun 17, 2025
e32219a
Change ookla/list-server
svenvg93 Jun 23, 2025
a8ea4f5
add test
svenvg93 Jun 25, 2025
39d239e
update the ci
svenvg93 Jun 25, 2025
1823e25
seperate test
svenvg93 Jun 25, 2025
64a1eb1
Remove tests
svenvg93 Jun 26, 2025
34d2c63
requested changes
svenvg93 Jun 26, 2025
ca0b1b9
Merge branch 'main' into refactor-api
svenvg93 Jun 26, 2025
8665a5c
Merge branch 'main' into refactor-api
alexjustesen Jun 26, 2025
bbcddb2
Merge branch 'main' into refactor-api
svenvg93 Jul 11, 2025
33234f0
Merge branch 'main' into refactor-api
svenvg93 Jul 23, 2025
423c65b
Merge branch 'main' into refactor-api
svenvg93 Jul 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions app/Actions/GetOoklaSpeedtestServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Actions;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Lorisleiva\Actions\Concerns\AsAction;
Expand All @@ -11,7 +12,22 @@ class GetOoklaSpeedtestServers
{
use AsAction;

/**
* For UI: return the ID, Sponsor, and Name to start a manual test
*/
public function handle(): array
{
return collect(self::fetch())->mapWithKeys(function (array $item) {
return [
$item['id'] => ($item['sponsor'] ?? 'Unknown').' ('.($item['name'] ?? 'Unknown').', '.$item['id'].')',
];
})->toArray();
}

/**
* Fetch the raw Ookla server array from the Ookla API.
*/
public static function fetch(): array
{
$query = [
'engine' => 'js',
Expand All @@ -23,17 +39,37 @@ public function handle(): array
$response = Http::retry(3, 250)
->timeout(5)
->get(url: 'https://www.speedtest.net/api/js/servers', query: $query);

return $response->json();
} catch (Throwable $e) {
Log::error('Unable to retrieve Ookla servers.', [$e->getMessage()]);

return [
'⚠️ Unable to retrieve Ookla servers, check internet connection and see logs.',
];
}
}

/**
* For API: return array of structured server objects
*/
public static function forApi(): array
{
$servers = self::fetch();

// If the first item is not an array, treat as error or empty
if (empty($servers) || ! is_array($servers) || (isset($servers[0]) && ! is_array($servers[0]))) {
// Optionally, you could return an error message here, but to match the controller's behavior, return an empty array
return [];
}

return $response->collect()->mapWithKeys(function (array $item, int $key) {
return collect($servers)->map(function (array $item) {
return [
$item['id'] => $item['sponsor'].' ('.$item['name'].', '.$item['id'].')',
'id' => $item['id'],
'host' => Arr::get($item, 'host', 'Unknown'),
'name' => Arr::get($item, 'sponsor', 'Unknown'),
'location' => Arr::get($item, 'name', 'Unknown'),
'country' => Arr::get($item, 'country', 'Unknown'),
];
})->toArray();
}
Expand Down
6 changes: 3 additions & 3 deletions app/Filament/Resources/ApiTokenResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public static function getTokenFormSchema(): array
->required()
->bulkToggleable()
->descriptions([
'results:read' => 'Allow this token to read results.',
'speedtests:run' => 'Allow this token to run speedtests.',
'ookla:list-servers' => 'Allow this token to list servers.',
'results:read' => 'Grant this token permission to read results and statistics.',
'speedtests:run' => 'Grant this token permission to run speedtests.',
'ookla:list-servers' => 'Grant this token permission to list available servers.',
]),
DateTimePicker::make('expires_at')
->label('Expires at')
Expand Down
52 changes: 0 additions & 52 deletions app/Http/Controllers/Api/V1/LatestResult.php

This file was deleted.

86 changes: 0 additions & 86 deletions app/Http/Controllers/Api/V1/ListResults.php

This file was deleted.

57 changes: 0 additions & 57 deletions app/Http/Controllers/Api/V1/ListSpeedtestServers.php

This file was deleted.

32 changes: 32 additions & 0 deletions app/Http/Controllers/Api/V1/OoklaController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Http\Controllers\Api\V1;

use App\Actions\GetOoklaSpeedtestServers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class OoklaController extends ApiController
{
/**
* GET /api/v1/ookla/list-servers
* List available Ookla speedtest servers.
*/
public function __invoke(Request $request)
{
if ($request->user()->tokenCant('ookla:list-servers')) {
return $this->sendResponse(
data: null,
message: 'You do not have permission to view speedtest servers.',
code: Response::HTTP_FORBIDDEN,
);
}

$servers = GetOoklaSpeedtestServers::forApi();

return $this->sendResponse(
data: $servers,
message: 'Speedtest servers fetched successfully.'
);
}
}
Loading