2023-11-17 01:44:01 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\V1\User;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2023-12-10 04:53:31 -05:00
|
|
|
use App\Http\Resources\NodeResource;
|
2023-11-17 01:44:01 -05:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Services\ServerService;
|
|
|
|
use App\Services\UserService;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class ServerController extends Controller
|
|
|
|
{
|
|
|
|
public function fetch(Request $request)
|
|
|
|
{
|
|
|
|
$user = User::find($request->user['id']);
|
|
|
|
$servers = [];
|
|
|
|
$userService = new UserService();
|
|
|
|
if ($userService->isAvailable($user)) {
|
2024-04-09 12:51:03 -04:00
|
|
|
$servers = ServerService::getAvailableServers($user);
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
$eTag = sha1(json_encode(array_column($servers, 'cache_key')));
|
|
|
|
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
|
|
|
return response(null,304);
|
|
|
|
}
|
2023-12-10 04:53:31 -05:00
|
|
|
$data = NodeResource::collection($servers);
|
2023-11-17 01:44:01 -05:00
|
|
|
return response([
|
2023-12-10 04:53:31 -05:00
|
|
|
'data' => $data
|
2024-01-14 15:25:25 -05:00
|
|
|
])->header('ETag', "\"{$eTag}\"");
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
}
|