2019-12-22 23:59:27 +08:00
|
|
|
<?php
|
|
|
|
|
2023-06-12 02:32:49 +08:00
|
|
|
namespace App\Http\Controllers\V1\User;
|
2019-12-22 23:59:27 +08:00
|
|
|
|
2020-01-29 16:08:50 +08:00
|
|
|
use App\Http\Controllers\Controller;
|
2023-06-12 02:32:49 +08:00
|
|
|
use App\Models\User;
|
2020-06-12 00:18:35 +08:00
|
|
|
use App\Services\ServerService;
|
2020-02-28 01:12:55 +08:00
|
|
|
use App\Services\UserService;
|
2019-12-22 23:59:27 +08:00
|
|
|
use Illuminate\Http\Request;
|
2020-01-12 01:27:36 +08:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-01-04 13:40:35 +08:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2019-12-22 23:59:27 +08:00
|
|
|
|
2020-01-11 13:36:52 +08:00
|
|
|
class ServerController extends Controller
|
|
|
|
{
|
|
|
|
public function fetch(Request $request)
|
|
|
|
{
|
2022-07-19 03:11:36 +08:00
|
|
|
$user = User::find($request->user['id']);
|
2020-06-12 00:18:35 +08:00
|
|
|
$servers = [];
|
2020-02-28 17:16:05 +08:00
|
|
|
$userService = new UserService();
|
|
|
|
if ($userService->isAvailable($user)) {
|
2020-06-12 00:18:35 +08:00
|
|
|
$serverService = new ServerService();
|
2020-11-14 17:26:17 +08:00
|
|
|
$servers = $serverService->getAvailableServers($user);
|
2019-12-23 15:38:50 +08:00
|
|
|
}
|
2023-01-04 23:02:28 +08:00
|
|
|
$eTag = sha1(json_encode(array_column($servers, 'cache_key')));
|
2022-11-25 03:53:18 +08:00
|
|
|
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
|
|
|
abort(304);
|
|
|
|
}
|
|
|
|
|
2019-12-23 15:38:50 +08:00
|
|
|
return response([
|
2020-06-12 00:18:35 +08:00
|
|
|
'data' => $servers
|
2022-11-25 03:53:18 +08:00
|
|
|
])->header('ETag', "\"{$eTag}\"");
|
2019-12-23 15:38:50 +08:00
|
|
|
}
|
2020-01-11 13:36:52 +08:00
|
|
|
}
|