2020-06-04 14:43:07 +00:00
|
|
|
package inthttp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2020-06-12 13:55:57 +00:00
|
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
2020-06-04 14:43:07 +00:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/api"
|
|
|
|
"github.com/matrix-org/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AddRoutes adds the RoomserverInternalAPI handlers to the http.ServeMux.
|
|
|
|
// nolint: gocyclo
|
|
|
|
func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|
|
|
internalAPIMux.Handle(RoomserverInputRoomEventsPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.InputRoomEventsRequest
|
|
|
|
var response api.InputRoomEventsResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
2020-09-16 12:00:52 +00:00
|
|
|
r.InputRoomEvents(req.Context(), &request, &response)
|
2020-06-04 14:43:07 +00:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-06-24 14:06:14 +00:00
|
|
|
internalAPIMux.Handle(RoomserverPerformInvitePath,
|
|
|
|
httputil.MakeInternalAPI("performInvite", func(req *http.Request) util.JSONResponse {
|
|
|
|
var request api.PerformInviteRequest
|
|
|
|
var response api.PerformInviteResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
2020-08-17 10:40:49 +00:00
|
|
|
if err := r.PerformInvite(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-24 14:06:14 +00:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-06-04 14:43:07 +00:00
|
|
|
internalAPIMux.Handle(RoomserverPerformJoinPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.PerformJoinRequest
|
|
|
|
var response api.PerformJoinResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
2020-06-24 14:06:14 +00:00
|
|
|
r.PerformJoin(req.Context(), &request, &response)
|
2020-06-04 14:43:07 +00:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(RoomserverPerformLeavePath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("performLeave", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.PerformLeaveRequest
|
|
|
|
var response api.PerformLeaveResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
if err := r.PerformLeave(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-09-10 13:39:18 +00:00
|
|
|
internalAPIMux.Handle(RoomserverPerformPeekPath,
|
|
|
|
httputil.MakeInternalAPI("performPeek", func(req *http.Request) util.JSONResponse {
|
|
|
|
var request api.PerformPeekRequest
|
|
|
|
var response api.PerformPeekResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
r.PerformPeek(req.Context(), &request, &response)
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
2020-12-03 11:11:46 +00:00
|
|
|
}),
|
|
|
|
)
|
2021-01-22 14:55:08 +00:00
|
|
|
internalAPIMux.Handle(RoomserverPerformInboundPeekPath,
|
|
|
|
httputil.MakeInternalAPI("performInboundPeek", func(req *http.Request) util.JSONResponse {
|
|
|
|
var request api.PerformInboundPeekRequest
|
|
|
|
var response api.PerformInboundPeekResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
if err := r.PerformInboundPeek(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-12-03 11:11:46 +00:00
|
|
|
internalAPIMux.Handle(RoomserverPerformPeekPath,
|
|
|
|
httputil.MakeInternalAPI("performUnpeek", func(req *http.Request) util.JSONResponse {
|
|
|
|
var request api.PerformUnpeekRequest
|
|
|
|
var response api.PerformUnpeekResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
r.PerformUnpeek(req.Context(), &request, &response)
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
2022-04-05 09:04:08 +00:00
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(RoomserverPerformRoomUpgradePath,
|
|
|
|
httputil.MakeInternalAPI("performRoomUpgrade", func(req *http.Request) util.JSONResponse {
|
|
|
|
var request api.PerformRoomUpgradeRequest
|
|
|
|
var response api.PerformRoomUpgradeResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
r.PerformRoomUpgrade(req.Context(), &request, &response)
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
2020-09-10 13:39:18 +00:00
|
|
|
}),
|
|
|
|
)
|
2020-07-02 14:41:18 +00:00
|
|
|
internalAPIMux.Handle(RoomserverPerformPublishPath,
|
|
|
|
httputil.MakeInternalAPI("performPublish", func(req *http.Request) util.JSONResponse {
|
|
|
|
var request api.PerformPublishRequest
|
|
|
|
var response api.PerformPublishResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
r.PerformPublish(req.Context(), &request, &response)
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2022-04-28 15:02:30 +00:00
|
|
|
internalAPIMux.Handle(RoomserverPerformAdminEvacuateRoomPath,
|
|
|
|
httputil.MakeInternalAPI("performAdminEvacuateRoom", func(req *http.Request) util.JSONResponse {
|
|
|
|
var request api.PerformAdminEvacuateRoomRequest
|
|
|
|
var response api.PerformAdminEvacuateRoomResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
r.PerformAdminEvacuateRoom(req.Context(), &request, &response)
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-07-02 14:41:18 +00:00
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryPublishedRoomsPath,
|
|
|
|
httputil.MakeInternalAPI("queryPublishedRooms", func(req *http.Request) util.JSONResponse {
|
|
|
|
var request api.QueryPublishedRoomsRequest
|
|
|
|
var response api.QueryPublishedRoomsResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryPublishedRooms(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-06-04 14:43:07 +00:00
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryLatestEventsAndStatePath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.QueryLatestEventsAndStateRequest
|
|
|
|
var response api.QueryLatestEventsAndStateResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryLatestEventsAndState(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryStateAfterEventsPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.QueryStateAfterEventsRequest
|
|
|
|
var response api.QueryStateAfterEventsResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryStateAfterEvents(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryEventsByIDPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.QueryEventsByIDRequest
|
|
|
|
var response api.QueryEventsByIDResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryEventsByID(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryMembershipForUserPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.QueryMembershipForUserRequest
|
|
|
|
var response api.QueryMembershipForUserResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryMembershipForUser(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryMembershipsForRoomPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.QueryMembershipsForRoomRequest
|
|
|
|
var response api.QueryMembershipsForRoomResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryMembershipsForRoom(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-09-24 15:18:13 +00:00
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryServerJoinedToRoomPath,
|
|
|
|
httputil.MakeInternalAPI("queryServerJoinedToRoom", func(req *http.Request) util.JSONResponse {
|
|
|
|
var request api.QueryServerJoinedToRoomRequest
|
|
|
|
var response api.QueryServerJoinedToRoomResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryServerJoinedToRoom(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-06-04 14:43:07 +00:00
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryServerAllowedToSeeEventPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.QueryServerAllowedToSeeEventRequest
|
|
|
|
var response api.QueryServerAllowedToSeeEventResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryServerAllowedToSeeEvent(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryMissingEventsPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.QueryMissingEventsRequest
|
|
|
|
var response api.QueryMissingEventsResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryMissingEvents(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryStateAndAuthChainPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.QueryStateAndAuthChainRequest
|
|
|
|
var response api.QueryStateAndAuthChainResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryStateAndAuthChain(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
2020-06-11 18:50:40 +00:00
|
|
|
RoomserverPerformBackfillPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("PerformBackfill", func(req *http.Request) util.JSONResponse {
|
2020-06-11 18:50:40 +00:00
|
|
|
var request api.PerformBackfillRequest
|
|
|
|
var response api.PerformBackfillResponse
|
2020-06-04 14:43:07 +00:00
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-11 18:50:40 +00:00
|
|
|
if err := r.PerformBackfill(req.Context(), &request, &response); err != nil {
|
2020-06-04 14:43:07 +00:00
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-11-05 10:19:23 +00:00
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverPerformForgetPath,
|
|
|
|
httputil.MakeInternalAPI("PerformForget", func(req *http.Request) util.JSONResponse {
|
|
|
|
var request api.PerformForgetRequest
|
|
|
|
var response api.PerformForgetResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.PerformForget(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-06-04 14:43:07 +00:00
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryRoomVersionCapabilitiesPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.QueryRoomVersionCapabilitiesRequest
|
|
|
|
var response api.QueryRoomVersionCapabilitiesResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryRoomVersionCapabilities(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverQueryRoomVersionForRoomPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.QueryRoomVersionForRoomRequest
|
|
|
|
var response api.QueryRoomVersionForRoomResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.QueryRoomVersionForRoom(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverSetRoomAliasPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.SetRoomAliasRequest
|
|
|
|
var response api.SetRoomAliasResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.SetRoomAlias(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverGetRoomIDForAliasPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.GetRoomIDForAliasRequest
|
|
|
|
var response api.GetRoomIDForAliasResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.GetRoomIDForAlias(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverGetAliasesForRoomIDPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.GetAliasesForRoomIDRequest
|
|
|
|
var response api.GetAliasesForRoomIDResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.GetAliasesForRoomID(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(
|
|
|
|
RoomserverRemoveRoomAliasPath,
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse {
|
2020-06-04 14:43:07 +00:00
|
|
|
var request api.RemoveRoomAliasRequest
|
|
|
|
var response api.RemoveRoomAliasResponse
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
if err := r.RemoveRoomAlias(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-09-03 16:20:54 +00:00
|
|
|
internalAPIMux.Handle(RoomserverQueryCurrentStatePath,
|
|
|
|
httputil.MakeInternalAPI("queryCurrentState", func(req *http.Request) util.JSONResponse {
|
|
|
|
request := api.QueryCurrentStateRequest{}
|
|
|
|
response := api.QueryCurrentStateResponse{}
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
if err := r.QueryCurrentState(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(RoomserverQueryRoomsForUserPath,
|
|
|
|
httputil.MakeInternalAPI("queryRoomsForUser", func(req *http.Request) util.JSONResponse {
|
|
|
|
request := api.QueryRoomsForUserRequest{}
|
|
|
|
response := api.QueryRoomsForUserResponse{}
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
if err := r.QueryRoomsForUser(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(RoomserverQueryBulkStateContentPath,
|
|
|
|
httputil.MakeInternalAPI("queryBulkStateContent", func(req *http.Request) util.JSONResponse {
|
|
|
|
request := api.QueryBulkStateContentRequest{}
|
|
|
|
response := api.QueryBulkStateContentResponse{}
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
if err := r.QueryBulkStateContent(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(RoomserverQuerySharedUsersPath,
|
|
|
|
httputil.MakeInternalAPI("querySharedUsers", func(req *http.Request) util.JSONResponse {
|
|
|
|
request := api.QuerySharedUsersRequest{}
|
|
|
|
response := api.QuerySharedUsersResponse{}
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
if err := r.QuerySharedUsers(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-09-04 10:46:01 +00:00
|
|
|
internalAPIMux.Handle(RoomserverQueryKnownUsersPath,
|
2020-09-03 16:20:54 +00:00
|
|
|
httputil.MakeInternalAPI("queryKnownUsers", func(req *http.Request) util.JSONResponse {
|
|
|
|
request := api.QueryKnownUsersRequest{}
|
|
|
|
response := api.QueryKnownUsersResponse{}
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
if err := r.QueryKnownUsers(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
internalAPIMux.Handle(RoomserverQueryServerBannedFromRoomPath,
|
|
|
|
httputil.MakeInternalAPI("queryServerBannedFromRoom", func(req *http.Request) util.JSONResponse {
|
|
|
|
request := api.QueryServerBannedFromRoomRequest{}
|
|
|
|
response := api.QueryServerBannedFromRoomResponse{}
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
if err := r.QueryServerBannedFromRoom(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-12-04 14:11:01 +00:00
|
|
|
internalAPIMux.Handle(RoomserverQueryAuthChainPath,
|
|
|
|
httputil.MakeInternalAPI("queryAuthChain", func(req *http.Request) util.JSONResponse {
|
|
|
|
request := api.QueryAuthChainRequest{}
|
|
|
|
response := api.QueryAuthChainResponse{}
|
|
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
if err := r.QueryAuthChain(req.Context(), &request, &response); err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|