Xboard/app/Http/Controllers/V1/User/ServerController.php

32 lines
921 B
PHP
Raw Normal View History

2023-11-17 01:44:01 -05:00
<?php
namespace App\Http\Controllers\V1\User;
use App\Http\Controllers\Controller;
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)) {
$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);
}
$data = NodeResource::collection($servers);
2023-11-17 01:44:01 -05:00
return response([
'data' => $data
])->header('ETag', "\"{$eTag}\"");
2023-11-17 01:44:01 -05:00
}
}