mirror of
https://github.com/v2board/v2board.git
synced 2024-11-15 00:09:13 +08:00
39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\User;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\ServerService;
|
|
use App\Services\UserService;
|
|
use App\Utils\CacheKey;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use App\Models\ServerVmess;
|
|
use App\Models\ServerLog;
|
|
use App\Models\User;
|
|
|
|
use App\Utils\Helper;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ServerController extends Controller
|
|
{
|
|
public function fetch(Request $request)
|
|
{
|
|
$user = User::find($request->user['id']);
|
|
$servers = [];
|
|
$userService = new UserService();
|
|
if ($userService->isAvailable($user)) {
|
|
$serverService = new ServerService();
|
|
$servers = $serverService->getAvailableServers($user);
|
|
}
|
|
$eTag = sha1(json_encode(array_column($servers, 'cache_key')));
|
|
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
|
abort(304);
|
|
}
|
|
|
|
return response([
|
|
'data' => $servers
|
|
])->header('ETag', "\"{$eTag}\"");
|
|
}
|
|
}
|