[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
c8feee7354
commit
730c4f74db
@ -108,24 +108,24 @@ func Setup(
|
|||||||
},
|
},
|
||||||
)).Methods(http.MethodGet)
|
)).Methods(http.MethodGet)
|
||||||
|
|
||||||
v1fedmux.Handle("/state/{roomID}/{eventID}", common.MakeFedAPI(
|
v1fedmux.Handle("/state/{roomID}", common.MakeFedAPI(
|
||||||
"federation_get_event_auth", cfg.Matrix.ServerName, keys,
|
"federation_get_event_auth", cfg.Matrix.ServerName, keys,
|
||||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||||
vars := mux.Vars(httpReq)
|
vars := mux.Vars(httpReq)
|
||||||
return GetState(
|
return GetState(
|
||||||
httpReq.Context(), request, cfg, query, time.Now(),
|
httpReq.Context(), request, cfg, query, time.Now(),
|
||||||
keys, vars["roomID"], vars["eventID"],
|
keys, vars["roomID"],
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)).Methods(http.MethodGet)
|
)).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,
|
"federation_get_event_auth", cfg.Matrix.ServerName, keys,
|
||||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||||
vars := mux.Vars(httpReq)
|
vars := mux.Vars(httpReq)
|
||||||
return GetStateIDs(
|
return GetStateIDs(
|
||||||
httpReq.Context(), request, cfg, query, time.Now(),
|
httpReq.Context(), request, cfg, query, time.Now(),
|
||||||
keys, vars["roomID"], vars["eventID"],
|
keys, vars["roomID"],
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)).Methods(http.MethodGet)
|
)).Methods(http.MethodGet)
|
||||||
|
@ -15,8 +15,10 @@ package routing
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/common/config"
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
@ -32,8 +34,12 @@ func GetState(
|
|||||||
_ time.Time,
|
_ time.Time,
|
||||||
_ gomatrixserverlib.KeyRing,
|
_ gomatrixserverlib.KeyRing,
|
||||||
roomID string,
|
roomID string,
|
||||||
eventID string,
|
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
|
eventID, err := parseEventIDParam(request)
|
||||||
|
if err != nil {
|
||||||
|
return *err
|
||||||
|
}
|
||||||
|
|
||||||
state, err := getState(ctx, request, query, roomID, eventID)
|
state, err := getState(ctx, request, query, roomID, eventID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return *err
|
return *err
|
||||||
@ -51,8 +57,12 @@ func GetStateIDs(
|
|||||||
_ time.Time,
|
_ time.Time,
|
||||||
_ gomatrixserverlib.KeyRing,
|
_ gomatrixserverlib.KeyRing,
|
||||||
roomID string,
|
roomID string,
|
||||||
eventID string,
|
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
|
eventID, err := parseEventIDParam(request)
|
||||||
|
if err != nil {
|
||||||
|
return *err
|
||||||
|
}
|
||||||
|
|
||||||
state, err := getState(ctx, request, query, roomID, eventID)
|
state, err := getState(ctx, request, query, roomID, eventID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return *err
|
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(
|
func getState(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *gomatrixserverlib.FederationRequest,
|
request *gomatrixserverlib.FederationRequest,
|
||||||
|
Loading…
Reference in New Issue
Block a user