mirror of
https://github.com/cedar2025/Xboard.git
synced 2025-01-23 11:08:13 -05:00
32 lines
921 B
PHP
32 lines
921 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\V1\User;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Resources\NodeResource;
|
|
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)) {
|
|
$servers = ServerService::getAvailableServers($user);
|
|
}
|
|
$eTag = sha1(json_encode(array_column($servers, 'cache_key')));
|
|
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
|
return response(null,304);
|
|
}
|
|
$data = NodeResource::collection($servers);
|
|
return response([
|
|
'data' => $data
|
|
])->header('ETag', "\"{$eTag}\"");
|
|
}
|
|
}
|