From 68caa148f6a965f01ea503d42f56daad6799e5f7 Mon Sep 17 00:00:00 2001 From: maru Date: Sun, 2 Jun 2024 18:23:51 -0400 Subject: [PATCH] Clean up clientSessionId checks --- api/endpoints.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/api/endpoints.go b/api/endpoints.go index cd25fb9..92d4570 100644 --- a/api/endpoints.go +++ b/api/endpoints.go @@ -162,14 +162,12 @@ func handleGetSessionData(w http.ResponseWriter, r *http.Request) { } } - var clientSessionId string - if r.URL.Query().Has("clientSessionId") { - clientSessionId = r.URL.Query().Get("clientSessionId") - } else { + if !r.URL.Query().Has("clientSessionId") { httpError(w, r, fmt.Errorf("missing clientSessionId"), http.StatusBadRequest) + return } - err = db.UpdateActiveSession(uuid, clientSessionId) + err = db.UpdateActiveSession(uuid, r.URL.Query().Get("clientSessionId")) if err != nil { httpError(w, r, fmt.Errorf("failed to update active session: %s", err), http.StatusBadRequest) return @@ -434,10 +432,7 @@ func legacyHandleSaveData(w http.ResponseWriter, r *http.Request) { } } - var clientSessionId string - if r.URL.Query().Has("clientSessionId") { - clientSessionId = r.URL.Query().Get("clientSessionId") - } + clientSessionId := r.URL.Query().Get("clientSessionId") if clientSessionId == "" { clientSessionId = legacyClientSessionId } @@ -709,14 +704,12 @@ func handleGetSystemData(w http.ResponseWriter, r *http.Request) { return } - var clientSessionId string - if r.URL.Query().Has("clientSessionId") { - clientSessionId = r.URL.Query().Get("clientSessionId") - } else { + if !r.URL.Query().Has("clientSessionId") { httpError(w, r, fmt.Errorf("missing clientSessionId"), http.StatusBadRequest) + return } - err = db.UpdateActiveSession(uuid, clientSessionId) + err = db.UpdateActiveSession(uuid, r.URL.Query().Get("clientSessionId")) if err != nil { httpError(w, r, fmt.Errorf("failed to update active session: %s", err), http.StatusBadRequest) return