Skip to content

Commit 93bdc86

Browse files
authored
[Bug] Return latest speedtest download and upload in mbits (alexjustesen#1201)
1 parent f33e6ed commit 93bdc86

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

app/Helpers/Number.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function bitsToMagnitude(int|float $bits, int $precision = 0, stri
2323
default => $bits,
2424
};
2525

26-
return static::format($value, $precision);
26+
return round(num: $value, precision: $precision);
2727
}
2828

2929
/**

app/Http/Controllers/API/Speedtest/GetLatestController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers\API\Speedtest;
44

55
use App\Enums\ResultStatus;
6+
use App\Helpers\Number;
67
use App\Http\Controllers\Controller;
78
use App\Models\Result;
89
use Illuminate\Http\JsonResponse;
@@ -30,8 +31,8 @@ public function __invoke(): JsonResponse
3031
'data' => [
3132
'id' => $latest->id,
3233
'ping' => $latest->ping,
33-
'download' => $latest->download_bits,
34-
'upload' => $latest->upload_bits,
34+
'download' => ! blank($latest->download) ? Number::bitsToMagnitude(bits: $latest->download_bits, precision: 2, magnitude: 'mbit') : null,
35+
'upload' => ! blank($latest->upload) ? Number::bitsToMagnitude(bits: $latest->upload_bits, precision: 2, magnitude: 'mbit') : null,
3536
'server_id' => $latest->server_id,
3637
'server_host' => $latest->server_host,
3738
'server_name' => $latest->server_name,

routes/api.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@
1919
return $request->user();
2020
});
2121

22+
/**
23+
* This route provides backwards compatibility from https://github.com/henrywhitaker3/Speedtest-Tracker
24+
* for Homepage and Organizr dashboards which expects the returned
25+
* download and upload values in mbits.
26+
*/
2227
Route::get('/speedtest/latest', GetLatestController::class)
2328
->name('speedtest.latest');

0 commit comments

Comments
 (0)