2020-07-02 16:41:18 +02:00
|
|
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
2017-04-21 00:40:52 +02: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 16:41:29 +01:00
|
|
|
package routing
|
|
|
|
|
|
|
|
import (
|
2022-02-18 16:05:03 +01:00
|
|
|
"context"
|
2017-02-20 16:41:29 +01:00
|
|
|
"net/http"
|
2017-08-18 16:33:40 +02:00
|
|
|
"strings"
|
2017-02-20 16:41:29 +01:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2022-12-22 11:54:03 +01:00
|
|
|
"github.com/matrix-org/dendrite/setup/base"
|
2022-09-27 18:06:49 +02:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
|
|
|
"github.com/matrix-org/util"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
2018-08-20 11:45:17 +02:00
|
|
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
2020-07-02 18:11:33 +02:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/api"
|
2020-07-10 01:39:44 +02:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth"
|
2020-10-09 10:15:51 +02:00
|
|
|
clientutil "github.com/matrix-org/dendrite/clientapi/httputil"
|
2017-06-27 13:37:25 +02:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
2017-03-15 14:36:26 +01:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
2021-11-24 11:45:23 +01:00
|
|
|
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
2020-06-12 15:55:57 +02:00
|
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
2020-05-21 15:40:13 +02:00
|
|
|
"github.com/matrix-org/dendrite/internal/transactions"
|
2020-07-15 13:02:34 +02:00
|
|
|
keyserverAPI "github.com/matrix-org/dendrite/keyserver/api"
|
2018-08-08 17:17:09 +02:00
|
|
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
2020-12-02 18:41:00 +01:00
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2022-04-06 13:11:19 +02:00
|
|
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
2020-07-02 16:41:18 +02:00
|
|
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
2017-02-20 16:41:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
|
|
|
|
// to clients which need to make outbound HTTP requests.
|
2019-07-03 17:38:50 +02:00
|
|
|
//
|
|
|
|
// Due to Setup being used to call many other functions, a gocyclo nolint is
|
|
|
|
// applied:
|
|
|
|
// nolint: gocyclo
|
2017-05-25 17:08:28 +02:00
|
|
|
func Setup(
|
2022-12-22 11:54:03 +01:00
|
|
|
base *base.BaseDendrite,
|
2022-04-28 17:02:30 +02:00
|
|
|
cfg *config.ClientAPI,
|
2022-05-05 14:17:38 +02:00
|
|
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
2022-05-06 13:39:26 +02:00
|
|
|
asAPI appserviceAPI.AppServiceInternalAPI,
|
2022-05-05 14:17:38 +02:00
|
|
|
userAPI userapi.ClientUserAPI,
|
2022-05-05 20:30:38 +02:00
|
|
|
userDirectoryProvider userapi.QuerySearchProfilesAPI,
|
2017-05-25 17:08:28 +02:00
|
|
|
federation *gomatrixserverlib.FederationClient,
|
2017-08-02 17:21:35 +02:00
|
|
|
syncProducer *producers.SyncAPIProducer,
|
2018-05-18 11:49:40 +02:00
|
|
|
transactionsCache *transactions.Cache,
|
2022-05-05 14:17:38 +02:00
|
|
|
federationSender federationAPI.ClientFederationAPI,
|
|
|
|
keyAPI keyserverAPI.ClientKeyAPI,
|
2020-07-03 13:59:00 +02:00
|
|
|
extRoomsProvider api.ExtraPublicRoomsProvider,
|
2022-04-06 13:11:19 +02:00
|
|
|
mscCfg *config.MSCs, natsClient *nats.Conn,
|
2017-05-25 17:08:28 +02:00
|
|
|
) {
|
2022-12-22 11:54:03 +01:00
|
|
|
publicAPIMux := base.PublicClientAPIMux
|
|
|
|
wkMux := base.PublicWellKnownAPIMux
|
|
|
|
synapseAdminRouter := base.SynapseAdminMux
|
|
|
|
dendriteAdminRouter := base.DendriteAdminMux
|
|
|
|
|
|
|
|
if base.EnableMetrics {
|
|
|
|
prometheus.MustRegister(amtRegUsers, sendEventDuration)
|
|
|
|
}
|
2022-04-08 12:24:40 +02:00
|
|
|
|
2021-11-24 13:55:44 +01:00
|
|
|
rateLimits := httputil.NewRateLimits(&cfg.RateLimiting)
|
2022-03-24 22:45:44 +01:00
|
|
|
userInteractiveAuth := auth.NewUserInteractive(userAPI, cfg)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2021-08-04 18:56:29 +02:00
|
|
|
unstableFeatures := map[string]bool{
|
2021-08-17 14:44:30 +02:00
|
|
|
"org.matrix.e2e_cross_signing": true,
|
2022-10-17 11:38:22 +02:00
|
|
|
"org.matrix.msc2285.stable": true,
|
2021-08-04 18:56:29 +02:00
|
|
|
}
|
2021-01-18 14:09:28 +01:00
|
|
|
for _, msc := range cfg.MSCs.MSCs {
|
|
|
|
unstableFeatures["org.matrix."+msc] = true
|
|
|
|
}
|
|
|
|
|
2022-07-25 11:39:57 +02:00
|
|
|
if cfg.Matrix.WellKnownClientName != "" {
|
|
|
|
logrus.Infof("Setting m.homeserver base_url as %s at /.well-known/matrix/client", cfg.Matrix.WellKnownClientName)
|
|
|
|
wkMux.Handle("/client", httputil.MakeExternalAPI("wellknown", func(r *http.Request) util.JSONResponse {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusOK,
|
|
|
|
JSON: struct {
|
|
|
|
HomeserverName struct {
|
|
|
|
BaseUrl string `json:"base_url"`
|
|
|
|
} `json:"m.homeserver"`
|
|
|
|
}{
|
|
|
|
HomeserverName: struct {
|
|
|
|
BaseUrl string `json:"base_url"`
|
|
|
|
}{
|
|
|
|
BaseUrl: cfg.Matrix.WellKnownClientName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
}
|
|
|
|
|
2020-08-13 13:16:37 +02:00
|
|
|
publicAPIMux.Handle("/versions",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse {
|
2017-06-27 13:37:25 +02:00
|
|
|
return util.JSONResponse{
|
2018-03-13 16:55:45 +01:00
|
|
|
Code: http.StatusOK,
|
2017-06-27 13:37:25 +02:00
|
|
|
JSON: struct {
|
2021-01-18 14:09:28 +01:00
|
|
|
Versions []string `json:"versions"`
|
|
|
|
UnstableFeatures map[string]bool `json:"unstable_features"`
|
|
|
|
}{Versions: []string{
|
2017-06-27 13:37:25 +02:00
|
|
|
"r0.0.1",
|
|
|
|
"r0.1.0",
|
|
|
|
"r0.2.0",
|
2018-03-14 18:36:02 +01:00
|
|
|
"r0.3.0",
|
2020-08-25 16:44:33 +02:00
|
|
|
"r0.4.0",
|
|
|
|
"r0.5.0",
|
|
|
|
"r0.6.1",
|
2022-06-01 10:39:17 +02:00
|
|
|
"v1.0",
|
|
|
|
"v1.1",
|
|
|
|
"v1.2",
|
2021-01-18 14:09:28 +01:00
|
|
|
}, UnstableFeatures: unstableFeatures},
|
2017-06-27 13:37:25 +02:00
|
|
|
}
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2021-07-09 17:52:31 +02: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 {
|
2022-08-26 10:56:41 +02:00
|
|
|
return handleSharedSecretRegistration(cfg, userAPI, sr, req)
|
2021-07-09 17:52:31 +02:00
|
|
|
}
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusMethodNotAllowed,
|
|
|
|
JSON: jsonerror.NotFound("unknown method"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
|
|
|
|
2022-04-28 17:02:30 +02:00
|
|
|
dendriteAdminRouter.Handle("/admin/evacuateRoom/{roomID}",
|
2022-08-12 13:00:07 +02:00
|
|
|
httputil.MakeAdminAPI("admin_evacuate_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return AdminEvacuateRoom(req, cfg, device, rsAPI)
|
2022-04-28 17:02:30 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-06-29 16:29:39 +02:00
|
|
|
dendriteAdminRouter.Handle("/admin/evacuateUser/{userID}",
|
2022-08-12 13:00:07 +02:00
|
|
|
httputil.MakeAdminAPI("admin_evacuate_user", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return AdminEvacuateUser(req, cfg, device, rsAPI)
|
2022-06-29 16:29:39 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-11-11 17:41:37 +01:00
|
|
|
dendriteAdminRouter.Handle("/admin/resetPassword/{userID}",
|
2022-08-12 13:00:07 +02:00
|
|
|
httputil.MakeAdminAPI("admin_reset_password", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return AdminResetPassword(req, cfg, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-10-31 10:13:28 +01:00
|
|
|
dendriteAdminRouter.Handle("/admin/downloadState/{serverName}/{roomID}",
|
|
|
|
httputil.MakeAdminAPI("admin_download_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return AdminDownloadState(req, cfg, device, rsAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-09-27 18:06:49 +02:00
|
|
|
dendriteAdminRouter.Handle("/admin/fulltext/reindex",
|
2022-09-30 10:32:31 +02:00
|
|
|
httputil.MakeAdminAPI("admin_fultext_reindex", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-09-27 18:06:49 +02:00
|
|
|
return AdminReindex(req, cfg, device, natsClient)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-09-30 10:32:31 +02:00
|
|
|
dendriteAdminRouter.Handle("/admin/refreshDevices/{userID}",
|
|
|
|
httputil.MakeAdminAPI("admin_refresh_devices", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return AdminMarkAsStale(req, cfg, keyAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-18 16:05:03 +01:00
|
|
|
// server notifications
|
|
|
|
if cfg.Matrix.ServerNotices.Enabled {
|
|
|
|
logrus.Info("Enabling server notices at /_synapse/admin/v1/send_server_notice")
|
2022-10-21 10:48:25 +02:00
|
|
|
serverNotificationSender, err := getSenderDevice(context.Background(), rsAPI, userAPI, cfg)
|
2022-02-18 16:05:03 +01: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}",
|
|
|
|
httputil.MakeAuthAPI("send_server_notice", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
// not specced, but ensure we're rate limiting requests to this endpoint
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2022-02-18 16:05:03 +01:00
|
|
|
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 22:45:44 +01:00
|
|
|
cfg, userAPI, rsAPI, asAPI,
|
2022-02-18 16:05:03 +01:00
|
|
|
device, serverNotificationSender,
|
|
|
|
&txnID, transactionsCache,
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
synapseAdminRouter.Handle("/admin/v1/send_server_notice",
|
|
|
|
httputil.MakeAuthAPI("send_server_notice", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
// not specced, but ensure we're rate limiting requests to this endpoint
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2022-02-18 16:05:03 +01:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return SendServerNotice(
|
|
|
|
req, &cfg.Matrix.ServerNotices,
|
2022-03-24 22:45:44 +01:00
|
|
|
cfg, userAPI, rsAPI, asAPI,
|
2022-02-18 16:05:03 +01:00
|
|
|
device, serverNotificationSender,
|
|
|
|
nil, transactionsCache,
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
|
|
|
|
2022-02-17 18:38:22 +01: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()
|
|
|
|
|
2020-08-13 13:16:37 +02:00
|
|
|
unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter()
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/createRoom",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("createRoom", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 22:45:44 +01:00
|
|
|
return CreateRoom(req, device, cfg, userAPI, rsAPI, asAPI)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/join/{roomIDOrAlias}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 19:16:53 +02:00
|
|
|
return JoinRoomByIDOrAlias(
|
2022-03-24 22:45:44 +01:00
|
|
|
req, device, rsAPI, userAPI, vars["roomIDOrAlias"],
|
2017-05-25 17:08:28 +02:00
|
|
|
)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2021-01-22 17:08:47 +01:00
|
|
|
|
|
|
|
if mscCfg.Enabled("msc2753") {
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/peek/{roomIDOrAlias}",
|
2021-01-22 17:08:47 +01:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Peek, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2021-01-22 17:08:47 +01:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return PeekRoomByIDOrAlias(
|
2022-03-24 22:45:44 +01:00
|
|
|
req, device, rsAPI, vars["roomIDOrAlias"],
|
2021-01-22 17:08:47 +01:00
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/joined_rooms",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("joined_rooms", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-09-04 16:58:30 +02:00
|
|
|
return GetJoinedRooms(req, device, rsAPI)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-03-19 11:25:36 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/join",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-24 19:19:54 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return JoinRoomByIDOrAlias(
|
2022-03-24 22:45:44 +01:00
|
|
|
req, device, rsAPI, userAPI, vars["roomID"],
|
2020-06-24 19:19:54 +02:00
|
|
|
)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-06-24 19:19:54 +02:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/leave",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-05-04 19:34:09 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return LeaveRoomByID(
|
|
|
|
req, device, rsAPI, vars["roomID"],
|
|
|
|
)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-05-04 19:34:09 +02:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/unpeek",
|
2020-12-03 12:11:46 +01:00
|
|
|
httputil.MakeAuthAPI("unpeek", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return UnpeekRoomByID(
|
2022-03-24 22:45:44 +01:00
|
|
|
req, device, rsAPI, vars["roomID"],
|
2020-12-03 12:11:46 +01:00
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/ban",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-24 19:19:54 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return SendBan(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2020-06-24 19:19:54 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/invite",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-24 19:19:54 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return SendInvite(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2020-06-24 19:19:54 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/kick",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-24 19:19:54 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return SendKick(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2020-06-24 19:19:54 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/unban",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return SendUnban(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2017-08-04 17:32:10 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/send/{eventType}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-10 13:17:54 +02:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, nil, cfg, rsAPI, nil)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-09-26 13:55:48 +02:00
|
|
|
txnID := vars["txnID"]
|
2018-05-18 11:49:40 +02:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], &txnID,
|
2020-06-10 13:17:54 +02:00
|
|
|
nil, cfg, rsAPI, transactionsCache)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2020-04-14 19:36:08 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 19:36:08 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-08-25 19:43:56 +02:00
|
|
|
return OnIncomingStateRequest(req.Context(), device, rsAPI, vars["roomID"])
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests())).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 19:36:08 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/aliases", httputil.MakeAuthAPI("aliases", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-21 17:53:50 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetAliases(req, rsAPI, device, vars["roomID"])
|
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{type:[^/]+/?}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 19:36:08 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-24 10:59:59 +02:00
|
|
|
// If there's a trailing slash, remove it
|
2021-08-17 11:39:09 +02:00
|
|
|
eventType := strings.TrimSuffix(vars["type"], "/")
|
2020-06-17 17:21:42 +02:00
|
|
|
eventFormat := req.URL.Query().Get("format") == "event"
|
2020-07-28 11:09:10 +02:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), device, rsAPI, vars["roomID"], eventType, "", eventFormat)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests())).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 19:36:08 +02:00
|
|
|
|
2022-02-17 18:38:22 +01: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 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 19:36:08 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-17 17:21:42 +02:00
|
|
|
eventFormat := req.URL.Query().Get("format") == "event"
|
2020-07-28 11:09:10 +02:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), device, rsAPI, vars["roomID"], vars["type"], vars["stateKey"], eventFormat)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests())).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 19:36:08 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 12:21:52 +01:00
|
|
|
emptyString := ""
|
2021-08-17 11:39:09 +02:00
|
|
|
eventType := strings.TrimSuffix(vars["eventType"], "/")
|
2020-06-10 13:17:54 +02:00
|
|
|
return SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, rsAPI, nil)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2020-04-14 19:36:08 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 12:21:52 +01:00
|
|
|
stateKey := vars["stateKey"]
|
2020-06-10 13:17:54 +02:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, &stateKey, cfg, rsAPI, nil)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-02-20 16:41:29 +01:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/register", httputil.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, nil); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return Register(req, userAPI, cfg)
|
2018-03-13 16:55:45 +01:00
|
|
|
})).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-22 17:13:19 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/register/available", httputil.MakeExternalAPI("registerAvailable", func(req *http.Request) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, nil); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return RegisterAvailable(req, cfg, userAPI)
|
2018-03-13 16:55:45 +01:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-09 16:24:38 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("directory_room", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return DirectoryRoom(req, vars["roomAlias"], federation, cfg, rsAPI, federationSender)
|
2017-06-27 13:37:25 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-28 12:31:43 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return SetLocalAlias(req, device, vars["roomAlias"], cfg, rsAPI)
|
2017-07-28 12:31:43 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-28 12:31:43 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return RemoveLocalAlias(req, device, vars["roomAlias"], rsAPI)
|
2017-07-28 12:31:43 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/directory/list/room/{roomID}",
|
2020-07-02 16:41:18 +02: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)
|
2022-10-27 14:40:35 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/directory/list/room/{roomID}",
|
2020-07-02 16:41:18 +02:00
|
|
|
httputil.MakeAuthAPI("directory_list", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-09-07 15:47:59 +02:00
|
|
|
return SetVisibility(req, rsAPI, device, vars["roomID"])
|
2020-07-02 16:41:18 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2022-10-27 14:40:35 +02:00
|
|
|
v3mux.Handle("/directory/list/appservice/{networkID}/{roomID}",
|
|
|
|
httputil.MakeAuthAPI("directory_list", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return SetVisibilityAS(req, rsAPI, device, vars["networkID"], vars["roomID"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
// Undocumented endpoint
|
|
|
|
v3mux.Handle("/directory/list/appservice/{networkID}/{roomID}",
|
|
|
|
httputil.MakeAuthAPI("directory_list", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return SetVisibilityAS(req, rsAPI, device, vars["networkID"], vars["roomID"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/publicRooms",
|
2020-07-02 16:41:18 +02:00
|
|
|
httputil.MakeExternalAPI("public_rooms", func(req *http.Request) util.JSONResponse {
|
2020-09-07 13:38:09 +02:00
|
|
|
return GetPostPublicRooms(req, rsAPI, extRoomsProvider, federation, cfg)
|
2020-07-02 16:41:18 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/logout",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("logout", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 19:53:40 +02:00
|
|
|
return Logout(req, userAPI, device)
|
2017-07-11 17:04:34 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-07-11 17:04:34 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/logout/all",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("logout", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 19:53:40 +02:00
|
|
|
return LogoutAll(req, userAPI, device)
|
2017-10-15 12:29:47 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-10-15 12:29:47 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/typing/{userID}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("rooms_typing", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-29 14:14:35 +02:00
|
|
|
return SendTyping(req, device, vars["roomID"], vars["userID"], rsAPI, syncProducer)
|
2018-07-24 16:49:49 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/redact/{eventID}",
|
2020-07-03 18:24:51 +02:00
|
|
|
httputil.MakeAuthAPI("rooms_redact", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-04-26 10:28:41 +02:00
|
|
|
return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, nil, nil)
|
2020-07-03 18:24:51 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/redact/{eventID}/{txnId}",
|
2020-08-25 11:39:30 +02:00
|
|
|
httputil.MakeAuthAPI("rooms_redact", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-04-26 10:28:41 +02:00
|
|
|
txnID := vars["txnId"]
|
|
|
|
return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, &txnID, transactionsCache)
|
2020-08-25 11:39:30 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2018-07-24 16:49:49 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/sendToDevice/{eventType}/{txnID}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
2022-03-29 14:14:35 +02:00
|
|
|
return SendToDevice(req, device, syncProducer, transactionsCache, vars["eventType"], &txnID)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
// This is only here because sytest refers to /unstable for this endpoint
|
|
|
|
// rather than r0. It's an exact duplicate of the above handler.
|
|
|
|
// TODO: Remove this if/when sytest is fixed!
|
|
|
|
unstableMux.Handle("/sendToDevice/{eventType}/{txnID}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
2022-03-29 14:14:35 +02:00
|
|
|
return SendToDevice(req, device, syncProducer, transactionsCache, vars["eventType"], &txnID)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 18:50:19 +02:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/account/whoami",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("whoami", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2018-08-04 11:32:02 +02:00
|
|
|
return Whoami(req, device)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-08-04 11:32:02 +02:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/account/password",
|
2020-09-04 16:16:13 +02:00
|
|
|
httputil.MakeAuthAPI("password", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-04 16:16:13 +02:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return Password(req, userAPI, device, cfg)
|
2020-09-04 16:16:13 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/account/deactivate",
|
2020-10-02 18:18:20 +02:00
|
|
|
httputil.MakeAuthAPI("deactivate", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-10-02 18:18:20 +02:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return Deactivate(req, userInteractiveAuth, userAPI, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2021-04-07 14:26:20 +02:00
|
|
|
// Stub endpoints required by Element
|
2017-04-20 18:11:53 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/login",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("login", func(req *http.Request) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, nil); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return Login(req, userAPI, cfg)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
2017-04-20 18:11:53 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/auth/{authType}/fallback/web",
|
2022-12-22 11:54:03 +01:00
|
|
|
httputil.MakeHTMLAPI("auth_fallback", base.EnableMetrics, func(w http.ResponseWriter, req *http.Request) *util.JSONResponse {
|
2019-08-14 19:34:49 +02:00
|
|
|
vars := mux.Vars(req)
|
|
|
|
return AuthFallback(w, req, vars["authType"], cfg)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-03-03 12:40:53 +01:00
|
|
|
// Push rules
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("missing trailing slash"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/pushrules/",
|
2022-03-03 12:40:53 +01:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return GetAllPushRules(req.Context(), device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2017-04-20 18:11:53 +02:00
|
|
|
return util.JSONResponse{
|
2022-03-03 12:40:53 +01:00
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("scope, kind and rule ID must be specified"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
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}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("missing trailing slash after scope"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope:[^/]+/?}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("kind and rule ID must be specified"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
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}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("missing trailing slash after kind"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind:[^/]+/?}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("rule ID must be specified"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
2017-04-20 18:11:53 +02:00
|
|
|
}
|
2022-03-03 12:40:53 +01:00
|
|
|
return GetPushRuleByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], device, userAPI)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 18:11:53 +02:00
|
|
|
|
2022-03-03 12:40:53 +01:00
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2022-03-03 12:40:53 +01:00
|
|
|
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}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
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}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
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}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
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 14:26:20 +02:00
|
|
|
// Element user settings
|
2017-04-20 18:11:53 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/profile/{userID}",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("profile", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return GetProfile(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 18:11:53 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/profile/{userID}/avatar_url",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("profile_avatar_url", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return GetAvatarURL(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 15:52:41 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 15:52:41 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/profile/{userID}/avatar_url",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("profile_avatar_url", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return SetAvatarURL(req, userAPI, device, vars["userID"], cfg, rsAPI)
|
2017-07-10 15:52:41 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 15:52:41 +02:00
|
|
|
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows
|
|
|
|
// PUT requests, so we need to allow this method
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/profile/{userID}/displayname",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("profile_displayname", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return GetDisplayName(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 15:52:41 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 15:52:41 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/profile/{userID}/displayname",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("profile_displayname", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 22:45:44 +01:00
|
|
|
return SetDisplayName(req, userAPI, device, vars["userID"], cfg, rsAPI)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 15:52:41 +02:00
|
|
|
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows
|
|
|
|
// PUT requests, so we need to allow this method
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/account/3pid",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 22:45:44 +01:00
|
|
|
return GetAssociated3PIDs(req, userAPI, device)
|
2017-05-18 14:47:23 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-01 11:13:10 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/account/3pid",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 22:45:44 +01:00
|
|
|
return CheckAndSave3PIDAssociation(req, userAPI, device, cfg)
|
2017-09-01 11:13:10 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 11:13:10 +02:00
|
|
|
|
|
|
|
unstableMux.Handle("/account/3pid/delete",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 22:45:44 +01:00
|
|
|
return Forget3PID(req, userAPI)
|
2017-09-01 11:13:10 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 11:13:10 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/{path:(?:account/3pid|register)}/email/requestToken",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("account_3pid_request_token", func(req *http.Request) util.JSONResponse {
|
2022-03-24 22:45:44 +01:00
|
|
|
return RequestEmailToken(req, userAPI, cfg)
|
2017-09-01 11:13:10 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-04-20 18:11:53 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/voip/turnServer",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("turn_server", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2017-11-09 10:58:45 +01:00
|
|
|
return RequestTurnServer(req, device, cfg)
|
2017-06-27 13:37:25 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/thirdparty/protocols",
|
2022-11-02 11:17:53 +01:00
|
|
|
httputil.MakeAuthAPI("thirdparty_protocols", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return Protocols(req, asAPI, device, "")
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2022-11-02 11:17:53 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/thirdparty/protocol/{protocolID}",
|
|
|
|
httputil.MakeAuthAPI("thirdparty_protocols", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return Protocols(req, asAPI, device, vars["protocolID"])
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2022-11-02 11:17:53 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/thirdparty/user/{protocolID}",
|
|
|
|
httputil.MakeAuthAPI("thirdparty_user", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return User(req, asAPI, device, vars["protocolID"], req.URL.Query())
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2022-11-02 11:17:53 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/thirdparty/user",
|
|
|
|
httputil.MakeAuthAPI("thirdparty_user", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return User(req, asAPI, device, "", req.URL.Query())
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2022-11-02 11:17:53 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/thirdparty/location/{protocolID}",
|
|
|
|
httputil.MakeAuthAPI("thirdparty_location", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
2017-06-27 13:37:25 +02:00
|
|
|
}
|
2022-11-02 11:17:53 +01:00
|
|
|
return Location(req, asAPI, device, vars["protocolID"], req.URL.Query())
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2022-11-02 11:17:53 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/thirdparty/location",
|
|
|
|
httputil.MakeAuthAPI("thirdparty_location", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return Location(req, asAPI, device, "", req.URL.Query())
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/initialSync",
|
2020-06-12 15:55:57 +02:00
|
|
|
httputil.MakeExternalAPI("rooms_initial_sync", func(req *http.Request) util.JSONResponse {
|
2017-06-27 13:37:25 +02:00
|
|
|
// TODO: Allow people to peek into rooms.
|
|
|
|
return util.JSONResponse{
|
2018-03-13 16:55:45 +01:00
|
|
|
Code: http.StatusForbidden,
|
2017-06-27 13:37:25 +02:00
|
|
|
JSON: jsonerror.GuestAccessForbidden("Guest access not implemented"),
|
|
|
|
}
|
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/user/{userID}/account_data/{type}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 19:36:03 +02:00
|
|
|
return SaveAccountData(req, userAPI, device, vars["userID"], "", vars["type"], syncProducer)
|
2017-07-26 15:53:11 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-26 15:53:11 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 19:36:03 +02:00
|
|
|
return SaveAccountData(req, userAPI, device, vars["userID"], vars["roomID"], vars["type"], syncProducer)
|
2017-06-27 13:37:25 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/user/{userID}/account_data/{type}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-01-29 18:53:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 19:36:03 +02:00
|
|
|
return GetAccountData(req, userAPI, device, vars["userID"], "", vars["type"])
|
2020-01-29 18:53:05 +01:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-01-29 18:53:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 19:36:03 +02:00
|
|
|
return GetAccountData(req, userAPI, device, vars["userID"], vars["roomID"], vars["type"])
|
2020-01-29 18:53:05 +01:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/admin/whois/{userID}",
|
2020-11-17 11:07:03 +01:00
|
|
|
httputil.MakeAuthAPI("admin_whois", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetAdminWhois(req, userAPI, device, vars["userID"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/user/{userID}/openid/request_token",
|
2021-04-07 14:26:20 +02:00
|
|
|
httputil.MakeAuthAPI("openid_request_token", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2021-04-07 14:26:20 +02: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)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/user_directory/search",
|
2020-07-28 11:53:17 +02:00
|
|
|
httputil.MakeAuthAPI("userdirectory_search", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2020-07-28 11:53:17 +02:00
|
|
|
postContent := struct {
|
|
|
|
SearchString string `json:"search_term"`
|
|
|
|
Limit int `json:"limit"`
|
|
|
|
}{}
|
2020-10-09 10:15:51 +02:00
|
|
|
|
|
|
|
if resErr := clientutil.UnmarshalJSONRequest(req, &postContent); resErr != nil {
|
|
|
|
return *resErr
|
2020-07-28 11:53:17 +02:00
|
|
|
}
|
2022-05-05 14:17:38 +02:00
|
|
|
return SearchUserDirectory(
|
2020-07-28 11:53:17 +02:00
|
|
|
req.Context(),
|
|
|
|
device,
|
2020-09-04 12:46:01 +02:00
|
|
|
rsAPI,
|
2022-03-28 17:25:26 +02:00
|
|
|
userDirectoryProvider,
|
2020-07-28 11:53:17 +02:00
|
|
|
postContent.SearchString,
|
|
|
|
postContent.Limit,
|
2022-08-12 13:33:31 +02:00
|
|
|
federation,
|
|
|
|
cfg.Matrix.ServerName,
|
2020-07-28 11:53:17 +02:00
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/read_markers",
|
2020-10-09 10:15:35 +02:00
|
|
|
httputil.MakeAuthAPI("rooms_read_markers", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2020-10-09 10:15:35 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-29 14:14:35 +02:00
|
|
|
return SaveReadMarker(req, userAPI, rsAPI, syncProducer, device, vars["roomID"])
|
2017-06-27 13:37:25 +02:00
|
|
|
}),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-06-27 13:37:25 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomID}/forget",
|
2020-11-05 11:19:23 +01:00
|
|
|
httputil.MakeAuthAPI("rooms_forget", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-11-05 11:19:23 +01:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return SendForget(req, device, vars["roomID"], rsAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-04-05 11:04:08 +02:00
|
|
|
v3mux.Handle("/rooms/{roomID}/upgrade",
|
|
|
|
httputil.MakeAuthAPI("rooms_upgrade", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return UpgradeRoom(req, device, cfg, vars["roomID"], userAPI, rsAPI, asAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/devices",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("get_devices", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 19:53:40 +02:00
|
|
|
return GetDevicesByLocalpart(req, userAPI, device)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 20:12:54 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("get_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-08-27 19:53:40 +02:00
|
|
|
return GetDeviceByID(req, userAPI, device, vars["deviceID"])
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 20:12:54 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("device_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 17:38:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-07-31 15:40:45 +02:00
|
|
|
return UpdateDeviceByID(req, userAPI, device, vars["deviceID"])
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-11-14 10:59:02 +01:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("delete_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-02-11 13:13:38 +01:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-07-30 19:00:56 +02:00
|
|
|
return DeleteDeviceById(req, userInteractiveAuth, userAPI, device, vars["deviceID"])
|
2020-02-11 13:13:38 +01:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/delete_devices",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("delete_devices", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-07-30 19:00:56 +02:00
|
|
|
return DeleteDevices(req, userAPI, device)
|
2020-02-11 13:13:38 +01:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-03-03 12:40:53 +01:00
|
|
|
v3mux.Handle("/notifications",
|
|
|
|
httputil.MakeAuthAPI("get_notifications", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return GetNotifications(req, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushers",
|
|
|
|
httputil.MakeAuthAPI("get_pushers", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return GetPushers(req, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushers/set",
|
|
|
|
httputil.MakeAuthAPI("set_pushers", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2022-03-03 12:40:53 +01:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return SetPusher(req, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2017-09-22 18:28:29 +02:00
|
|
|
// Stub implementations for sytest
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/events",
|
2022-11-11 10:52:08 +01:00
|
|
|
httputil.MakeAuthAPI("events", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2018-03-13 16:55:45 +01:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 18:28:29 +02:00
|
|
|
"chunk": []interface{}{},
|
|
|
|
"start": "",
|
|
|
|
"end": "",
|
|
|
|
}}
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-22 18:28:29 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/initialSync",
|
2022-11-11 10:52:08 +01:00
|
|
|
httputil.MakeAuthAPI("initial_sync", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2018-03-13 16:55:45 +01:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 18:28:29 +02:00
|
|
|
"end": "",
|
|
|
|
}}
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 16:55:45 +01:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2019-08-02 13:17:51 +02:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("get_tags", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 13:17:51 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 19:36:03 +02:00
|
|
|
return GetTags(req, userAPI, device, vars["userId"], vars["roomId"], syncProducer)
|
2019-08-02 13:17:51 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("put_tag", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 13:17:51 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 19:36:03 +02:00
|
|
|
return PutTag(req, userAPI, device, vars["userId"], vars["roomId"], vars["tag"], syncProducer)
|
2019-08-02 13:17:51 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("delete_tag", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 15:55:57 +02:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 13:17:51 +02:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 19:36:03 +02:00
|
|
|
return DeleteTag(req, userAPI, device, vars["userId"], vars["roomId"], vars["tag"], syncProducer)
|
2019-08-02 13:17:51 +02:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
2020-02-05 19:06:39 +01:00
|
|
|
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/capabilities",
|
2020-07-02 18:11:33 +02:00
|
|
|
httputil.MakeAuthAPI("capabilities", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 11:12:11 +02:00
|
|
|
return *r
|
|
|
|
}
|
2020-05-01 11:48:17 +02:00
|
|
|
return GetCapabilities(req, rsAPI)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-09-27 23:23:42 +02:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2020-07-13 17:02:35 +02:00
|
|
|
|
2021-07-27 20:29:32 +02:00
|
|
|
// Key Backup Versions (Metadata)
|
|
|
|
|
2021-07-28 11:25:45 +02:00
|
|
|
getBackupKeysVersion := httputil.MakeAuthAPI("get_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return KeyBackupVersion(req, userAPI, device, vars["version"])
|
|
|
|
})
|
|
|
|
|
|
|
|
getLatestBackupKeysVersion := httputil.MakeAuthAPI("get_latest_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return KeyBackupVersion(req, userAPI, device, "")
|
|
|
|
})
|
|
|
|
|
|
|
|
putBackupKeysVersion := httputil.MakeAuthAPI("put_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return ModifyKeyBackupVersionAuthData(req, userAPI, device, vars["version"])
|
|
|
|
})
|
|
|
|
|
|
|
|
deleteBackupKeysVersion := httputil.MakeAuthAPI("delete_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return DeleteKeyBackupVersion(req, userAPI, device, vars["version"])
|
|
|
|
})
|
|
|
|
|
|
|
|
postNewBackupKeysVersion := httputil.MakeAuthAPI("post_new_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return CreateKeyBackupVersion(req, userAPI, device)
|
|
|
|
})
|
|
|
|
|
2022-02-17 18:38:22 +01: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 11:25:45 +02: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 13:47:32 +02:00
|
|
|
|
2021-07-27 20:29:32 +02:00
|
|
|
// Inserting E2E Backup Keys
|
|
|
|
|
2021-07-27 18:08:53 +02:00
|
|
|
// Bulk room and session
|
2021-07-28 11:25:45 +02:00
|
|
|
putBackupKeys := httputil.MakeAuthAPI("put_backup_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
if version == "" {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: 400,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
2021-07-27 18:08:53 +02:00
|
|
|
}
|
2021-07-28 11:25:45 +02:00
|
|
|
}
|
|
|
|
var reqBody keyBackupSessionRequest
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &reqBody)
|
|
|
|
if resErr != nil {
|
|
|
|
return *resErr
|
|
|
|
}
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &reqBody)
|
|
|
|
})
|
|
|
|
|
2021-07-27 18:08:53 +02:00
|
|
|
// Single room bulk session
|
2021-07-28 11:25:45 +02:00
|
|
|
putBackupKeysRoom := httputil.MakeAuthAPI("put_backup_keys_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
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 18:08:53 +02:00
|
|
|
}
|
2021-07-28 11:25:45 +02: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)
|
|
|
|
})
|
|
|
|
|
2021-07-27 18:08:53 +02:00
|
|
|
// Single room, single session
|
2021-07-28 11:25:45 +02:00
|
|
|
putBackupKeysRoomSession := httputil.MakeAuthAPI("put_backup_keys_room_session", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
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 20:29:32 +02:00
|
|
|
}
|
2021-07-28 11:25:45 +02: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-02-17 18:38:22 +01: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 11:25:45 +02: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 18:08:53 +02:00
|
|
|
|
2021-07-27 20:29:32 +02:00
|
|
|
// Querying E2E Backup Keys
|
|
|
|
|
2021-07-28 11:25:45 +02:00
|
|
|
getBackupKeys := httputil.MakeAuthAPI("get_backup_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), "", "")
|
|
|
|
})
|
|
|
|
|
|
|
|
getBackupKeysRoom := httputil.MakeAuthAPI("get_backup_keys_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
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"], "")
|
|
|
|
})
|
|
|
|
|
|
|
|
getBackupKeysRoomSession := httputil.MakeAuthAPI("get_backup_keys_room_session", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
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-02-17 18:38:22 +01: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 11:25:45 +02: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 20:29:32 +02:00
|
|
|
|
|
|
|
// Deleting E2E Backup Keys
|
|
|
|
|
2021-08-04 18:56:29 +02:00
|
|
|
// Cross-signing device keys
|
|
|
|
|
|
|
|
postDeviceSigningKeys := httputil.MakeAuthAPI("post_device_signing_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 22:45:44 +01:00
|
|
|
return UploadCrossSigningDeviceKeys(req, userInteractiveAuth, keyAPI, device, userAPI, cfg)
|
2021-08-04 18:56:29 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
postDeviceSigningSignatures := httputil.MakeAuthAPI("post_device_signing_signatures", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return UploadCrossSigningDeviceSignatures(req, keyAPI, device)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests())
|
2021-08-04 18:56:29 +02:00
|
|
|
|
2022-02-17 18:38:22 +01: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 18:56:29 +02: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 17:02:35 +02:00
|
|
|
// Supplying a device ID is deprecated.
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/keys/upload/{deviceID}",
|
2020-07-13 17:02:35 +02:00
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-07-15 13:02:34 +02:00
|
|
|
return UploadKeys(req, keyAPI, device)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-07-15 13:02:34 +02:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/keys/upload",
|
2020-07-15 13:02:34 +02:00
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return UploadKeys(req, keyAPI, device)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-07-13 17:02:35 +02:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/keys/query",
|
2020-07-15 19:40:41 +02:00
|
|
|
httputil.MakeAuthAPI("keys_query", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-08-04 18:56:29 +02:00
|
|
|
return QueryKeys(req, keyAPI, device)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-07-15 19:40:41 +02:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/keys/claim",
|
2020-07-21 15:47:53 +02:00
|
|
|
httputil.MakeAuthAPI("keys_claim", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return ClaimKeys(req, keyAPI)
|
2022-11-11 10:52:08 +01:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-07-21 15:47:53 +02:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 18:38:22 +01:00
|
|
|
v3mux.Handle("/rooms/{roomId}/receipt/{receiptType}/{eventId}",
|
2020-11-09 19:46:11 +01:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 15:24:04 +02:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-11-09 19:46:11 +01:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
|
2022-10-11 13:27:21 +02:00
|
|
|
return SetReceipt(req, userAPI, syncProducer, device, vars["roomId"], vars["receiptType"], vars["eventId"])
|
2020-11-09 19:46:11 +01:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-04-06 13:11:19 +02:00
|
|
|
v3mux.Handle("/presence/{userId}/status",
|
|
|
|
httputil.MakeAuthAPI("set_presence", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return SetPresence(req, cfg, device, syncProducer, vars["userId"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
v3mux.Handle("/presence/{userId}/status",
|
|
|
|
httputil.MakeAuthAPI("get_presence", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetPresence(req, device, natsClient, cfg.Matrix.JetStream.Prefixed(jetstream.RequestPresence), vars["userId"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-02-20 16:41:29 +01:00
|
|
|
}
|