2017-04-20 23:40:52 +01: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 15:41:29 +00:00
|
|
|
package routing
|
|
|
|
|
|
|
|
import (
|
2017-04-20 17:11:53 +01:00
|
|
|
"encoding/json"
|
2017-02-20 15:41:29 +00:00
|
|
|
"net/http"
|
2017-08-18 15:33:40 +01:00
|
|
|
"strings"
|
2017-02-20 15:41:29 +00:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2018-08-20 10:45:17 +01:00
|
|
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
2018-07-16 23:17:03 +01:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth"
|
2017-05-23 17:43:05 +01:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
2017-05-22 19:28:26 +01:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
2017-05-23 17:43:05 +01:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
2017-06-27 12:37:25 +01:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
2017-03-15 13:36:26 +00:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
2017-05-23 17:43:05 +01:00
|
|
|
"github.com/matrix-org/dendrite/common"
|
2017-06-19 15:21:04 +01:00
|
|
|
"github.com/matrix-org/dendrite/common/config"
|
2018-05-18 10:49:40 +01:00
|
|
|
"github.com/matrix-org/dendrite/common/transactions"
|
2019-10-01 17:09:47 +01:00
|
|
|
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
|
2018-08-08 16:17:09 +01:00
|
|
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
2017-05-25 16:08:28 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2017-02-20 15:41:29 +00:00
|
|
|
"github.com/matrix-org/util"
|
|
|
|
)
|
|
|
|
|
2017-09-22 16:13:19 +01:00
|
|
|
const pathPrefixV1 = "/_matrix/client/api/v1"
|
2017-02-20 15:41:29 +00:00
|
|
|
const pathPrefixR0 = "/_matrix/client/r0"
|
2017-06-27 12:37:25 +01:00
|
|
|
const pathPrefixUnstable = "/_matrix/client/unstable"
|
2017-02-20 15:41:29 +00: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 16:38:50 +01:00
|
|
|
//
|
|
|
|
// Due to Setup being used to call many other functions, a gocyclo nolint is
|
|
|
|
// applied:
|
|
|
|
// nolint: gocyclo
|
2017-05-25 16:08:28 +01:00
|
|
|
func Setup(
|
2020-02-11 11:18:12 +00:00
|
|
|
apiMux *mux.Router, cfg *config.Dendrite,
|
2018-08-08 16:17:09 +01:00
|
|
|
producer *producers.RoomserverProducer,
|
2020-05-01 10:48:17 +01:00
|
|
|
rsAPI roomserverAPI.RoomserverInternalAPI,
|
2018-08-20 10:45:17 +01:00
|
|
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
2020-02-13 17:27:33 +00:00
|
|
|
accountDB accounts.Database,
|
|
|
|
deviceDB devices.Database,
|
2017-05-25 16:08:28 +01:00
|
|
|
federation *gomatrixserverlib.FederationClient,
|
|
|
|
keyRing gomatrixserverlib.KeyRing,
|
2017-07-11 14:14:06 +01:00
|
|
|
userUpdateProducer *producers.UserUpdateProducer,
|
2017-08-02 16:21:35 +01:00
|
|
|
syncProducer *producers.SyncAPIProducer,
|
2020-03-30 15:02:20 +01:00
|
|
|
eduProducer *producers.EDUServerProducer,
|
2018-05-18 10:49:40 +01:00
|
|
|
transactionsCache *transactions.Cache,
|
2020-04-29 11:34:31 +01:00
|
|
|
federationSender federationSenderAPI.FederationSenderInternalAPI,
|
2017-05-25 16:08:28 +01:00
|
|
|
) {
|
2017-06-27 12:37:25 +01:00
|
|
|
|
|
|
|
apiMux.Handle("/_matrix/client/versions",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse {
|
2017-06-27 12:37:25 +01:00
|
|
|
return util.JSONResponse{
|
2018-03-13 15:55:45 +00:00
|
|
|
Code: http.StatusOK,
|
2017-06-27 12:37:25 +01:00
|
|
|
JSON: struct {
|
|
|
|
Versions []string `json:"versions"`
|
|
|
|
}{[]string{
|
|
|
|
"r0.0.1",
|
|
|
|
"r0.1.0",
|
|
|
|
"r0.2.0",
|
2018-03-14 17:36:02 +00:00
|
|
|
"r0.3.0",
|
2017-06-27 12:37:25 +01:00
|
|
|
}},
|
|
|
|
}
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 12:37:25 +01:00
|
|
|
|
2017-02-20 15:41:29 +00:00
|
|
|
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
|
2017-09-22 16:13:19 +01:00
|
|
|
v1mux := apiMux.PathPrefix(pathPrefixV1).Subrouter()
|
2017-06-27 12:37:25 +01:00
|
|
|
unstableMux := apiMux.PathPrefix(pathPrefixUnstable).Subrouter()
|
|
|
|
|
2019-05-21 21:56:55 +01:00
|
|
|
authData := auth.Data{
|
|
|
|
AccountDB: accountDB,
|
|
|
|
DeviceDB: deviceDB,
|
|
|
|
AppServices: cfg.Derived.ApplicationServices,
|
|
|
|
}
|
2018-07-16 23:17:03 +01:00
|
|
|
|
2017-05-18 13:47:23 +01:00
|
|
|
r0mux.Handle("/createRoom",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("createRoom", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2020-05-01 10:48:17 +01:00
|
|
|
return CreateRoom(req, device, cfg, producer, accountDB, rsAPI, asAPI)
|
2017-05-18 13:47:23 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-05-25 16:08:28 +01:00
|
|
|
r0mux.Handle("/join/{roomIDOrAlias}",
|
2019-08-06 15:07:36 +01:00
|
|
|
common.MakeAuthAPI(gomatrixserverlib.Join, authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 18:16:53 +01:00
|
|
|
return JoinRoomByIDOrAlias(
|
2020-04-29 15:29:39 +01:00
|
|
|
req, device, vars["roomIDOrAlias"], cfg, federation, producer,
|
2020-05-01 10:48:17 +01:00
|
|
|
rsAPI, federationSender, keyRing, accountDB,
|
2017-05-25 16:08:28 +01:00
|
|
|
)
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2020-03-19 10:25:36 +00:00
|
|
|
r0mux.Handle("/joined_rooms",
|
|
|
|
common.MakeAuthAPI("joined_rooms", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
return GetJoinedRooms(req, device, accountDB)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2017-08-04 16:32:10 +01:00
|
|
|
r0mux.Handle("/rooms/{roomID}/{membership:(?:join|kick|ban|unban|leave|invite)}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("membership", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return SendMembership(req, accountDB, device, vars["roomID"], vars["membership"], cfg, rsAPI, asAPI, producer)
|
2017-08-04 16:32:10 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-26 12:55:48 +01:00
|
|
|
r0mux.Handle("/rooms/{roomID}/send/{eventType}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, nil, cfg, rsAPI, producer, nil)
|
2017-09-26 12:55:48 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-03-15 11:22:40 +00:00
|
|
|
r0mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-09-26 12:55:48 +01:00
|
|
|
txnID := vars["txnID"]
|
2018-05-18 10:49:40 +01:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], &txnID,
|
2020-05-01 10:48:17 +01:00
|
|
|
nil, cfg, rsAPI, producer, transactionsCache)
|
2017-05-18 13:47:23 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2019-08-09 10:45:54 +01:00
|
|
|
r0mux.Handle("/rooms/{roomID}/event/{eventID}",
|
|
|
|
common.MakeAuthAPI("rooms_get_event", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return GetEvent(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, federation, keyRing)
|
2019-08-09 10:45:54 +01:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 18:36:08 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/state", common.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return OnIncomingStateRequest(req.Context(), rsAPI, vars["roomID"])
|
2020-04-14 18:36:08 +01:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{type}", common.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], "")
|
2020-04-14 18:36:08 +01:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", common.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], vars["stateKey"])
|
2020-04-14 18:36:08 +01:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2017-08-18 15:33:40 +01:00
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 11:21:52 +00:00
|
|
|
emptyString := ""
|
2017-08-18 15:33:40 +01:00
|
|
|
eventType := vars["eventType"]
|
|
|
|
// If there's a trailing slash, remove it
|
|
|
|
if strings.HasSuffix(eventType, "/") {
|
|
|
|
eventType = eventType[:len(eventType)-1]
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, rsAPI, producer, nil)
|
2017-05-18 13:47:23 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2020-04-14 18:36:08 +01:00
|
|
|
|
2017-03-17 11:21:52 +00:00
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("send_message", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 11:21:52 +00:00
|
|
|
stateKey := vars["stateKey"]
|
2020-05-01 10:48:17 +01:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, &stateKey, cfg, rsAPI, producer, nil)
|
2017-05-18 13:47:23 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-02-20 15:41:29 +00:00
|
|
|
|
2017-09-28 14:50:40 +01:00
|
|
|
r0mux.Handle("/register", common.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse {
|
2020-02-11 11:18:12 +00:00
|
|
|
return Register(req, accountDB, deviceDB, cfg)
|
2018-03-13 15:55:45 +00:00
|
|
|
})).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-22 16:13:19 +01:00
|
|
|
|
2017-09-28 14:50:40 +01:00
|
|
|
v1mux.Handle("/register", common.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse {
|
2020-02-11 11:18:12 +00:00
|
|
|
return LegacyRegister(req, accountDB, deviceDB, cfg)
|
2018-03-13 15:55:45 +00:00
|
|
|
})).Methods(http.MethodPost, http.MethodOptions)
|
2017-05-22 15:55:39 +01:00
|
|
|
|
2017-10-09 15:24:38 +01:00
|
|
|
r0mux.Handle("/register/available", common.MakeExternalAPI("registerAvailable", func(req *http.Request) util.JSONResponse {
|
2018-08-20 10:23:01 +01:00
|
|
|
return RegisterAvailable(req, cfg, accountDB)
|
2018-03-13 15:55:45 +00:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-09 15:24:38 +01:00
|
|
|
|
2017-06-27 12:37:25 +01:00
|
|
|
r0mux.Handle("/directory/room/{roomAlias}",
|
2018-08-08 16:17:09 +01:00
|
|
|
common.MakeExternalAPI("directory_room", func(req *http.Request) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return DirectoryRoom(req, vars["roomAlias"], federation, cfg, rsAPI, federationSender)
|
2017-06-27 12:37:25 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-28 11:31:43 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/directory/room/{roomAlias}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("directory_room", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return SetLocalAlias(req, device, vars["roomAlias"], cfg, rsAPI)
|
2017-07-28 11:31:43 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-28 11:31:43 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/directory/room/{roomAlias}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("directory_room", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return RemoveLocalAlias(req, device, vars["roomAlias"], rsAPI)
|
2017-07-28 11:31:43 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
2017-06-27 12:37:25 +01:00
|
|
|
|
2017-07-11 16:04:34 +01:00
|
|
|
r0mux.Handle("/logout",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("logout", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2017-10-11 18:16:53 +01:00
|
|
|
return Logout(req, deviceDB, device)
|
2017-07-11 16:04:34 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-07-11 16:04:34 +01:00
|
|
|
|
2017-10-15 11:29:47 +01:00
|
|
|
r0mux.Handle("/logout/all",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("logout", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2017-10-15 11:29:47 +01:00
|
|
|
return LogoutAll(req, deviceDB, device)
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-10-15 11:29:47 +01:00
|
|
|
|
2018-07-24 15:49:49 +01:00
|
|
|
r0mux.Handle("/rooms/{roomID}/typing/{userID}",
|
|
|
|
common.MakeAuthAPI("rooms_typing", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-03-30 15:02:20 +01:00
|
|
|
return SendTyping(req, device, vars["roomID"], vars["userID"], accountDB, eduProducer)
|
2018-07-24 15:49:49 +01:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
2018-08-04 10:32:02 +01:00
|
|
|
r0mux.Handle("/account/whoami",
|
|
|
|
common.MakeAuthAPI("whoami", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
return Whoami(req, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2017-04-20 17:11:53 +01:00
|
|
|
// Stub endpoints required by Riot
|
|
|
|
|
|
|
|
r0mux.Handle("/login",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("login", func(req *http.Request) util.JSONResponse {
|
2017-10-11 18:16:53 +01:00
|
|
|
return Login(req, accountDB, deviceDB, cfg)
|
2017-05-18 13:47:23 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
2017-04-20 17:11:53 +01:00
|
|
|
|
2019-08-14 18:34:49 +01:00
|
|
|
r0mux.Handle("/auth/{authType}/fallback/web",
|
|
|
|
common.MakeHTMLAPI("auth_fallback", func(w http.ResponseWriter, req *http.Request) *util.JSONResponse {
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
return AuthFallback(w, req, vars["authType"], cfg)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
|
2017-04-20 17:11:53 +01:00
|
|
|
r0mux.Handle("/pushrules/",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("push_rules", func(req *http.Request) util.JSONResponse {
|
2017-04-20 17:11:53 +01:00
|
|
|
// TODO: Implement push rules API
|
|
|
|
res := json.RawMessage(`{
|
|
|
|
"global": {
|
|
|
|
"content": [],
|
|
|
|
"override": [],
|
|
|
|
"room": [],
|
|
|
|
"sender": [],
|
|
|
|
"underride": []
|
|
|
|
}
|
|
|
|
}`)
|
|
|
|
return util.JSONResponse{
|
2018-03-13 15:55:45 +00:00
|
|
|
Code: http.StatusOK,
|
2017-04-20 17:11:53 +01:00
|
|
|
JSON: &res,
|
|
|
|
}
|
2017-05-18 13:47:23 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 17:11:53 +01:00
|
|
|
|
2017-10-10 14:28:49 +01:00
|
|
|
r0mux.Handle("/user/{userId}/filter",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("put_filter", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 18:16:53 +01:00
|
|
|
return PutFilter(req, device, accountDB, vars["userId"])
|
2017-05-18 13:47:23 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-04-20 17:11:53 +01:00
|
|
|
|
2017-10-10 14:28:49 +01:00
|
|
|
r0mux.Handle("/user/{userId}/filter/{filterId}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("get_filter", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 18:16:53 +01:00
|
|
|
return GetFilter(req, device, accountDB, vars["userId"], vars["filterId"])
|
2017-05-18 13:47:23 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 17:11:53 +01:00
|
|
|
|
|
|
|
// Riot user settings
|
|
|
|
|
|
|
|
r0mux.Handle("/profile/{userID}",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("profile", func(req *http.Request) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-02-11 11:18:12 +00:00
|
|
|
return GetProfile(req, accountDB, cfg, vars["userID"], asAPI, federation)
|
2017-05-18 13:47:23 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 17:11:53 +01:00
|
|
|
|
2017-07-10 14:52:41 +01:00
|
|
|
r0mux.Handle("/profile/{userID}/avatar_url",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("profile_avatar_url", func(req *http.Request) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-02-11 11:18:12 +00:00
|
|
|
return GetAvatarURL(req, accountDB, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 14:52:41 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 14:52:41 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/profile/{userID}/avatar_url",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("profile_avatar_url", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return SetAvatarURL(req, accountDB, device, vars["userID"], userUpdateProducer, cfg, producer, rsAPI)
|
2017-07-10 14:52:41 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 14:52:41 +01: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",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("profile_displayname", func(req *http.Request) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-02-11 11:18:12 +00:00
|
|
|
return GetDisplayName(req, accountDB, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 14:52:41 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 14:52:41 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/profile/{userID}/displayname",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("profile_displayname", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return SetDisplayName(req, accountDB, device, vars["userID"], userUpdateProducer, cfg, producer, rsAPI)
|
2017-07-10 14:52:41 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 14:52:41 +01: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 17:11:53 +01:00
|
|
|
r0mux.Handle("/account/3pid",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2017-10-11 18:16:53 +01:00
|
|
|
return GetAssociated3PIDs(req, accountDB, device)
|
2017-05-18 13:47:23 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-01 10:13:10 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/account/3pid",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2017-10-11 18:16:53 +01:00
|
|
|
return CheckAndSave3PIDAssociation(req, accountDB, device, cfg)
|
2017-09-01 10:13:10 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 10:13:10 +01:00
|
|
|
|
|
|
|
unstableMux.Handle("/account/3pid/delete",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2017-10-11 18:16:53 +01:00
|
|
|
return Forget3PID(req, accountDB)
|
2017-09-01 10:13:10 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 10:13:10 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/{path:(?:account/3pid|register)}/email/requestToken",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("account_3pid_request_token", func(req *http.Request) util.JSONResponse {
|
2017-10-11 18:16:53 +01:00
|
|
|
return RequestEmailToken(req, accountDB, cfg)
|
2017-09-01 10:13:10 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-04-20 17:11:53 +01:00
|
|
|
|
|
|
|
// Riot logs get flooded unless this is handled
|
|
|
|
r0mux.Handle("/presence/{userID}/status",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("presence", func(req *http.Request) util.JSONResponse {
|
2017-04-20 17:11:53 +01:00
|
|
|
// TODO: Set presence (probably the responsibility of a presence server not clientapi)
|
|
|
|
return util.JSONResponse{
|
2018-03-13 15:55:45 +00:00
|
|
|
Code: http.StatusOK,
|
2017-04-20 17:11:53 +01:00
|
|
|
JSON: struct{}{},
|
|
|
|
}
|
2017-05-18 13:47:23 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-04-20 17:11:53 +01:00
|
|
|
|
2017-06-27 12:37:25 +01:00
|
|
|
r0mux.Handle("/voip/turnServer",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("turn_server", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2017-11-09 09:58:45 +00:00
|
|
|
return RequestTurnServer(req, device, cfg)
|
2017-06-27 12:37:25 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 12:37:25 +01:00
|
|
|
|
2020-03-19 11:04:08 +00:00
|
|
|
r0mux.Handle("/thirdparty/protocols",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("thirdparty_protocols", func(req *http.Request) util.JSONResponse {
|
2017-06-27 12:37:25 +01:00
|
|
|
// TODO: Return the third party protcols
|
|
|
|
return util.JSONResponse{
|
2018-03-13 15:55:45 +00:00
|
|
|
Code: http.StatusOK,
|
2017-06-27 12:37:25 +01:00
|
|
|
JSON: struct{}{},
|
|
|
|
}
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 12:37:25 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/initialSync",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("rooms_initial_sync", func(req *http.Request) util.JSONResponse {
|
2017-06-27 12:37:25 +01:00
|
|
|
// TODO: Allow people to peek into rooms.
|
|
|
|
return util.JSONResponse{
|
2018-03-13 15:55:45 +00:00
|
|
|
Code: http.StatusForbidden,
|
2017-06-27 12:37:25 +01:00
|
|
|
JSON: jsonerror.GuestAccessForbidden("Guest access not implemented"),
|
|
|
|
}
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 12:37:25 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/user/{userID}/account_data/{type}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 18:16:53 +01:00
|
|
|
return SaveAccountData(req, accountDB, device, vars["userID"], "", vars["type"], syncProducer)
|
2017-07-26 14:53:11 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-26 14:53:11 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 18:16:53 +01:00
|
|
|
return SaveAccountData(req, accountDB, device, vars["userID"], vars["roomID"], vars["type"], syncProducer)
|
2017-06-27 12:37:25 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-06-27 12:37:25 +01:00
|
|
|
|
2020-01-29 17:53:05 +00:00
|
|
|
r0mux.Handle("/user/{userID}/account_data/{type}",
|
|
|
|
common.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
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}",
|
|
|
|
common.MakeAuthAPI("user_account_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetAccountData(req, accountDB, device, vars["userID"], vars["roomID"], vars["type"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2017-08-21 16:34:26 +01:00
|
|
|
r0mux.Handle("/rooms/{roomID}/members",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("rooms_members", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return GetMemberships(req, device, vars["roomID"], false, cfg, rsAPI)
|
2017-08-24 16:00:14 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-08-24 16:00:14 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/joined_members",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("rooms_members", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 10:48:17 +01:00
|
|
|
return GetMemberships(req, device, vars["roomID"], true, cfg, rsAPI)
|
2017-08-21 16:34:26 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-08-21 16:34:26 +01:00
|
|
|
|
2017-06-27 12:37:25 +01:00
|
|
|
r0mux.Handle("/rooms/{roomID}/read_markers",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("rooms_read_markers", func(req *http.Request) util.JSONResponse {
|
2017-06-27 12:37:25 +01:00
|
|
|
// TODO: return the read_markers.
|
2018-03-13 15:55:45 +00:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: struct{}{}}
|
2017-06-27 12:37:25 +01:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-06-27 12:37:25 +01:00
|
|
|
|
2017-10-17 19:12:54 +01:00
|
|
|
r0mux.Handle("/devices",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("get_devices", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2017-10-17 19:12:54 +01:00
|
|
|
return GetDevicesByLocalpart(req, deviceDB, device)
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 19:12:54 +01:00
|
|
|
|
2018-05-24 13:53:22 +01:00
|
|
|
r0mux.Handle("/devices/{deviceID}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("get_device", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-17 19:12:54 +01:00
|
|
|
return GetDeviceByID(req, deviceDB, device, vars["deviceID"])
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 19:12:54 +01:00
|
|
|
|
2017-11-14 09:59:02 +00:00
|
|
|
r0mux.Handle("/devices/{deviceID}",
|
2018-07-16 23:17:03 +01:00
|
|
|
common.MakeAuthAPI("device_data", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2019-07-03 16:38:50 +01:00
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-11-14 09:59:02 +00:00
|
|
|
return UpdateDeviceByID(req, deviceDB, device, vars["deviceID"])
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-11-14 09:59:02 +00:00
|
|
|
|
2020-02-11 12:13:38 +00:00
|
|
|
r0mux.Handle("/devices/{deviceID}",
|
|
|
|
common.MakeAuthAPI("delete_device", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return DeleteDeviceById(req, deviceDB, device, vars["deviceID"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
|
|
|
|
|
|
|
r0mux.Handle("/delete_devices",
|
|
|
|
common.MakeAuthAPI("delete_devices", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
return DeleteDevices(req, deviceDB, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2017-09-22 17:28:29 +01:00
|
|
|
// Stub implementations for sytest
|
|
|
|
r0mux.Handle("/events",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("events", func(req *http.Request) util.JSONResponse {
|
2018-03-13 15:55:45 +00:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 17:28:29 +01:00
|
|
|
"chunk": []interface{}{},
|
|
|
|
"start": "",
|
|
|
|
"end": "",
|
|
|
|
}}
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-22 17:28:29 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/initialSync",
|
2017-09-28 14:50:40 +01:00
|
|
|
common.MakeExternalAPI("initial_sync", func(req *http.Request) util.JSONResponse {
|
2018-03-13 15:55:45 +00:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 17:28:29 +01:00
|
|
|
"end": "",
|
|
|
|
}}
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2019-08-02 12:17:51 +01:00
|
|
|
|
|
|
|
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags",
|
|
|
|
common.MakeAuthAPI("get_tags", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
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}",
|
|
|
|
common.MakeAuthAPI("put_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
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}",
|
|
|
|
common.MakeAuthAPI("delete_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
|
|
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
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 18:06:39 +00:00
|
|
|
|
|
|
|
r0mux.Handle("/capabilities",
|
|
|
|
common.MakeAuthAPI("capabilities", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
2020-05-01 10:48:17 +01:00
|
|
|
return GetCapabilities(req, rsAPI)
|
2020-02-05 18:06:39 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
2017-02-20 15:41:29 +00:00
|
|
|
}
|