mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-11 08:03:09 -06:00
type safety
This commit is contained in:
parent
dbc3b47d14
commit
2fcc16fbb7
|
|
@ -227,7 +227,7 @@ func AdminUpdateRegistrationToken(req *http.Request, cfg *config.ClientAPI, user
|
||||||
return util.ErrorResponse(err)
|
return util.ErrorResponse(err)
|
||||||
}
|
}
|
||||||
tokenText := vars["token"]
|
tokenText := vars["token"]
|
||||||
request := make(map[string]interface{})
|
request := make(map[string]*int64)
|
||||||
if err = json.NewDecoder(req.Body).Decode(&request); err != nil {
|
if err = json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
|
|
@ -238,9 +238,7 @@ func AdminUpdateRegistrationToken(req *http.Request, cfg *config.ClientAPI, user
|
||||||
usesAllowed, ok := request["uses_allowed"]
|
usesAllowed, ok := request["uses_allowed"]
|
||||||
if ok {
|
if ok {
|
||||||
// Only add usesAllowed to newAtrributes if it is present and valid
|
// Only add usesAllowed to newAtrributes if it is present and valid
|
||||||
// Non numeric values in payload will cause panic during type conversion. But this is the best way to mimic
|
if !(usesAllowed == nil || *usesAllowed >= 0) {
|
||||||
// Synapse's behaviour of updating the field if and only if it is present in request body.
|
|
||||||
if !(usesAllowed == nil || int32(usesAllowed.(float64)) >= 0) {
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: spec.BadJSON("uses_allowed must be a non-negative integer or null"),
|
JSON: spec.BadJSON("uses_allowed must be a non-negative integer or null"),
|
||||||
|
|
@ -251,9 +249,7 @@ func AdminUpdateRegistrationToken(req *http.Request, cfg *config.ClientAPI, user
|
||||||
expiryTime, ok := request["expiry_time"]
|
expiryTime, ok := request["expiry_time"]
|
||||||
if ok {
|
if ok {
|
||||||
// Only add expiryTime to newAtrributes if it is present and valid
|
// Only add expiryTime to newAtrributes if it is present and valid
|
||||||
// Non numeric values in payload will cause panic during type conversion. But this is the best way to mimic
|
if !(expiryTime == nil || *expiryTime > time.Now().UnixNano()/int64(time.Millisecond)) {
|
||||||
// Synapse's behaviour of updating the field if and only if it is present in request body.
|
|
||||||
if !(expiryTime == nil || int64(expiryTime.(float64)) > time.Now().UnixNano()/int64(time.Millisecond)) {
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: spec.BadJSON("expiry_time must not be in the past"),
|
JSON: spec.BadJSON("expiry_time must not be in the past"),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue