Clean up handleUpdateAll

pull/34/head
Pancakes 5 months ago
parent 048db67609
commit ddf1e8d9e5
No known key found for this signature in database
GPG Key ID: 5792877BFA27DC8F

@ -586,6 +586,7 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) {
httpError(w, r, fmt.Errorf("failed to decode request body: %s", err), http.StatusBadRequest) httpError(w, r, fmt.Errorf("failed to decode request body: %s", err), http.StatusBadRequest)
return return
} }
if data.ClientSessionId == "" { if data.ClientSessionId == "" {
data.ClientSessionId = legacyClientSessionId data.ClientSessionId = legacyClientSessionId
} }
@ -602,9 +603,6 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) {
return return
} }
trainerId := data.System.TrainerId
secretId := data.System.SecretId
storedTrainerId, storedSecretId, err := db.FetchTrainerIds(uuid) storedTrainerId, storedSecretId, err := db.FetchTrainerIds(uuid)
if err != nil { if err != nil {
httpError(w, r, err, http.StatusInternalServerError) httpError(w, r, err, http.StatusInternalServerError)
@ -612,12 +610,13 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) {
} }
if storedTrainerId > 0 || storedSecretId > 0 { if storedTrainerId > 0 || storedSecretId > 0 {
if trainerId != storedTrainerId || secretId != storedSecretId { if data.System.TrainerId != storedTrainerId || data.System.SecretId != storedSecretId {
httpError(w, r, fmt.Errorf("session out of date: stored trainer or secret ID does not match"), http.StatusBadRequest) httpError(w, r, fmt.Errorf("session out of date: stored trainer or secret ID does not match"), http.StatusBadRequest)
return return
} }
} else { } else {
if err = db.UpdateTrainerIds(trainerId, secretId, uuid); err != nil { err = db.UpdateTrainerIds(data.System.TrainerId, data.System.SecretId, uuid)
if err != nil {
httpError(w, r, err, http.StatusInternalServerError) httpError(w, r, err, http.StatusInternalServerError)
return return
} }
@ -628,11 +627,13 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) {
httpError(w, r, err, http.StatusInternalServerError) httpError(w, r, err, http.StatusInternalServerError)
return return
} }
err = savedata.Update(uuid, 0, data.System) err = savedata.Update(uuid, 0, data.System)
if err != nil { if err != nil {
httpError(w, r, err, http.StatusInternalServerError) httpError(w, r, err, http.StatusInternalServerError)
return return
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} }

Loading…
Cancel
Save