2020-07-02 09:41:18 -05:00
|
|
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
2017-04-20 17:40:52 -05:00
|
|
|
//
|
|
|
|
// 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 09:41:29 -06:00
|
|
|
package routing
|
|
|
|
|
|
|
|
import (
|
2022-02-18 09:05:03 -06:00
|
|
|
"context"
|
2017-02-20 09:41:29 -06:00
|
|
|
"net/http"
|
2017-08-18 09:33:40 -05:00
|
|
|
"strings"
|
2017-02-20 09:41:29 -06:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2018-08-20 04:45:17 -05:00
|
|
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
2020-07-02 11:11:33 -05:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/api"
|
2020-07-09 18:39:44 -05:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth"
|
2020-10-09 03:15:51 -05:00
|
|
|
clientutil "github.com/matrix-org/dendrite/clientapi/httputil"
|
2017-06-27 06:37:25 -05:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
2017-03-15 08:36:26 -05:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
2020-06-10 06:17:54 -05:00
|
|
|
eduServerAPI "github.com/matrix-org/dendrite/eduserver/api"
|
2021-11-24 04:45:23 -06:00
|
|
|
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
2020-06-12 08:55:57 -05:00
|
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
2020-05-21 08:40:13 -05:00
|
|
|
"github.com/matrix-org/dendrite/internal/transactions"
|
2020-07-15 06:02:34 -05:00
|
|
|
keyserverAPI "github.com/matrix-org/dendrite/keyserver/api"
|
2018-08-08 10:17:09 -05:00
|
|
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
2020-12-02 11:41:00 -06:00
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2020-07-02 09:41:18 -05:00
|
|
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
2017-05-25 10:08:28 -05:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2017-02-20 09:41:29 -06:00
|
|
|
"github.com/matrix-org/util"
|
2021-07-09 10:52:31 -05:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-02-20 09:41:29 -06: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 10:38:50 -05:00
|
|
|
//
|
|
|
|
// Due to Setup being used to call many other functions, a gocyclo nolint is
|
|
|
|
// applied:
|
|
|
|
// nolint: gocyclo
|
2017-05-25 10:08:28 -05:00
|
|
|
func Setup(
|
2022-02-21 10:09:25 -06:00
|
|
|
publicAPIMux, synapseAdminRouter *mux.Router, cfg *config.ClientAPI,
|
2020-06-10 06:17:54 -05:00
|
|
|
eduAPI eduServerAPI.EDUServerInputAPI,
|
2020-05-01 04:48:17 -05:00
|
|
|
rsAPI roomserverAPI.RoomserverInternalAPI,
|
2018-08-20 04:45:17 -05:00
|
|
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
2020-07-02 11:11:33 -05:00
|
|
|
userAPI userapi.UserInternalAPI,
|
2017-05-25 10:08:28 -05:00
|
|
|
federation *gomatrixserverlib.FederationClient,
|
2017-08-02 10:21:35 -05:00
|
|
|
syncProducer *producers.SyncAPIProducer,
|
2018-05-18 04:49:40 -05:00
|
|
|
transactionsCache *transactions.Cache,
|
2021-11-24 04:45:23 -06:00
|
|
|
federationSender federationAPI.FederationInternalAPI,
|
2020-07-15 06:02:34 -05:00
|
|
|
keyAPI keyserverAPI.KeyInternalAPI,
|
2020-07-03 06:59:00 -05:00
|
|
|
extRoomsProvider api.ExtraPublicRoomsProvider,
|
2021-01-22 10:08:47 -06:00
|
|
|
mscCfg *config.MSCs,
|
2017-05-25 10:08:28 -05:00
|
|
|
) {
|
2021-11-24 06:55:44 -06:00
|
|
|
rateLimits := httputil.NewRateLimits(&cfg.RateLimiting)
|
2022-03-24 16:45:44 -05:00
|
|
|
userInteractiveAuth := auth.NewUserInteractive(userAPI, cfg)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2021-08-04 11:56:29 -05:00
|
|
|
unstableFeatures := map[string]bool{
|
2021-08-17 07:44:30 -05:00
|
|
|
"org.matrix.e2e_cross_signing": true,
|
2021-08-04 11:56:29 -05:00
|
|
|
}
|
2021-01-18 07:09:28 -06:00
|
|
|
for _, msc := range cfg.MSCs.MSCs {
|
|
|
|
unstableFeatures["org.matrix."+msc] = true
|
|
|
|
}
|
|
|
|
|
2020-08-13 06:16:37 -05:00
|
|
|
publicAPIMux.Handle("/versions",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse {
|
2017-06-27 06:37:25 -05:00
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusOK,
|
2017-06-27 06:37:25 -05:00
|
|
|
JSON: struct {
|
2021-01-18 07:09:28 -06:00
|
|
|
Versions []string `json:"versions"`
|
|
|
|
UnstableFeatures map[string]bool `json:"unstable_features"`
|
|
|
|
}{Versions: []string{
|
2017-06-27 06:37:25 -05:00
|
|
|
"r0.0.1",
|
|
|
|
"r0.1.0",
|
|
|
|
"r0.2.0",
|
2018-03-14 12:36:02 -05:00
|
|
|
"r0.3.0",
|
2020-08-25 09:44:33 -05:00
|
|
|
"r0.4.0",
|
|
|
|
"r0.5.0",
|
|
|
|
"r0.6.1",
|
2021-01-18 07:09:28 -06:00
|
|
|
}, UnstableFeatures: unstableFeatures},
|
2017-06-27 06:37:25 -05:00
|
|
|
}
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2021-07-09 10:52:31 -05:00
|
|
|
if cfg.RegistrationSharedSecret != "" {
|
|
|
|
logrus.Info("Enabling shared secret registration at /_synapse/admin/v1/register")
|
|
|
|
sr := NewSharedSecretRegistration(cfg.RegistrationSharedSecret)
|
|
|
|
synapseAdminRouter.Handle("/admin/v1/register",
|
|
|
|
httputil.MakeExternalAPI("shared_secret_registration", func(req *http.Request) util.JSONResponse {
|
|
|
|
if req.Method == http.MethodGet {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: 200,
|
|
|
|
JSON: struct {
|
|
|
|
Nonce string `json:"nonce"`
|
|
|
|
}{
|
|
|
|
Nonce: sr.GenerateNonce(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if req.Method == http.MethodPost {
|
|
|
|
return handleSharedSecretRegistration(userAPI, sr, req)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusMethodNotAllowed,
|
|
|
|
JSON: jsonerror.NotFound("unknown method"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:05:03 -06:00
|
|
|
// server notifications
|
2022-02-21 07:27:59 -06:00
|
|
|
var (
|
|
|
|
serverNotificationSender *userapi.Device
|
|
|
|
err error
|
|
|
|
)
|
2022-02-18 09:05:03 -06:00
|
|
|
if cfg.Matrix.ServerNotices.Enabled {
|
|
|
|
logrus.Info("Enabling server notices at /_synapse/admin/v1/send_server_notice")
|
2022-03-28 04:30:16 -05:00
|
|
|
serverNotificationSender, err = getSenderDevice(context.Background(), userAPI, cfg)
|
2022-02-18 09:05:03 -06:00
|
|
|
if err != nil {
|
|
|
|
logrus.WithError(err).Fatal("unable to get account for sending sending server notices")
|
|
|
|
}
|
|
|
|
|
|
|
|
synapseAdminRouter.Handle("/admin/v1/send_server_notice/{txnID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("send_server_notice", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-02-18 09:05:03 -06:00
|
|
|
// not specced, but ensure we're rate limiting requests to this endpoint
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
|
|
|
return SendServerNotice(
|
|
|
|
req, &cfg.Matrix.ServerNotices,
|
2022-03-24 16:45:44 -05:00
|
|
|
cfg, userAPI, rsAPI, asAPI,
|
2022-02-18 09:05:03 -06:00
|
|
|
device, serverNotificationSender,
|
|
|
|
&txnID, transactionsCache,
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
synapseAdminRouter.Handle("/admin/v1/send_server_notice",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("send_server_notice", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-02-18 09:05:03 -06:00
|
|
|
// not specced, but ensure we're rate limiting requests to this endpoint
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return SendServerNotice(
|
|
|
|
req, &cfg.Matrix.ServerNotices,
|
2022-03-24 16:45:44 -05:00
|
|
|
cfg, userAPI, rsAPI, asAPI,
|
2022-02-18 09:05:03 -06:00
|
|
|
device, serverNotificationSender,
|
|
|
|
nil, transactionsCache,
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
// You can't just do PathPrefix("/(r0|v3)") because regexps only apply when inside named path variables.
|
|
|
|
// So make a named path variable called 'apiversion' (which we will never read in handlers) and then do
|
|
|
|
// (r0|v3) - BUT this is a captured group, which makes no sense because you cannot extract this group
|
|
|
|
// from a match (gorilla/mux exposes no way to do this) so it demands you make it a non-capturing group
|
|
|
|
// using ?: so the final regexp becomes what is below. We also need a trailing slash to stop 'v33333' matching.
|
|
|
|
// Note that 'apiversion' is chosen because it must not collide with a variable used in any of the routing!
|
|
|
|
v3mux := publicAPIMux.PathPrefix("/{apiversion:(?:r0|v3)}/").Subrouter()
|
2022-03-04 02:59:15 -06:00
|
|
|
unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter()
|
2022-02-17 11:38:22 -06:00
|
|
|
|
2022-02-21 10:09:25 -06:00
|
|
|
// NOTSPEC: consent tracking
|
2022-02-16 03:11:23 -06:00
|
|
|
if cfg.Matrix.UserConsentOptions.Enabled {
|
2022-02-21 07:27:59 -06:00
|
|
|
if !cfg.Matrix.ServerNotices.Enabled {
|
|
|
|
logrus.Warnf("Consent tracking is enabled, but server notes are not. No server notice will be sent to users")
|
|
|
|
} else {
|
|
|
|
// start a new go routine to send messages about consent
|
2022-03-28 04:33:12 -05:00
|
|
|
go sendServerNoticeForConsent(userAPI, rsAPI, &cfg.Matrix.ServerNotices, cfg, serverNotificationSender, asAPI)
|
2022-02-21 07:27:59 -06:00
|
|
|
}
|
2022-02-21 10:09:25 -06:00
|
|
|
publicAPIMux.Handle("/consent",
|
2022-02-15 04:07:24 -06:00
|
|
|
httputil.MakeHTMLAPI("consent", func(writer http.ResponseWriter, request *http.Request) *util.JSONResponse {
|
|
|
|
return consent(writer, request, userAPI, cfg)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
2022-02-14 11:11:56 -06:00
|
|
|
}
|
2022-02-14 06:41:21 -06:00
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
consentRequiredCheck := httputil.WithConsentCheck(cfg.Matrix.UserConsentOptions, userAPI)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/createRoom",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("createRoom", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return CreateRoom(req, device, cfg, userAPI, rsAPI, asAPI)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/join/{roomIDOrAlias}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 12:16:53 -05:00
|
|
|
return JoinRoomByIDOrAlias(
|
2022-03-24 16:45:44 -05:00
|
|
|
req, device, rsAPI, userAPI, vars["roomIDOrAlias"],
|
2017-05-25 10:08:28 -05:00
|
|
|
)
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2021-01-22 10:08:47 -06:00
|
|
|
|
|
|
|
if mscCfg.Enabled("msc2753") {
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/peek/{roomIDOrAlias}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Peek, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2021-01-22 10:08:47 -06:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return PeekRoomByIDOrAlias(
|
2022-03-24 16:45:44 -05:00
|
|
|
req, device, rsAPI, vars["roomIDOrAlias"],
|
2021-01-22 10:08:47 -06:00
|
|
|
)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2021-01-22 10:08:47 -06:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/joined_rooms",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("joined_rooms", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-09-04 09:58:30 -05:00
|
|
|
return GetJoinedRooms(req, device, rsAPI)
|
2020-03-19 05:25:36 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/join",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-24 12:19:54 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return JoinRoomByIDOrAlias(
|
2022-03-24 16:45:44 -05:00
|
|
|
req, device, rsAPI, userAPI, vars["roomID"],
|
2020-06-24 12:19:54 -05:00
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/leave",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-05-04 12:34:09 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return LeaveRoomByID(
|
|
|
|
req, device, rsAPI, vars["roomID"],
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/unpeek",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("unpeek", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-12-03 05:11:46 -06:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return UnpeekRoomByID(
|
2022-03-24 16:45:44 -05:00
|
|
|
req, device, rsAPI, vars["roomID"],
|
2020-12-03 05:11:46 -06:00
|
|
|
)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2020-12-03 05:11:46 -06:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/ban",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-24 12:19:54 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SendBan(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2020-06-24 12:19:54 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/invite",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-24 12:19:54 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SendInvite(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2020-06-24 12:19:54 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/kick",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-24 12:19:54 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SendKick(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2020-06-24 12:19:54 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/unban",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SendUnban(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/send/{eventType}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-10 06:17:54 -05:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, nil, cfg, rsAPI, nil)
|
2017-09-26 06:55:48 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-09-26 06:55:48 -05:00
|
|
|
txnID := vars["txnID"]
|
2018-05-18 04:49:40 -05:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], &txnID,
|
2020-06-10 06:17:54 -05:00
|
|
|
nil, cfg, rsAPI, transactionsCache)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/event/{eventID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("rooms_get_event", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-09 04:45:54 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-15 04:13:57 -05:00
|
|
|
return GetEvent(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, federation)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2019-08-09 04:45:54 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 12:36:08 -05:00
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 12:36:08 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-08-25 12:43:56 -05:00
|
|
|
return OnIncomingStateRequest(req.Context(), device, rsAPI, vars["roomID"])
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 12:36:08 -05:00
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/aliases", httputil.MakeAuthAPI("aliases", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-21 10:53:50 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetAliases(req, rsAPI, device, vars["roomID"])
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)).Methods(http.MethodGet, http.MethodOptions)
|
2021-07-21 10:53:50 -05:00
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{type:[^/]+/?}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 12:36:08 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-24 03:59:59 -05:00
|
|
|
// If there's a trailing slash, remove it
|
2021-08-17 04:39:09 -05:00
|
|
|
eventType := strings.TrimSuffix(vars["type"], "/")
|
2020-06-17 10:21:42 -05:00
|
|
|
eventFormat := req.URL.Query().Get("format") == "event"
|
2020-07-28 04:09:10 -05:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), device, rsAPI, vars["roomID"], eventType, "", eventFormat)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 12:36:08 -05:00
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 12:36:08 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-17 10:21:42 -05:00
|
|
|
eventFormat := req.URL.Query().Get("format") == "event"
|
2020-07-28 04:09:10 -05:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), device, rsAPI, vars["roomID"], vars["type"], vars["stateKey"], eventFormat)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 12:36:08 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 06:21:52 -05:00
|
|
|
emptyString := ""
|
2021-08-17 04:39:09 -05:00
|
|
|
eventType := strings.TrimSuffix(vars["eventType"], "/")
|
2020-06-10 06:17:54 -05:00
|
|
|
return SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, rsAPI, nil)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2020-04-14 12:36:08 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 06:21:52 -05:00
|
|
|
stateKey := vars["stateKey"]
|
2020-06-10 06:17:54 -05:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, &stateKey, cfg, rsAPI, nil)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-02-20 09:41:29 -06:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/register", httputil.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return Register(req, userAPI, cfg)
|
2018-03-13 10:55:45 -05:00
|
|
|
})).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-22 10:13:19 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/register/available", httputil.MakeExternalAPI("registerAvailable", func(req *http.Request) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return RegisterAvailable(req, cfg, userAPI)
|
2018-03-13 10:55:45 -05:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-09 09:24:38 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("directory_room", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return DirectoryRoom(req, vars["roomAlias"], federation, cfg, rsAPI, federationSender)
|
2017-06-27 06:37:25 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-28 05:31:43 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return SetLocalAlias(req, device, vars["roomAlias"], cfg, rsAPI)
|
2017-07-28 05:31:43 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-28 05:31:43 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return RemoveLocalAlias(req, device, vars["roomAlias"], rsAPI)
|
2017-07-28 05:31:43 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/directory/list/room/{roomID}",
|
2020-07-02 09:41:18 -05:00
|
|
|
httputil.MakeExternalAPI("directory_list", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetVisibility(req, rsAPI, vars["roomID"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
// TODO: Add AS support
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/directory/list/room/{roomID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("directory_list", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-07-02 09:41:18 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-09-07 08:47:59 -05:00
|
|
|
return SetVisibility(req, rsAPI, device, vars["roomID"])
|
2020-07-02 09:41:18 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/publicRooms",
|
2020-07-02 09:41:18 -05:00
|
|
|
httputil.MakeExternalAPI("public_rooms", func(req *http.Request) util.JSONResponse {
|
2020-09-07 06:38:09 -05:00
|
|
|
return GetPostPublicRooms(req, rsAPI, extRoomsProvider, federation, cfg)
|
2020-07-02 09:41:18 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/logout",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("logout", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 12:53:40 -05:00
|
|
|
return Logout(req, userAPI, device)
|
2017-07-11 10:04:34 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-07-11 10:04:34 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/logout/all",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("logout", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 12:53:40 -05:00
|
|
|
return LogoutAll(req, userAPI, device)
|
2017-10-15 05:29:47 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-10-15 05:29:47 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/typing/{userID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("rooms_typing", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SendTyping(req, device, vars["roomID"], vars["userID"], eduAPI, rsAPI)
|
2018-07-24 09:49:49 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/redact/{eventID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("rooms_redact", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-07-03 11:24:51 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-09-04 06:30:56 -05:00
|
|
|
return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2020-07-03 11:24:51 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/redact/{eventID}/{txnId}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("rooms_redact", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-25 04:39:30 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-09-04 06:30:56 -05:00
|
|
|
return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI)
|
2020-08-25 04:39:30 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2018-07-24 09:49:49 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/sendToDevice/{eventType}/{txnID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05: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 11:50:19 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
2020-06-10 06:17:54 -05:00
|
|
|
return SendToDevice(req, device, eduAPI, transactionsCache, vars["eventType"], &txnID)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
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 11:50:19 -05: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}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05: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 11:50:19 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
2020-06-10 06:17:54 -05:00
|
|
|
return SendToDevice(req, device, eduAPI, transactionsCache, vars["eventType"], &txnID)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
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 11:50:19 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/account/whoami",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("whoami", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2018-08-04 04:32:02 -05:00
|
|
|
return Whoami(req, device)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-08-04 04:32:02 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/account/password",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("password", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-04 09:16:13 -05:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return Password(req, userAPI, device, cfg)
|
2020-09-04 09:16:13 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/account/deactivate",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("deactivate", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-10-02 11:18:20 -05:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return Deactivate(req, userInteractiveAuth, userAPI, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2021-04-07 07:26:20 -05:00
|
|
|
// Stub endpoints required by Element
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/login",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("login", func(req *http.Request) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return Login(req, userAPI, cfg)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/auth/{authType}/fallback/web",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeHTMLAPI("auth_fallback", func(w http.ResponseWriter, req *http.Request) *util.JSONResponse {
|
2019-08-14 12:34:49 -05:00
|
|
|
vars := mux.Vars(req)
|
|
|
|
return AuthFallback(w, req, vars["authType"], cfg)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-03-03 05:40:53 -06:00
|
|
|
// Push rules
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("missing trailing slash"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/pushrules/",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
return GetAllPushRules(req.Context(), device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2017-04-20 11:11:53 -05:00
|
|
|
return util.JSONResponse{
|
2022-03-03 05:40:53 -06:00
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("scope, kind and rule ID must be specified"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetPushRulesByScope(req.Context(), vars["scope"], device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("missing trailing slash after scope"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope:[^/]+/?}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("kind and rule ID must be specified"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetPushRulesByKind(req.Context(), vars["scope"], vars["kind"], device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("missing trailing slash after kind"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind:[^/]+/?}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("rule ID must be specified"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
2017-04-20 11:11:53 -05:00
|
|
|
}
|
2022-03-03 05:40:53 -06:00
|
|
|
return GetPushRuleByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], device, userAPI)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-03-03 05:40:53 -06:00
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
query := req.URL.Query()
|
|
|
|
return PutPushRuleByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], query.Get("after"), query.Get("before"), req.Body, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return DeletePushRuleByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}/{attr}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetPushRuleAttrByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], vars["attr"], device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}/{attr}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return PutPushRuleAttrByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], vars["attr"], req.Body, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
2021-04-07 07:26:20 -05:00
|
|
|
// Element user settings
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/profile/{userID}",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("profile", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return GetProfile(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/profile/{userID}/avatar_url",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("profile_avatar_url", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return GetAvatarURL(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 08:52:41 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 08:52:41 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/profile/{userID}/avatar_url",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("profile_avatar_url", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SetAvatarURL(req, userAPI, device, vars["userID"], cfg, rsAPI)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 08:52:41 -05:00
|
|
|
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows
|
|
|
|
// PUT requests, so we need to allow this method
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/profile/{userID}/displayname",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("profile_displayname", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return GetDisplayName(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 08:52:41 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 08:52:41 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/profile/{userID}/displayname",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("profile_displayname", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SetDisplayName(req, userAPI, device, vars["userID"], cfg, rsAPI)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 08:52:41 -05:00
|
|
|
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows
|
|
|
|
// PUT requests, so we need to allow this method
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/account/3pid",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return GetAssociated3PIDs(req, userAPI, device)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-01 04:13:10 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/account/3pid",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return CheckAndSave3PIDAssociation(req, userAPI, device, cfg)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 04:13:10 -05:00
|
|
|
|
|
|
|
unstableMux.Handle("/account/3pid/delete",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return Forget3PID(req, userAPI)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 04:13:10 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/{path:(?:account/3pid|register)}/email/requestToken",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("account_3pid_request_token", func(req *http.Request) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return RequestEmailToken(req, userAPI, cfg)
|
2017-09-01 04:13:10 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2021-04-07 07:26:20 -05:00
|
|
|
// Element logs get flooded unless this is handled
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/presence/{userID}/status",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("presence", func(req *http.Request) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2017-04-20 11:11:53 -05:00
|
|
|
// TODO: Set presence (probably the responsibility of a presence server not clientapi)
|
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusOK,
|
2017-04-20 11:11:53 -05:00
|
|
|
JSON: struct{}{},
|
|
|
|
}
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/voip/turnServer",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("turn_server", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2017-11-09 03:58:45 -06:00
|
|
|
return RequestTurnServer(req, device, cfg)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/thirdparty/protocols",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("thirdparty_protocols", func(req *http.Request) util.JSONResponse {
|
2017-06-27 06:37:25 -05:00
|
|
|
// TODO: Return the third party protcols
|
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusOK,
|
2017-06-27 06:37:25 -05:00
|
|
|
JSON: struct{}{},
|
|
|
|
}
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/initialSync",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("rooms_initial_sync", func(req *http.Request) util.JSONResponse {
|
2017-06-27 06:37:25 -05:00
|
|
|
// TODO: Allow people to peek into rooms.
|
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusForbidden,
|
2017-06-27 06:37:25 -05:00
|
|
|
JSON: jsonerror.GuestAccessForbidden("Guest access not implemented"),
|
|
|
|
}
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userID}/account_data/{type}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return SaveAccountData(req, userAPI, device, vars["userID"], "", vars["type"], syncProducer)
|
2017-07-26 08:53:11 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-26 08:53:11 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return SaveAccountData(req, userAPI, device, vars["userID"], vars["roomID"], vars["type"], syncProducer)
|
2017-06-27 06:37:25 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userID}/account_data/{type}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-01-29 11:53:05 -06:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return GetAccountData(req, userAPI, device, vars["userID"], "", vars["type"])
|
2020-01-29 11:53:05 -06:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-01-29 11:53:05 -06:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return GetAccountData(req, userAPI, device, vars["userID"], vars["roomID"], vars["type"])
|
2020-01-29 11:53:05 -06:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/admin/whois/{userID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("admin_whois", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-11-17 04:07:03 -06:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetAdminWhois(req, userAPI, device, vars["userID"])
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2020-11-17 04:07:03 -06:00
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userID}/openid/request_token",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("openid_request_token", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2021-04-07 07:26:20 -05:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return CreateOpenIDToken(req, userAPI, device, vars["userID"], cfg)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2021-04-07 07:26:20 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user_directory/search",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("userdirectory_search", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-07-28 04:53:17 -05:00
|
|
|
postContent := struct {
|
|
|
|
SearchString string `json:"search_term"`
|
|
|
|
Limit int `json:"limit"`
|
|
|
|
}{}
|
2020-10-09 03:15:51 -05:00
|
|
|
|
|
|
|
if resErr := clientutil.UnmarshalJSONRequest(req, &postContent); resErr != nil {
|
|
|
|
return *resErr
|
2020-07-28 04:53:17 -05:00
|
|
|
}
|
|
|
|
return *SearchUserDirectory(
|
|
|
|
req.Context(),
|
|
|
|
device,
|
|
|
|
userAPI,
|
2020-09-04 05:46:01 -05:00
|
|
|
rsAPI,
|
2020-07-28 04:53:17 -05:00
|
|
|
cfg.Matrix.ServerName,
|
|
|
|
postContent.SearchString,
|
|
|
|
postContent.Limit,
|
|
|
|
)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2020-07-28 04:53:17 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/members",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("rooms_members", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return GetMemberships(req, device, vars["roomID"], false, cfg, rsAPI)
|
2017-08-24 10:00:14 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-08-24 10:00:14 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/joined_members",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("rooms_members", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return GetMemberships(req, device, vars["roomID"], true, cfg, rsAPI)
|
2017-08-21 10:34:26 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-08-21 10:34:26 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/read_markers",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("rooms_read_markers", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-10-09 03:15:35 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-11-09 12:46:11 -06:00
|
|
|
return SaveReadMarker(req, userAPI, rsAPI, eduAPI, syncProducer, device, vars["roomID"])
|
2017-06-27 06:37:25 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/forget",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("rooms_forget", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-11-05 04:19:23 -06:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return SendForget(req, device, vars["roomID"], rsAPI)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2020-11-05 04:19:23 -06:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/devices",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("get_devices", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 12:53:40 -05:00
|
|
|
return GetDevicesByLocalpart(req, userAPI, device)
|
2017-10-17 13:12:54 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 13:12:54 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("get_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-08-27 12:53:40 -05:00
|
|
|
return GetDeviceByID(req, userAPI, device, vars["deviceID"])
|
2017-10-17 13:12:54 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 13:12:54 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("device_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-07-31 08:40:45 -05:00
|
|
|
return UpdateDeviceByID(req, userAPI, device, vars["deviceID"])
|
2017-11-14 03:59:02 -06:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-11-14 03:59:02 -06:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("delete_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-02-11 06:13:38 -06:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-07-30 12:00:56 -05:00
|
|
|
return DeleteDeviceById(req, userInteractiveAuth, userAPI, device, vars["deviceID"])
|
2020-02-11 06:13:38 -06:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/delete_devices",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("delete_devices", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-07-30 12:00:56 -05:00
|
|
|
return DeleteDevices(req, userAPI, device)
|
2020-02-11 06:13:38 -06:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-03-03 05:40:53 -06:00
|
|
|
v3mux.Handle("/notifications",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("get_notifications", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
return GetNotifications(req, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushers",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("get_pushers", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
return GetPushers(req, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushers/set",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("set_pushers", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-03 05:40:53 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return SetPusher(req, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2017-09-22 11:28:29 -05:00
|
|
|
// Stub implementations for sytest
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/events",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("events", func(req *http.Request) util.JSONResponse {
|
2018-03-13 10:55:45 -05:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 11:28:29 -05:00
|
|
|
"chunk": []interface{}{},
|
|
|
|
"start": "",
|
|
|
|
"end": "",
|
|
|
|
}}
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-22 11:28:29 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/initialSync",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("initial_sync", func(req *http.Request) util.JSONResponse {
|
2018-03-13 10:55:45 -05:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 11:28:29 -05:00
|
|
|
"end": "",
|
|
|
|
}}
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2019-08-02 06:17:51 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("get_tags", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 06:17:51 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return GetTags(req, userAPI, device, vars["userId"], vars["roomId"], syncProducer)
|
2019-08-02 06:17:51 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("put_tag", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 06:17:51 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return PutTag(req, userAPI, device, vars["userId"], vars["roomId"], vars["tag"], syncProducer)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2019-08-02 06:17:51 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("delete_tag", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 06:17:51 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return DeleteTag(req, userAPI, device, vars["userId"], vars["roomId"], vars["tag"], syncProducer)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2019-08-02 06:17:51 -05:00
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
2020-02-05 12:06:39 -06:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/capabilities",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("capabilities", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return GetCapabilities(req, rsAPI)
|
2020-02-05 12:06:39 -06:00
|
|
|
}),
|
2020-09-27 16:23:42 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2020-07-13 10:02:35 -05:00
|
|
|
|
2021-07-27 13:29:32 -05:00
|
|
|
// Key Backup Versions (Metadata)
|
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
getBackupKeysVersion := httputil.MakeAuthAPI("get_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-28 04:25:45 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return KeyBackupVersion(req, userAPI, device, vars["version"])
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
getLatestBackupKeysVersion := httputil.MakeAuthAPI("get_latest_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-28 04:25:45 -05:00
|
|
|
return KeyBackupVersion(req, userAPI, device, "")
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
putBackupKeysVersion := httputil.MakeAuthAPI("put_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-28 04:25:45 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return ModifyKeyBackupVersionAuthData(req, userAPI, device, vars["version"])
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
deleteBackupKeysVersion := httputil.MakeAuthAPI("delete_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-28 04:25:45 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return DeleteKeyBackupVersion(req, userAPI, device, vars["version"])
|
|
|
|
})
|
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
postNewBackupKeysVersion := httputil.MakeAuthAPI("post_new_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-28 04:25:45 -05:00
|
|
|
return CreateKeyBackupVersion(req, userAPI, device)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/room_keys/version/{version}", getBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
v3mux.Handle("/room_keys/version", getLatestBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
v3mux.Handle("/room_keys/version/{version}", putBackupKeysVersion).Methods(http.MethodPut)
|
|
|
|
v3mux.Handle("/room_keys/version/{version}", deleteBackupKeysVersion).Methods(http.MethodDelete)
|
|
|
|
v3mux.Handle("/room_keys/version", postNewBackupKeysVersion).Methods(http.MethodPost, http.MethodOptions)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
|
|
|
unstableMux.Handle("/room_keys/version/{version}", getBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
unstableMux.Handle("/room_keys/version", getLatestBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
unstableMux.Handle("/room_keys/version/{version}", putBackupKeysVersion).Methods(http.MethodPut)
|
|
|
|
unstableMux.Handle("/room_keys/version/{version}", deleteBackupKeysVersion).Methods(http.MethodDelete)
|
|
|
|
unstableMux.Handle("/room_keys/version", postNewBackupKeysVersion).Methods(http.MethodPost, http.MethodOptions)
|
2021-07-27 06:47:32 -05:00
|
|
|
|
2021-07-27 13:29:32 -05:00
|
|
|
// Inserting E2E Backup Keys
|
|
|
|
|
2021-07-27 11:08:53 -05:00
|
|
|
// Bulk room and session
|
2022-03-04 10:01:18 -06:00
|
|
|
putBackupKeys := httputil.MakeAuthAPI("put_backup_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-28 04:25:45 -05:00
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
if version == "" {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: 400,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
2021-07-27 11:08:53 -05:00
|
|
|
}
|
2021-07-28 04:25:45 -05:00
|
|
|
}
|
|
|
|
var reqBody keyBackupSessionRequest
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &reqBody)
|
|
|
|
if resErr != nil {
|
|
|
|
return *resErr
|
|
|
|
}
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &reqBody)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
2021-07-27 11:08:53 -05:00
|
|
|
// Single room bulk session
|
2022-03-04 10:01:18 -06:00
|
|
|
putBackupKeysRoom := httputil.MakeAuthAPI("put_backup_keys_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-28 04:25:45 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
if version == "" {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: 400,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
2021-07-27 11:08:53 -05:00
|
|
|
}
|
2021-07-28 04:25:45 -05:00
|
|
|
}
|
|
|
|
roomID := vars["roomID"]
|
|
|
|
var reqBody keyBackupSessionRequest
|
|
|
|
reqBody.Rooms = make(map[string]struct {
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
})
|
|
|
|
reqBody.Rooms[roomID] = struct {
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
}{
|
|
|
|
Sessions: map[string]userapi.KeyBackupSession{},
|
|
|
|
}
|
|
|
|
body := reqBody.Rooms[roomID]
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &body)
|
|
|
|
if resErr != nil {
|
|
|
|
return *resErr
|
|
|
|
}
|
|
|
|
reqBody.Rooms[roomID] = body
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &reqBody)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
2021-07-27 11:08:53 -05:00
|
|
|
// Single room, single session
|
2022-03-04 10:01:18 -06:00
|
|
|
putBackupKeysRoomSession := httputil.MakeAuthAPI("put_backup_keys_room_session", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-28 04:25:45 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
if version == "" {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: 400,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
2021-07-27 13:29:32 -05:00
|
|
|
}
|
2021-07-28 04:25:45 -05:00
|
|
|
}
|
|
|
|
var reqBody userapi.KeyBackupSession
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &reqBody)
|
|
|
|
if resErr != nil {
|
|
|
|
return *resErr
|
|
|
|
}
|
|
|
|
roomID := vars["roomID"]
|
|
|
|
sessionID := vars["sessionID"]
|
|
|
|
var keyReq keyBackupSessionRequest
|
|
|
|
keyReq.Rooms = make(map[string]struct {
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
})
|
|
|
|
keyReq.Rooms[roomID] = struct {
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
}{
|
|
|
|
Sessions: make(map[string]userapi.KeyBackupSession),
|
|
|
|
}
|
|
|
|
keyReq.Rooms[roomID].Sessions[sessionID] = reqBody
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &keyReq)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/room_keys/keys", putBackupKeys).Methods(http.MethodPut)
|
|
|
|
v3mux.Handle("/room_keys/keys/{roomID}", putBackupKeysRoom).Methods(http.MethodPut)
|
|
|
|
v3mux.Handle("/room_keys/keys/{roomID}/{sessionID}", putBackupKeysRoomSession).Methods(http.MethodPut)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
|
|
|
unstableMux.Handle("/room_keys/keys", putBackupKeys).Methods(http.MethodPut)
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}", putBackupKeysRoom).Methods(http.MethodPut)
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}/{sessionID}", putBackupKeysRoomSession).Methods(http.MethodPut)
|
2021-07-27 11:08:53 -05:00
|
|
|
|
2021-07-27 13:29:32 -05:00
|
|
|
// Querying E2E Backup Keys
|
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
getBackupKeys := httputil.MakeAuthAPI("get_backup_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-28 04:25:45 -05:00
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), "", "")
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
getBackupKeysRoom := httputil.MakeAuthAPI("get_backup_keys_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-28 04:25:45 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), vars["roomID"], "")
|
|
|
|
})
|
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
getBackupKeysRoomSession := httputil.MakeAuthAPI("get_backup_keys_room_session", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-28 04:25:45 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), vars["roomID"], vars["sessionID"])
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/room_keys/keys", getBackupKeys).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
v3mux.Handle("/room_keys/keys/{roomID}", getBackupKeysRoom).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
v3mux.Handle("/room_keys/keys/{roomID}/{sessionID}", getBackupKeysRoomSession).Methods(http.MethodGet, http.MethodOptions)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
|
|
|
unstableMux.Handle("/room_keys/keys", getBackupKeys).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}", getBackupKeysRoom).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}/{sessionID}", getBackupKeysRoomSession).Methods(http.MethodGet, http.MethodOptions)
|
2021-07-27 13:29:32 -05:00
|
|
|
|
|
|
|
// Deleting E2E Backup Keys
|
|
|
|
|
2021-08-04 11:56:29 -05:00
|
|
|
// Cross-signing device keys
|
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
postDeviceSigningKeys := httputil.MakeAuthAPI("post_device_signing_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return UploadCrossSigningDeviceKeys(req, userInteractiveAuth, keyAPI, device, userAPI, cfg)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)
|
2021-08-04 11:56:29 -05:00
|
|
|
|
2022-03-04 10:01:18 -06:00
|
|
|
postDeviceSigningSignatures := httputil.MakeAuthAPI("post_device_signing_signatures", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-08-04 11:56:29 -05:00
|
|
|
return UploadCrossSigningDeviceSignatures(req, keyAPI, device)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck)
|
2021-08-04 11:56:29 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/keys/device_signing/upload", postDeviceSigningKeys).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
v3mux.Handle("/keys/signatures/upload", postDeviceSigningSignatures).Methods(http.MethodPost, http.MethodOptions)
|
2021-08-04 11:56:29 -05:00
|
|
|
|
|
|
|
unstableMux.Handle("/keys/device_signing/upload", postDeviceSigningKeys).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
unstableMux.Handle("/keys/signatures/upload", postDeviceSigningSignatures).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2020-07-13 10:02:35 -05:00
|
|
|
// Supplying a device ID is deprecated.
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/keys/upload/{deviceID}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-07-15 06:02:34 -05:00
|
|
|
return UploadKeys(req, keyAPI, device)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2020-07-15 06:02:34 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/keys/upload",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-07-15 06:02:34 -05:00
|
|
|
return UploadKeys(req, keyAPI, device)
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2020-07-13 10:02:35 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/keys/query",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("keys_query", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-08-04 11:56:29 -05:00
|
|
|
return QueryKeys(req, keyAPI, device)
|
2020-07-15 12:40:41 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/keys/claim",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI("keys_claim", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-07-21 08:47:53 -05:00
|
|
|
return ClaimKeys(req, keyAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-03-04 02:59:15 -06:00
|
|
|
v3mux.Handle("/rooms/{roomId}/receipt/{receiptType}/{eventId}",
|
2022-03-04 10:01:18 -06:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-11-09 12:46:11 -06:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetReceipt(req, eduAPI, device, vars["roomId"], vars["receiptType"], vars["eventId"])
|
2022-03-04 10:01:18 -06:00
|
|
|
}, consentRequiredCheck),
|
2020-11-09 12:46:11 -06:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-02-20 09:41:29 -06:00
|
|
|
}
|