From 2930f1957c1fe54deec2a54845b6ce0e3fa3fea6 Mon Sep 17 00:00:00 2001 From: tokumeikoi Date: Fri, 25 Nov 2022 03:53:18 +0800 Subject: [PATCH] update: server etag --- app/Http/Controllers/User/ServerController.php | 8 +++++++- app/Http/Controllers/User/UserController.php | 3 ++- app/Http/Routes/ClientRoute.php | 1 - 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/User/ServerController.php b/app/Http/Controllers/User/ServerController.php index 96f6d0cb..a681d76a 100644 --- a/app/Http/Controllers/User/ServerController.php +++ b/app/Http/Controllers/User/ServerController.php @@ -26,8 +26,14 @@ class ServerController extends Controller $serverService = new ServerService(); $servers = $serverService->getAvailableServers($user); } + + $eTag = sha1(json_encode(array_column($servers, 'updated_at'))); + if (strpos($request->header('If-None-Match'), $eTag) !== false ) { + abort(304); + } + return response([ 'data' => $servers - ]); + ])->header('ETag', "\"{$eTag}\""); } } diff --git a/app/Http/Controllers/User/UserController.php b/app/Http/Controllers/User/UserController.php index fe5f55c8..7f81ecfb 100755 --- a/app/Http/Controllers/User/UserController.php +++ b/app/Http/Controllers/User/UserController.php @@ -113,7 +113,8 @@ class UserController extends Controller 'u', 'd', 'transfer_enable', - 'email' + 'email', + 'uuid' ]) ->first(); if (!$user) { diff --git a/app/Http/Routes/ClientRoute.php b/app/Http/Routes/ClientRoute.php index b1aef4cc..ebcb3bd0 100644 --- a/app/Http/Routes/ClientRoute.php +++ b/app/Http/Routes/ClientRoute.php @@ -14,7 +14,6 @@ class ClientRoute // Client $router->get('/subscribe', 'Client\\ClientController@subscribe'); // App - $router->get('/app/config', 'Client\\AppController@config'); $router->get('/app/getConfig', 'Client\\AppController@getConfig'); $router->get('/app/getVersion', 'Client\\AppController@getVersion'); });