2017-04-21 00:40:52 +02:00
|
|
|
// Copyright 2017 Vector Creations Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-02-20 16:41:29 +01:00
|
|
|
package routing
|
|
|
|
|
|
|
|
import (
|
2017-04-20 18:11:53 +02:00
|
|
|
"encoding/json"
|
2017-02-20 16:41:29 +01:00
|
|
|
"net/http"
|
2017-08-18 16:33:40 +02:00
|
|
|
"strings"
|
2017-02-20 16:41:29 +01:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2018-08-20 11:45:17 +02:00
|
|
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
2017-05-22 20:28:26 +02:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
2017-05-23 18:43:05 +02:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
2017-06-27 13:37:25 +02:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
2017-03-15 14:36:26 +01:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
2020-06-10 13:17:54 +02:00
|
|
|
eduServerAPI "github.com/matrix-org/dendrite/eduserver/api"
|
2019-10-01 18:09:47 +02:00
|
|
|
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
|
2020-05-21 15:40:13 +02:00
|
|
|
"github.com/matrix-org/dendrite/internal/config"
|
2020-06-12 15:55:57 +02:00
|
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
2020-05-21 15:40:13 +02:00
|
|
|
"github.com/matrix-org/dendrite/internal/transactions"
|
2018-08-08 17:17:09 +02:00
|
|
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
2020-06-16 15:10:55 +02:00
|
|
|
"github.com/matrix-org/dendrite/userapi/api"
|
2017-05-25 17:08:28 +02:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2017-02-20 16:41:29 +01:00
|
|
|
"github.com/matrix-org/util"
|
|
|
|
)
|
|
|
|
|
2020-05-22 12:43:17 +02:00
|
|
|
const pathPrefixV1 = "/client/api/v1"
|
|
|
|
const pathPrefixR0 = "/client/r0"
|
|
|
|
const pathPrefixUnstable = "/client/unstable"
|
2017-02-20 16:41:29 +01:00
|
|
|
|
|
|
|
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
|
|
|
|
// to clients which need to make outbound HTTP requests.
|
2019-07-03 17:38:50 +02:00
|
|
|
//
|
|
|
|
// Due to Setup being used to call many other functions, a gocyclo nolint is
|
|
|
|
// applied:
|
|
|
|
// nolint: gocyclo
|
2017-05-25 17:08:28 +02:00
|
|
|
func Setup(
|
2020-05-22 12:43:17 +02:00
|
|
|
publicAPIMux *mux.Router, cfg *config.Dendrite,
|
2020-06-10 13:17:54 +02:00
|
|
|
eduAPI eduServerAPI.EDUServerInputAPI,
|
2020-05-01 11:48:17 +02:00
|
|
|
rsAPI roomserverAPI.RoomserverInternalAPI,
|
2018-08-20 11:45:17 +02:00
|
|
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
2020-02-13 18:27:33 +01:00
|
|
|
accountDB accounts.Database,
|
|
|
|
deviceDB devices.Database,
|
2020-06-16 15:10:55 +02:00
|
|
|
userAPI api.UserInternalAPI,
|
2017-05-25 17:08:28 +02:00
|
|
|
federation *gomatrixserverlib.FederationClient,
|
2017-08-02 17:21:35 +02:00
|
|
|
syncProducer *producers.SyncAPIProducer,
|
2018-05-18 11:49:40 +02:00
|
|
|
transactionsCache *transactions.Cache,
|
2020-04-29 12:34:31 +02:00
|
|
|
federationSender federationSenderAPI.FederationSenderInternalAPI,
|
2017-05-25 17:08:28 +02:00
|
|
|
) {
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2020-05-22 12:43:17 +02:00
|
|
|
publicAPIMux.Handle("/client/versions",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse {
|
2017-06-27 13:37:25 +02:00
|
|
|
return util.JSONResponse{
|
2018-03-13 16:55:45 +01:00
|
|
|
Code: http.StatusOK,
|
2017-06-27 13:37:25 +02:00
|
|
|
JSON: struct {
|
|
|
|
Versions []string `json:"versions"`
|
|
|
|
}{[]string{
|
|
|
|
"r0.0.1",
|
|
|
|
"r0.1.0",
|
|
|
|
"r0.2.0",
|
2018-03-14 18:36:02 +01:00
|
|
|
"r0.3.0",
|
2017-06-27 13:37:25 +02:00
|
|
|
}},
|
|
|
|
}
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2020-05-22 12:43:17 +02:00
|
|
|
r0mux := publicAPIMux.PathPrefix(pathPrefixR0).Subrouter()
|
|
|
|
v1mux := publicAPIMux.PathPrefix(pathPrefixV1).Subrouter()
|
|
|
|
unstableMux := publicAPIMux.PathPrefix(pathPrefixUnstable).Subrouter()
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2017-05-18 14:47:23 +02:00
|
|
|
r0mux.Handle("/createRoom",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("createRoom", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-10 13:17:54 +02:00
|
|
|
return CreateRoom(req, device, cfg, accountDB, rsAPI, asAPI)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-05-25 17:08:28 +02:00
|
|
|
r0mux.Handle("/join/{roomIDOrAlias}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 19:16:53 +02:00
|
|
|
return JoinRoomByIDOrAlias(
|
2020-05-13 15:53:25 +02:00
|
|
|
req, device, rsAPI, accountDB, vars["roomIDOrAlias"],
|
2017-05-25 17:08:28 +02:00
|
|
|
)
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2020-03-19 11:25:36 +01:00
|
|
|
r0mux.Handle("/joined_rooms",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("joined_rooms", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-03-19 11:25:36 +01:00
|
|
|
return GetJoinedRooms(req, device, accountDB)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2020-05-04 19:34:09 +02:00
|
|
|
r0mux.Handle("/rooms/{roomID}/leave",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-05-04 19:34:09 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return LeaveRoomByID(
|
|
|
|
req, device, rsAPI, vars["roomID"],
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
r0mux.Handle("/rooms/{roomID}/{membership:(?:join|kick|ban|unban|invite)}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-10 13:17:54 +02:00
|
|
|
return SendMembership(req, accountDB, device, vars["roomID"], vars["membership"], cfg, rsAPI, asAPI)
|
2017-08-04 17:32:10 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-26 13:55:48 +02:00
|
|
|
r0mux.Handle("/rooms/{roomID}/send/{eventType}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-10 13:17:54 +02:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, nil, cfg, rsAPI, nil)
|
2017-09-26 13:55:48 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-03-15 12:22:40 +01:00
|
|
|
r0mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-09-26 13:55:48 +02:00
|
|
|
txnID := vars["txnID"]
|
2018-05-18 11:49:40 +02:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], &txnID,
|
2020-06-10 13:17:54 +02:00
|
|
|
nil, cfg, rsAPI, transactionsCache)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2019-08-09 11:45:54 +02:00
|
|
|
r0mux.Handle("/rooms/{roomID}/event/{eventID}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("rooms_get_event", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-09 11:45:54 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-15 11:13:57 +02:00
|
|
|
return GetEvent(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, federation)
|
2019-08-09 11:45:54 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 19:36:08 +02:00
|
|
|
|
2020-06-16 15:10:55 +02:00
|
|
|
r0mux.Handle("/rooms/{roomID}/state", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 19:36:08 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return OnIncomingStateRequest(req.Context(), rsAPI, vars["roomID"])
|
2020-04-14 19:36:08 +02:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2020-06-16 15:10:55 +02:00
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{type}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 19:36:08 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], "")
|
2020-04-14 19:36:08 +02:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2020-06-16 15:10:55 +02:00
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 19:36:08 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], vars["stateKey"])
|
2020-04-14 19:36:08 +02:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2017-08-18 16:33:40 +02:00
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 12:21:52 +01:00
|
|
|
emptyString := ""
|
2017-08-18 16:33:40 +02:00
|
|
|
eventType := vars["eventType"]
|
|
|
|
// If there's a trailing slash, remove it
|
|
|
|
if strings.HasSuffix(eventType, "/") {
|
|
|
|
eventType = eventType[:len(eventType)-1]
|
|
|
|
}
|
2020-06-10 13:17:54 +02:00
|
|
|
return SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, rsAPI, nil)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2020-04-14 19:36:08 +02:00
|
|
|
|
2017-03-17 12:21:52 +01:00
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 12:21:52 +01:00
|
|
|
stateKey := vars["stateKey"]
|
2020-06-10 13:17:54 +02:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, &stateKey, cfg, rsAPI, nil)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-02-20 16:41:29 +01:00
|
|
|
|
2020-06-12 15:55:57 +02:00
|
|
|
r0mux.Handle("/register", httputil.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse {
|
2020-06-17 12:22:26 +02:00
|
|
|
return Register(req, userAPI, accountDB, cfg)
|
2018-03-13 16:55:45 +01:00
|
|
|
})).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-22 17:13:19 +02:00
|
|
|
|
2020-06-12 15:55:57 +02:00
|
|
|
v1mux.Handle("/register", httputil.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse {
|
2020-06-17 12:22:26 +02:00
|
|
|
return LegacyRegister(req, userAPI, cfg)
|
2018-03-13 16:55:45 +01:00
|
|
|
})).Methods(http.MethodPost, http.MethodOptions)
|
2017-05-22 16:55:39 +02:00
|
|
|
|
2020-06-12 15:55:57 +02:00
|
|
|
r0mux.Handle("/register/available", httputil.MakeExternalAPI("registerAvailable", func(req *http.Request) util.JSONResponse {
|
2018-08-20 11:23:01 +02:00
|
|
|
return RegisterAvailable(req, cfg, accountDB)
|
2018-03-13 16:55:45 +01:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-09 16:24:38 +02:00
|
|
|
|
2017-06-27 13:37:25 +02:00
|
|
|
r0mux.Handle("/directory/room/{roomAlias}",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("directory_room", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return DirectoryRoom(req, vars["roomAlias"], federation, cfg, rsAPI, federationSender)
|
2017-06-27 13:37:25 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-28 12:31:43 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/directory/room/{roomAlias}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return SetLocalAlias(req, device, vars["roomAlias"], cfg, rsAPI)
|
2017-07-28 12:31:43 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-28 12:31:43 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/directory/room/{roomAlias}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return RemoveLocalAlias(req, device, vars["roomAlias"], rsAPI)
|
2017-07-28 12:31:43 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2017-07-11 17:04:34 +02:00
|
|
|
r0mux.Handle("/logout",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("logout", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2017-10-11 19:16:53 +02:00
|
|
|
return Logout(req, deviceDB, device)
|
2017-07-11 17:04:34 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-07-11 17:04:34 +02:00
|
|
|
|
2017-10-15 12:29:47 +02:00
|
|
|
r0mux.Handle("/logout/all",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("logout", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2017-10-15 12:29:47 +02:00
|
|
|
return LogoutAll(req, deviceDB, device)
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-10-15 12:29:47 +02:00
|
|
|
|
2018-07-24 16:49:49 +02:00
|
|
|
r0mux.Handle("/rooms/{roomID}/typing/{userID}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("rooms_typing", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-10 13:17:54 +02:00
|
|
|
return SendTyping(req, device, vars["roomID"], vars["userID"], accountDB, eduAPI)
|
2018-07-24 16:49:49 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
|
|
|
r0mux.Handle("/sendToDevice/{eventType}/{txnID}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
2020-06-10 13:17:54 +02:00
|
|
|
return SendToDevice(req, device, eduAPI, transactionsCache, vars["eventType"], &txnID)
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
// This is only here because sytest refers to /unstable for this endpoint
|
|
|
|
// rather than r0. It's an exact duplicate of the above handler.
|
|
|
|
// TODO: Remove this if/when sytest is fixed!
|
|
|
|
unstableMux.Handle("/sendToDevice/{eventType}/{txnID}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
2020-06-10 13:17:54 +02:00
|
|
|
return SendToDevice(req, device, eduAPI, transactionsCache, vars["eventType"], &txnID)
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
2018-08-04 11:32:02 +02:00
|
|
|
r0mux.Handle("/account/whoami",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("whoami", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2018-08-04 11:32:02 +02:00
|
|
|
return Whoami(req, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2017-04-20 18:11:53 +02:00
|
|
|
// Stub endpoints required by Riot
|
|
|
|
|
|
|
|
r0mux.Handle("/login",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("login", func(req *http.Request) util.JSONResponse {
|
2017-10-11 19:16:53 +02:00
|
|
|
return Login(req, accountDB, deviceDB, cfg)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
2017-04-20 18:11:53 +02:00
|
|
|
|
2019-08-14 19:34:49 +02:00
|
|
|
r0mux.Handle("/auth/{authType}/fallback/web",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeHTMLAPI("auth_fallback", func(w http.ResponseWriter, req *http.Request) *util.JSONResponse {
|
2019-08-14 19:34:49 +02:00
|
|
|
vars := mux.Vars(req)
|
|
|
|
return AuthFallback(w, req, vars["authType"], cfg)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
|
2017-04-20 18:11:53 +02:00
|
|
|
r0mux.Handle("/pushrules/",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("push_rules", func(req *http.Request) util.JSONResponse {
|
2017-04-20 18:11:53 +02:00
|
|
|
// TODO: Implement push rules API
|
|
|
|
res := json.RawMessage(`{
|
|
|
|
"global": {
|
|
|
|
"content": [],
|
|
|
|
"override": [],
|
|
|
|
"room": [],
|
|
|
|
"sender": [],
|
|
|
|
"underride": []
|
|
|
|
}
|
|
|
|
}`)
|
|
|
|
return util.JSONResponse{
|
2018-03-13 16:55:45 +01:00
|
|
|
Code: http.StatusOK,
|
2017-04-20 18:11:53 +02:00
|
|
|
JSON: &res,
|
|
|
|
}
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 18:11:53 +02:00
|
|
|
|
2017-10-10 15:28:49 +02:00
|
|
|
r0mux.Handle("/user/{userId}/filter",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("put_filter", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 19:16:53 +02:00
|
|
|
return PutFilter(req, device, accountDB, vars["userId"])
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-04-20 18:11:53 +02:00
|
|
|
|
2017-10-10 15:28:49 +02:00
|
|
|
r0mux.Handle("/user/{userId}/filter/{filterId}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("get_filter", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 19:16:53 +02:00
|
|
|
return GetFilter(req, device, accountDB, vars["userId"], vars["filterId"])
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 18:11:53 +02:00
|
|
|
|
|
|
|
// Riot user settings
|
|
|
|
|
|
|
|
r0mux.Handle("/profile/{userID}",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("profile", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-02-11 12:18:12 +01:00
|
|
|
return GetProfile(req, accountDB, cfg, vars["userID"], asAPI, federation)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 18:11:53 +02:00
|
|
|
|
2017-07-10 15:52:41 +02:00
|
|
|
r0mux.Handle("/profile/{userID}/avatar_url",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("profile_avatar_url", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-02-11 12:18:12 +01:00
|
|
|
return GetAvatarURL(req, accountDB, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 15:52:41 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 15:52:41 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/profile/{userID}/avatar_url",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("profile_avatar_url", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-10 13:17:54 +02:00
|
|
|
return SetAvatarURL(req, accountDB, device, vars["userID"], cfg, rsAPI)
|
2017-07-10 15:52:41 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 15:52:41 +02:00
|
|
|
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows
|
|
|
|
// PUT requests, so we need to allow this method
|
|
|
|
|
|
|
|
r0mux.Handle("/profile/{userID}/displayname",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("profile_displayname", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-02-11 12:18:12 +01:00
|
|
|
return GetDisplayName(req, accountDB, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 15:52:41 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 15:52:41 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/profile/{userID}/displayname",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("profile_displayname", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-10 13:17:54 +02:00
|
|
|
return SetDisplayName(req, accountDB, device, vars["userID"], cfg, rsAPI)
|
2017-07-10 15:52:41 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 15:52:41 +02:00
|
|
|
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows
|
|
|
|
// PUT requests, so we need to allow this method
|
|
|
|
|
2017-04-20 18:11:53 +02:00
|
|
|
r0mux.Handle("/account/3pid",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2017-10-11 19:16:53 +02:00
|
|
|
return GetAssociated3PIDs(req, accountDB, device)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-01 11:13:10 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/account/3pid",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2017-10-11 19:16:53 +02:00
|
|
|
return CheckAndSave3PIDAssociation(req, accountDB, device, cfg)
|
2017-09-01 11:13:10 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 11:13:10 +02:00
|
|
|
|
|
|
|
unstableMux.Handle("/account/3pid/delete",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2017-10-11 19:16:53 +02:00
|
|
|
return Forget3PID(req, accountDB)
|
2017-09-01 11:13:10 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 11:13:10 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/{path:(?:account/3pid|register)}/email/requestToken",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("account_3pid_request_token", func(req *http.Request) util.JSONResponse {
|
2017-10-11 19:16:53 +02:00
|
|
|
return RequestEmailToken(req, accountDB, cfg)
|
2017-09-01 11:13:10 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-04-20 18:11:53 +02:00
|
|
|
|
|
|
|
// Riot logs get flooded unless this is handled
|
|
|
|
r0mux.Handle("/presence/{userID}/status",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("presence", func(req *http.Request) util.JSONResponse {
|
2017-04-20 18:11:53 +02:00
|
|
|
// TODO: Set presence (probably the responsibility of a presence server not clientapi)
|
|
|
|
return util.JSONResponse{
|
2018-03-13 16:55:45 +01:00
|
|
|
Code: http.StatusOK,
|
2017-04-20 18:11:53 +02:00
|
|
|
JSON: struct{}{},
|
|
|
|
}
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-04-20 18:11:53 +02:00
|
|
|
|
2017-06-27 13:37:25 +02:00
|
|
|
r0mux.Handle("/voip/turnServer",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("turn_server", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2017-11-09 10:58:45 +01:00
|
|
|
return RequestTurnServer(req, device, cfg)
|
2017-06-27 13:37:25 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2020-03-19 12:04:08 +01:00
|
|
|
r0mux.Handle("/thirdparty/protocols",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("thirdparty_protocols", func(req *http.Request) util.JSONResponse {
|
2017-06-27 13:37:25 +02:00
|
|
|
// TODO: Return the third party protcols
|
|
|
|
return util.JSONResponse{
|
2018-03-13 16:55:45 +01:00
|
|
|
Code: http.StatusOK,
|
2017-06-27 13:37:25 +02:00
|
|
|
JSON: struct{}{},
|
|
|
|
}
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/initialSync",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("rooms_initial_sync", func(req *http.Request) util.JSONResponse {
|
2017-06-27 13:37:25 +02:00
|
|
|
// TODO: Allow people to peek into rooms.
|
|
|
|
return util.JSONResponse{
|
2018-03-13 16:55:45 +01:00
|
|
|
Code: http.StatusForbidden,
|
2017-06-27 13:37:25 +02:00
|
|
|
JSON: jsonerror.GuestAccessForbidden("Guest access not implemented"),
|
|
|
|
}
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/user/{userID}/account_data/{type}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 19:16:53 +02:00
|
|
|
return SaveAccountData(req, accountDB, device, vars["userID"], "", vars["type"], syncProducer)
|
2017-07-26 15:53:11 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-26 15:53:11 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 19:16:53 +02:00
|
|
|
return SaveAccountData(req, accountDB, device, vars["userID"], vars["roomID"], vars["type"], syncProducer)
|
2017-06-27 13:37:25 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2020-01-29 18:53:05 +01:00
|
|
|
r0mux.Handle("/user/{userID}/account_data/{type}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-01-29 18:53:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetAccountData(req, accountDB, device, vars["userID"], "", vars["type"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
r0mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-01-29 18:53:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetAccountData(req, accountDB, device, vars["userID"], vars["roomID"], vars["type"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2017-08-21 17:34:26 +02:00
|
|
|
r0mux.Handle("/rooms/{roomID}/members",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("rooms_members", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return GetMemberships(req, device, vars["roomID"], false, cfg, rsAPI)
|
2017-08-24 17:00:14 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-08-24 17:00:14 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/joined_members",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("rooms_members", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return GetMemberships(req, device, vars["roomID"], true, cfg, rsAPI)
|
2017-08-21 17:34:26 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-08-21 17:34:26 +02:00
|
|
|
|
2017-06-27 13:37:25 +02:00
|
|
|
r0mux.Handle("/rooms/{roomID}/read_markers",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("rooms_read_markers", func(req *http.Request) util.JSONResponse {
|
2017-06-27 13:37:25 +02:00
|
|
|
// TODO: return the read_markers.
|
2018-03-13 16:55:45 +01:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: struct{}{}}
|
2017-06-27 13:37:25 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2017-10-17 20:12:54 +02:00
|
|
|
r0mux.Handle("/devices",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("get_devices", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2017-10-17 20:12:54 +02:00
|
|
|
return GetDevicesByLocalpart(req, deviceDB, device)
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 20:12:54 +02:00
|
|
|
|
2018-05-24 14:53:22 +02:00
|
|
|
r0mux.Handle("/devices/{deviceID}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("get_device", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-17 20:12:54 +02:00
|
|
|
return GetDeviceByID(req, deviceDB, device, vars["deviceID"])
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 20:12:54 +02:00
|
|
|
|
2017-11-14 10:59:02 +01:00
|
|
|
r0mux.Handle("/devices/{deviceID}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("device_data", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-11-14 10:59:02 +01:00
|
|
|
return UpdateDeviceByID(req, deviceDB, device, vars["deviceID"])
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-11-14 10:59:02 +01:00
|
|
|
|
2020-02-11 13:13:38 +01:00
|
|
|
r0mux.Handle("/devices/{deviceID}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("delete_device", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-02-11 13:13:38 +01:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return DeleteDeviceById(req, deviceDB, device, vars["deviceID"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
|
|
|
|
|
|
|
r0mux.Handle("/delete_devices",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("delete_devices", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-02-11 13:13:38 +01:00
|
|
|
return DeleteDevices(req, deviceDB, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2017-09-22 18:28:29 +02:00
|
|
|
// Stub implementations for sytest
|
|
|
|
r0mux.Handle("/events",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("events", func(req *http.Request) util.JSONResponse {
|
2018-03-13 16:55:45 +01:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 18:28:29 +02:00
|
|
|
"chunk": []interface{}{},
|
|
|
|
"start": "",
|
|
|
|
"end": "",
|
|
|
|
}}
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-22 18:28:29 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/initialSync",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("initial_sync", func(req *http.Request) util.JSONResponse {
|
2018-03-13 16:55:45 +01:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 18:28:29 +02:00
|
|
|
"end": "",
|
|
|
|
}}
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2019-08-02 13:17:51 +02:00
|
|
|
|
|
|
|
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("get_tags", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 13:17:51 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetTags(req, accountDB, device, vars["userId"], vars["roomId"], syncProducer)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("put_tag", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 13:17:51 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return PutTag(req, accountDB, device, vars["userId"], vars["roomId"], vars["tag"], syncProducer)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("delete_tag", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 13:17:51 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return DeleteTag(req, accountDB, device, vars["userId"], vars["roomId"], vars["tag"], syncProducer)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
2020-02-05 19:06:39 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/capabilities",
|
2020-06-16 15:10:55 +02:00
|
|
|
httputil.MakeAuthAPI("capabilities", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse {
|
2020-05-01 11:48:17 +02:00
|
|
|
return GetCapabilities(req, rsAPI)
|
2020-02-05 19:06:39 +01:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
2017-02-20 16:41:29 +01:00
|
|
|
}
|