mirror of
https://github.com/alexjustesen/speedtest-tracker.git
synced 2026-06-23 04:40:08 +00:00
[Chore] Added public dashboard middleware (#1568)
* added public dashboard middleware * fixed lint issues
This commit is contained in:
@@ -16,6 +16,5 @@ class SpeedtestCompleted
|
||||
*/
|
||||
public function __construct(
|
||||
public Result $result,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,5 @@ class SpeedtestFailed
|
||||
*/
|
||||
public function __construct(
|
||||
public Result $result,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,5 @@ class SpeedtestStarted
|
||||
*/
|
||||
public function __construct(
|
||||
public Result $result,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,6 @@ class HomeController extends Controller
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
if (! config('speedtest.public_dashboard')) {
|
||||
return redirect()->route('filament.admin.auth.login');
|
||||
}
|
||||
|
||||
$latestResult = Result::query()
|
||||
->select(['id', 'ping', 'download', 'upload', 'status', 'created_at'])
|
||||
->where('status', '=', ResultStatus::Completed)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class PublicDashboard
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (! config('speedtest.public_dashboard')) {
|
||||
return redirect()->route('filament.admin.auth.login');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,7 @@ class WriteCompletedSpeedtest implements ShouldQueue
|
||||
public function __construct(
|
||||
public Result $result,
|
||||
public InfluxDbSettings $settings,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
|
||||
@@ -34,8 +34,7 @@ class ExecuteOoklaSpeedtest implements ShouldBeUnique, ShouldQueue
|
||||
public function __construct(
|
||||
public Result $result,
|
||||
public ?int $serverId,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
|
||||
@@ -24,8 +24,7 @@ class TruncateResults implements ShouldQueue
|
||||
|
||||
public function __construct(
|
||||
public User $user,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
|
||||
@@ -23,8 +23,7 @@ class SpeedtestCompletedMail extends Mailable implements ShouldQueue
|
||||
*/
|
||||
public function __construct(
|
||||
public Result $result,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
|
||||
@@ -23,8 +23,7 @@ class SpeedtestThresholdMail extends Mailable implements ShouldQueue
|
||||
public function __construct(
|
||||
public Result $result,
|
||||
public array $metrics,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
|
||||
@@ -17,8 +17,7 @@ class SpeedtestNotification extends Notification implements ShouldQueue
|
||||
public function __construct(
|
||||
public string $content,
|
||||
public bool $disableNotification = false,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Middleware\PublicDashboard;
|
||||
use App\Providers\AppServiceProvider;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Foundation\Configuration\Exceptions;
|
||||
@@ -14,6 +15,10 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
commands: __DIR__.'/../routes/console.php',
|
||||
)
|
||||
->withMiddleware(function (Middleware $middleware) {
|
||||
$middleware->alias([
|
||||
'public-dashboard' => PublicDashboard::class,
|
||||
]);
|
||||
|
||||
$middleware->redirectGuestsTo(fn () => route('admin/login'));
|
||||
$middleware->redirectUsersTo(AppServiceProvider::HOME);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"config"
|
||||
],
|
||||
"rules": {
|
||||
"fully_qualified_strict_types": false
|
||||
"fully_qualified_strict_types": false,
|
||||
"single_line_empty_body": true
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -14,8 +14,10 @@ use Illuminate\Support\Facades\Route;
|
||||
|
|
||||
*/
|
||||
|
||||
Route::get('/', HomeController::class)
|
||||
Route::middleware('public-dashboard')->group(function () {
|
||||
Route::get('/', HomeController::class)
|
||||
->name('home');
|
||||
});
|
||||
|
||||
Route::redirect('/login', '/admin/login')
|
||||
->name('login');
|
||||
|
||||
Reference in New Issue
Block a user