Skip to content

Commit

Permalink
Support legacy /savedata/system/verify
Browse files Browse the repository at this point in the history
  • Loading branch information
patapancakes committed Jun 10, 2024
1 parent f9cce33 commit 23c2458
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions api/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,18 @@ func handleSystem(w http.ResponseWriter, r *http.Request) {
return
}

if !r.URL.Query().Has("clientSessionId") {
httpError(w, r, fmt.Errorf("missing clientSessionId"), http.StatusBadRequest)
return
}

active, err := db.IsActiveSession(uuid, r.URL.Query().Get("clientSessionId"))
if err != nil {
httpError(w, r, fmt.Errorf("failed to check active session: %s", err), http.StatusBadRequest)
return
var active bool
if r.URL.Path != "/savedata/system/verify" {
if !r.URL.Query().Has("clientSessionId") {
httpError(w, r, fmt.Errorf("missing clientSessionId"), http.StatusBadRequest)
return
}

active, err = db.IsActiveSession(uuid, r.URL.Query().Get("clientSessionId"))
if err != nil {
httpError(w, r, fmt.Errorf("failed to check active session: %s", err), http.StatusBadRequest)
return
}
}

switch r.PathValue("action") {
Expand Down Expand Up @@ -536,12 +539,20 @@ func handleSystem(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
case "verify":
var input SystemVerifyRequest
err = json.NewDecoder(r.Body).Decode(&input)
if err != nil {
httpError(w, r, fmt.Errorf("failed to decode request body: %s", err), http.StatusBadRequest)
return
if !r.URL.Query().Has("clientSessionId") {
err = json.NewDecoder(r.Body).Decode(&input)
if err != nil {
httpError(w, r, fmt.Errorf("failed to decode request body: %s", err), http.StatusBadRequest)
return
}
} else {
active, err = db.IsActiveSession(uuid, r.URL.Query().Get("clientSessionId"))
if err != nil {
httpError(w, r, fmt.Errorf("failed to check active session: %s", err), http.StatusBadRequest)
return
}
}

response := SystemVerifyResponse{
Valid: active,
}
Expand Down

0 comments on commit 23c2458

Please sign in to comment.