From e2d771852ff5f7b37d9ac889d80e02bb4da2cf1c Mon Sep 17 00:00:00 2001 From: feiniks <36756310+feiniks@users.noreply.github.com> Date: Mon, 30 Dec 2024 17:32:41 +0800 Subject: [PATCH] Fix skip cache error (#732) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix skip cache error * Delete token cache when failed to get email --------- Co-authored-by: 杨赫然 --- fileserver/sync_api.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fileserver/sync_api.go b/fileserver/sync_api.go index ee0a7a3..ea1bbc8 100644 --- a/fileserver/sync_api.go +++ b/fileserver/sync_api.go @@ -1287,13 +1287,15 @@ func validateToken(r *http.Request, repoID string, skipCache bool) (string, *app } } - if value, ok := tokenCache.Load(token); ok { - if info, ok := value.(*tokenInfo); ok { - if info.repoID != repoID { - msg := "Invalid token" - return "", &appError{nil, msg, http.StatusForbidden} + if !skipCache { + if value, ok := tokenCache.Load(token); ok { + if info, ok := value.(*tokenInfo); ok { + if info.repoID != repoID { + msg := "Invalid token" + return "", &appError{nil, msg, http.StatusForbidden} + } + return info.email, nil } - return info.email, nil } } @@ -1304,6 +1306,7 @@ func validateToken(r *http.Request, repoID string, skipCache bool) (string, *app return email, &appError{err, "", http.StatusInternalServerError} } if email == "" { + tokenCache.Delete(token) msg := fmt.Sprintf("Failed to get email by token %s", token) return email, &appError{nil, msg, http.StatusForbidden} }