mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
[federation] Fix state API endpoints (#518)
* [federation] Fix state API endpoints Signed-off-by: Anant Prakash <anantprakashjsr@gmail.com> * Use parseEventIDParam instead
This commit is contained in:
parent
bcc6ae42c9
commit
a2a492fdb5
2 changed files with 36 additions and 6 deletions
|
@ -108,24 +108,24 @@ func Setup(
|
|||
},
|
||||
)).Methods(http.MethodGet)
|
||||
|
||||
v1fedmux.Handle("/state/{roomID}/{eventID}", common.MakeFedAPI(
|
||||
v1fedmux.Handle("/state/{roomID}", common.MakeFedAPI(
|
||||
"federation_get_event_auth", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
return GetState(
|
||||
httpReq.Context(), request, cfg, query, time.Now(),
|
||||
keys, vars["roomID"], vars["eventID"],
|
||||
keys, vars["roomID"],
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodGet)
|
||||
|
||||
v1fedmux.Handle("/state_ids/{roomID}/{eventID}", common.MakeFedAPI(
|
||||
v1fedmux.Handle("/state_ids/{roomID}", common.MakeFedAPI(
|
||||
"federation_get_event_auth", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
return GetStateIDs(
|
||||
httpReq.Context(), request, cfg, query, time.Now(),
|
||||
keys, vars["roomID"], vars["eventID"],
|
||||
keys, vars["roomID"],
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodGet)
|
||||
|
|
|
@ -15,8 +15,10 @@ package routing
|
|||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/common/config"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
@ -32,8 +34,12 @@ func GetState(
|
|||
_ time.Time,
|
||||
_ gomatrixserverlib.KeyRing,
|
||||
roomID string,
|
||||
eventID string,
|
||||
) util.JSONResponse {
|
||||
eventID, err := parseEventIDParam(request)
|
||||
if err != nil {
|
||||
return *err
|
||||
}
|
||||
|
||||
state, err := getState(ctx, request, query, roomID, eventID)
|
||||
if err != nil {
|
||||
return *err
|
||||
|
@ -51,8 +57,12 @@ func GetStateIDs(
|
|||
_ time.Time,
|
||||
_ gomatrixserverlib.KeyRing,
|
||||
roomID string,
|
||||
eventID string,
|
||||
) util.JSONResponse {
|
||||
eventID, err := parseEventIDParam(request)
|
||||
if err != nil {
|
||||
return *err
|
||||
}
|
||||
|
||||
state, err := getState(ctx, request, query, roomID, eventID)
|
||||
if err != nil {
|
||||
return *err
|
||||
|
@ -68,6 +78,26 @@ func GetStateIDs(
|
|||
}
|
||||
}
|
||||
|
||||
func parseEventIDParam(
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
) (eventID string, resErr *util.JSONResponse) {
|
||||
URL, err := url.Parse(request.RequestURI())
|
||||
if err != nil {
|
||||
*resErr = util.ErrorResponse(err)
|
||||
return
|
||||
}
|
||||
|
||||
eventID = URL.Query().Get("event_id")
|
||||
if eventID == "" {
|
||||
resErr = &util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: jsonerror.MissingArgument("event_id missing"),
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func getState(
|
||||
ctx context.Context,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
|
|
Loading…
Reference in a new issue