2020-07-02 14:41:18 +00:00
|
|
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
2017-04-20 22:40:52 +00: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 15:41:29 +00:00
|
|
|
package routing
|
|
|
|
|
|
|
|
import (
|
2022-02-18 15:05:03 +00:00
|
|
|
"context"
|
2017-02-20 15:41:29 +00:00
|
|
|
"net/http"
|
2017-08-18 14:33:40 +00:00
|
|
|
"strings"
|
2017-02-20 15:41:29 +00:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2023-04-03 19:42:46 +00:00
|
|
|
"github.com/matrix-org/dendrite/setup/base"
|
2023-02-20 13:58:03 +00:00
|
|
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
2023-04-06 08:55:01 +00:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
2023-04-19 14:50:33 +00:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
2022-09-27 16:06:49 +00:00
|
|
|
"github.com/matrix-org/util"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
2018-08-20 09:45:17 +00:00
|
|
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
2020-07-02 16:11:33 +00:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/api"
|
2020-07-09 23:39:44 +00:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth"
|
2020-10-09 08:15:51 +00:00
|
|
|
clientutil "github.com/matrix-org/dendrite/clientapi/httputil"
|
2017-03-15 13:36:26 +00:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
2021-11-24 10:45:23 +00:00
|
|
|
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
2020-06-12 13:55:57 +00:00
|
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
2020-05-21 13:40:13 +00:00
|
|
|
"github.com/matrix-org/dendrite/internal/transactions"
|
2018-08-08 15:17:09 +00:00
|
|
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
2020-12-02 17:41:00 +00:00
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2022-04-06 11:11:19 +00:00
|
|
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
2017-02-20 15:41:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
|
|
|
|
// to clients which need to make outbound HTTP requests.
|
2019-07-03 15:38:50 +00:00
|
|
|
//
|
|
|
|
// Due to Setup being used to call many other functions, a gocyclo nolint is
|
|
|
|
// applied:
|
|
|
|
// nolint: gocyclo
|
2017-05-25 15:08:28 +00:00
|
|
|
func Setup(
|
2023-03-22 08:21:32 +00:00
|
|
|
routers httputil.Routers,
|
|
|
|
dendriteCfg *config.Dendrite,
|
2022-05-05 12:17:38 +00:00
|
|
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
2022-05-06 11:39:26 +00:00
|
|
|
asAPI appserviceAPI.AppServiceInternalAPI,
|
2022-05-05 12:17:38 +00:00
|
|
|
userAPI userapi.ClientUserAPI,
|
2022-05-05 18:30:38 +00:00
|
|
|
userDirectoryProvider userapi.QuerySearchProfilesAPI,
|
2023-04-24 16:23:25 +00:00
|
|
|
federation fclient.FederationClient,
|
2017-08-02 15:21:35 +00:00
|
|
|
syncProducer *producers.SyncAPIProducer,
|
2018-05-18 09:49:40 +00:00
|
|
|
transactionsCache *transactions.Cache,
|
2022-05-05 12:17:38 +00:00
|
|
|
federationSender federationAPI.ClientFederationAPI,
|
2020-07-03 11:59:00 +00:00
|
|
|
extRoomsProvider api.ExtraPublicRoomsProvider,
|
2023-03-22 08:21:32 +00:00
|
|
|
natsClient *nats.Conn, enableMetrics bool,
|
2017-05-25 15:08:28 +00:00
|
|
|
) {
|
2023-03-22 08:21:32 +00:00
|
|
|
cfg := &dendriteCfg.ClientAPI
|
|
|
|
mscCfg := &dendriteCfg.MSCs
|
|
|
|
publicAPIMux := routers.Client
|
|
|
|
wkMux := routers.WellKnown
|
|
|
|
synapseAdminRouter := routers.SynapseAdmin
|
|
|
|
dendriteAdminRouter := routers.DendriteAdmin
|
|
|
|
|
|
|
|
if enableMetrics {
|
2022-12-22 10:54:03 +00:00
|
|
|
prometheus.MustRegister(amtRegUsers, sendEventDuration)
|
|
|
|
}
|
2022-04-08 10:24:40 +00:00
|
|
|
|
2021-11-24 12:55:44 +00:00
|
|
|
rateLimits := httputil.NewRateLimits(&cfg.RateLimiting)
|
2022-03-24 21:45:44 +00:00
|
|
|
userInteractiveAuth := auth.NewUserInteractive(userAPI, cfg)
|
2017-06-27 11:37:25 +00:00
|
|
|
|
2021-08-04 16:56:29 +00:00
|
|
|
unstableFeatures := map[string]bool{
|
2021-08-17 12:44:30 +00:00
|
|
|
"org.matrix.e2e_cross_signing": true,
|
2022-10-17 09:38:22 +00:00
|
|
|
"org.matrix.msc2285.stable": true,
|
2021-08-04 16:56:29 +00:00
|
|
|
}
|
2021-01-18 13:09:28 +00:00
|
|
|
for _, msc := range cfg.MSCs.MSCs {
|
|
|
|
unstableFeatures["org.matrix."+msc] = true
|
|
|
|
}
|
|
|
|
|
2022-07-25 09:39:57 +00: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 11:16:37 +00:00
|
|
|
publicAPIMux.Handle("/versions",
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse {
|
2017-06-27 11:37:25 +00:00
|
|
|
return util.JSONResponse{
|
2018-03-13 15:55:45 +00:00
|
|
|
Code: http.StatusOK,
|
2017-06-27 11:37:25 +00:00
|
|
|
JSON: struct {
|
2021-01-18 13:09:28 +00:00
|
|
|
Versions []string `json:"versions"`
|
|
|
|
UnstableFeatures map[string]bool `json:"unstable_features"`
|
|
|
|
}{Versions: []string{
|
2017-06-27 11:37:25 +00:00
|
|
|
"r0.0.1",
|
|
|
|
"r0.1.0",
|
|
|
|
"r0.2.0",
|
2018-03-14 17:36:02 +00:00
|
|
|
"r0.3.0",
|
2020-08-25 14:44:33 +00:00
|
|
|
"r0.4.0",
|
|
|
|
"r0.5.0",
|
|
|
|
"r0.6.1",
|
2022-06-01 08:39:17 +00:00
|
|
|
"v1.0",
|
|
|
|
"v1.1",
|
|
|
|
"v1.2",
|
2021-01-18 13:09:28 +00:00
|
|
|
}, UnstableFeatures: unstableFeatures},
|
2017-06-27 11:37:25 +00:00
|
|
|
}
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 11:37:25 +00:00
|
|
|
|
2021-07-09 15:52:31 +00: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 08:56:41 +00:00
|
|
|
return handleSharedSecretRegistration(cfg, userAPI, sr, req)
|
2021-07-09 15:52:31 +00:00
|
|
|
}
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusMethodNotAllowed,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.NotFound("unknown method"),
|
2021-07-09 15:52:31 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
|
|
|
|
2022-04-28 15:02:30 +00:00
|
|
|
dendriteAdminRouter.Handle("/admin/evacuateRoom/{roomID}",
|
2022-08-12 11:00:07 +00:00
|
|
|
httputil.MakeAdminAPI("admin_evacuate_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-03-27 13:39:33 +00:00
|
|
|
return AdminEvacuateRoom(req, rsAPI)
|
2022-04-28 15:02:30 +00:00
|
|
|
}),
|
2023-03-27 13:39:33 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-04-28 15:02:30 +00:00
|
|
|
|
2022-06-29 14:29:39 +00:00
|
|
|
dendriteAdminRouter.Handle("/admin/evacuateUser/{userID}",
|
2022-08-12 11:00:07 +00:00
|
|
|
httputil.MakeAdminAPI("admin_evacuate_user", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-04-28 15:46:01 +00:00
|
|
|
return AdminEvacuateUser(req, rsAPI)
|
2022-06-29 14:29:39 +00:00
|
|
|
}),
|
2023-03-27 13:39:33 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-06-29 14:29:39 +00:00
|
|
|
|
2023-01-19 20:02:32 +00:00
|
|
|
dendriteAdminRouter.Handle("/admin/purgeRoom/{roomID}",
|
|
|
|
httputil.MakeAdminAPI("admin_purge_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-04-28 15:46:01 +00:00
|
|
|
return AdminPurgeRoom(req, rsAPI)
|
2023-01-19 20:02:32 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-11-11 16:41:37 +00:00
|
|
|
dendriteAdminRouter.Handle("/admin/resetPassword/{userID}",
|
2022-08-12 11:00:07 +00: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 09:13:28 +00:00
|
|
|
dendriteAdminRouter.Handle("/admin/downloadState/{serverName}/{roomID}",
|
|
|
|
httputil.MakeAdminAPI("admin_download_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-04-28 15:46:01 +00:00
|
|
|
return AdminDownloadState(req, device, rsAPI)
|
2022-10-31 09:13:28 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-09-27 16:06:49 +00:00
|
|
|
dendriteAdminRouter.Handle("/admin/fulltext/reindex",
|
2022-09-30 08:32:31 +00:00
|
|
|
httputil.MakeAdminAPI("admin_fultext_reindex", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-09-27 16:06:49 +00:00
|
|
|
return AdminReindex(req, cfg, device, natsClient)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-09-30 08:32:31 +00:00
|
|
|
dendriteAdminRouter.Handle("/admin/refreshDevices/{userID}",
|
|
|
|
httputil.MakeAdminAPI("admin_refresh_devices", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-02-20 13:58:03 +00:00
|
|
|
return AdminMarkAsStale(req, cfg, userAPI)
|
2022-09-30 08:32:31 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-18 15:05:03 +00:00
|
|
|
// server notifications
|
|
|
|
if cfg.Matrix.ServerNotices.Enabled {
|
|
|
|
logrus.Info("Enabling server notices at /_synapse/admin/v1/send_server_notice")
|
2023-04-03 13:08:33 +00:00
|
|
|
serverNotificationSender, err := getSenderDevice(context.Background(), rsAPI, userAPI, cfg)
|
|
|
|
if err != nil {
|
|
|
|
logrus.WithError(err).Fatal("unable to get account for sending sending server notices")
|
|
|
|
}
|
2022-02-18 15:05:03 +00:00
|
|
|
|
|
|
|
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 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2022-02-18 15:05:03 +00:00
|
|
|
return *r
|
|
|
|
}
|
2023-02-03 12:42:35 +00:00
|
|
|
var vars map[string]string
|
|
|
|
vars, err = httputil.URLDecodeMapValues(mux.Vars(req))
|
2022-02-18 15:05:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
|
|
|
return SendServerNotice(
|
|
|
|
req, &cfg.Matrix.ServerNotices,
|
2022-03-24 21:45:44 +00:00
|
|
|
cfg, userAPI, rsAPI, asAPI,
|
2022-02-18 15:05:03 +00: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 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2022-02-18 15:05:03 +00:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return SendServerNotice(
|
|
|
|
req, &cfg.Matrix.ServerNotices,
|
2022-03-24 21:45:44 +00:00
|
|
|
cfg, userAPI, rsAPI, asAPI,
|
2022-02-18 15:05:03 +00:00
|
|
|
device, serverNotificationSender,
|
|
|
|
nil, transactionsCache,
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
|
|
|
|
2022-02-17 17:38:22 +00: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 11:16:37 +00:00
|
|
|
unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter()
|
2017-06-27 11:37:25 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/createRoom",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("createRoom", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 21:45:44 +00:00
|
|
|
return CreateRoom(req, device, cfg, userAPI, rsAPI, asAPI)
|
2017-05-18 12:47:23 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/join/{roomIDOrAlias}",
|
2023-04-19 14:50:33 +00:00
|
|
|
httputil.MakeAuthAPI(spec.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 17:16:53 +00:00
|
|
|
return JoinRoomByIDOrAlias(
|
2022-03-24 21:45:44 +00:00
|
|
|
req, device, rsAPI, userAPI, vars["roomIDOrAlias"],
|
2017-05-25 15:08:28 +00:00
|
|
|
)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2021-01-22 16:08:47 +00:00
|
|
|
|
|
|
|
if mscCfg.Enabled("msc2753") {
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/peek/{roomIDOrAlias}",
|
2023-04-19 14:50:33 +00:00
|
|
|
httputil.MakeAuthAPI(spec.Peek, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2021-01-22 16:08:47 +00:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return PeekRoomByIDOrAlias(
|
2022-03-24 21:45:44 +00:00
|
|
|
req, device, rsAPI, vars["roomIDOrAlias"],
|
2021-01-22 16:08:47 +00:00
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/joined_rooms",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("joined_rooms", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-09-04 14:58:30 +00:00
|
|
|
return GetJoinedRooms(req, device, rsAPI)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-03-19 10:25:36 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/join",
|
2023-04-19 14:50:33 +00:00
|
|
|
httputil.MakeAuthAPI(spec.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-24 17:19:54 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return JoinRoomByIDOrAlias(
|
2022-03-24 21:45:44 +00:00
|
|
|
req, device, rsAPI, userAPI, vars["roomID"],
|
2020-06-24 17:19:54 +00:00
|
|
|
)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-06-24 17:19:54 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/leave",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-05-04 17:34:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return LeaveRoomByID(
|
|
|
|
req, device, rsAPI, vars["roomID"],
|
|
|
|
)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-05-04 17:34:09 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/unpeek",
|
2020-12-03 11:11:46 +00: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 21:45:44 +00:00
|
|
|
req, device, rsAPI, vars["roomID"],
|
2020-12-03 11:11:46 +00:00
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/ban",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-24 17:19:54 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return SendBan(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2020-06-24 17:19:54 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/invite",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-24 17:19:54 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return SendInvite(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2020-06-24 17:19:54 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/kick",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-24 17:19:54 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return SendKick(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2020-06-24 17:19:54 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/unban",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return SendUnban(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2017-08-04 15:32:10 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/send/{eventType}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-10 11:17:54 +00:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, nil, cfg, rsAPI, nil)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-09-26 11:55:48 +00:00
|
|
|
txnID := vars["txnID"]
|
2018-05-18 09:49:40 +00:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], &txnID,
|
2020-06-10 11:17:54 +00:00
|
|
|
nil, cfg, rsAPI, transactionsCache)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2020-04-14 17:36:08 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 17:36:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-08-25 17:43:56 +00:00
|
|
|
return OnIncomingStateRequest(req.Context(), device, rsAPI, vars["roomID"])
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests())).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 17:36:08 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/aliases", httputil.MakeAuthAPI("aliases", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-21 15:53:50 +00: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 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{type:[^/]+/?}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 17:36:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-24 08:59:59 +00:00
|
|
|
// If there's a trailing slash, remove it
|
2021-08-17 09:39:09 +00:00
|
|
|
eventType := strings.TrimSuffix(vars["type"], "/")
|
2020-06-17 15:21:42 +00:00
|
|
|
eventFormat := req.URL.Query().Get("format") == "event"
|
2020-07-28 09:09:10 +00:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), device, rsAPI, vars["roomID"], eventType, "", eventFormat)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests())).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 17:36:08 +00:00
|
|
|
|
2022-02-17 17:38:22 +00: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 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 17:36:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-17 15:21:42 +00:00
|
|
|
eventFormat := req.URL.Query().Get("format") == "event"
|
2020-07-28 09:09:10 +00:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), device, rsAPI, vars["roomID"], vars["type"], vars["stateKey"], eventFormat)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests())).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 17:36:08 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 11:21:52 +00:00
|
|
|
emptyString := ""
|
2021-08-17 09:39:09 +00:00
|
|
|
eventType := strings.TrimSuffix(vars["eventType"], "/")
|
2020-06-10 11:17:54 +00:00
|
|
|
return SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, rsAPI, nil)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2020-04-14 17:36:08 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 11:21:52 +00:00
|
|
|
stateKey := vars["stateKey"]
|
2020-06-10 11:17:54 +00:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, &stateKey, cfg, rsAPI, nil)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-02-20 15:41:29 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/register", httputil.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, nil); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return Register(req, userAPI, cfg)
|
2018-03-13 15:55:45 +00:00
|
|
|
})).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-22 15:13:19 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/register/available", httputil.MakeExternalAPI("registerAvailable", func(req *http.Request) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, nil); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return RegisterAvailable(req, cfg, userAPI)
|
2018-03-13 15:55:45 +00:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-09 14:24:38 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeExternalAPI("directory_room", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 09:48:17 +00:00
|
|
|
return DirectoryRoom(req, vars["roomAlias"], federation, cfg, rsAPI, federationSender)
|
2017-06-27 11:37:25 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-28 10:31:43 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 09:48:17 +00:00
|
|
|
return SetLocalAlias(req, device, vars["roomAlias"], cfg, rsAPI)
|
2017-07-28 10:31:43 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-28 10:31:43 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 09:48:17 +00:00
|
|
|
return RemoveLocalAlias(req, device, vars["roomAlias"], rsAPI)
|
2017-07-28 10:31:43 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/directory/list/room/{roomID}",
|
2020-07-02 14:41:18 +00: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 12:40:35 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/directory/list/room/{roomID}",
|
2020-07-02 14:41:18 +00: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 13:47:59 +00:00
|
|
|
return SetVisibility(req, rsAPI, device, vars["roomID"])
|
2020-07-02 14:41:18 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2022-10-27 12:40:35 +00: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 17:38:22 +00:00
|
|
|
v3mux.Handle("/publicRooms",
|
2020-07-02 14:41:18 +00:00
|
|
|
httputil.MakeExternalAPI("public_rooms", func(req *http.Request) util.JSONResponse {
|
2020-09-07 11:38:09 +00:00
|
|
|
return GetPostPublicRooms(req, rsAPI, extRoomsProvider, federation, cfg)
|
2020-07-02 14:41:18 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
2017-06-27 11:37:25 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/logout",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("logout", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 17:53:40 +00:00
|
|
|
return Logout(req, userAPI, device)
|
2017-07-11 15:04:34 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-07-11 15:04:34 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/logout/all",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("logout", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 17:53:40 +00:00
|
|
|
return LogoutAll(req, userAPI, device)
|
2017-10-15 10:29:47 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-10-15 10:29:47 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/typing/{userID}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("rooms_typing", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-29 12:14:35 +00:00
|
|
|
return SendTyping(req, device, vars["roomID"], vars["userID"], rsAPI, syncProducer)
|
2018-07-24 14:49:49 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/redact/{eventID}",
|
2020-07-03 16:24:51 +00: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 08:28:41 +00:00
|
|
|
return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, nil, nil)
|
2020-07-03 16:24:51 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/redact/{eventID}/{txnId}",
|
2020-08-25 09:39:30 +00: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 08:28:41 +00:00
|
|
|
txnID := vars["txnId"]
|
|
|
|
return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, &txnID, transactionsCache)
|
2020-08-25 09:39:30 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2018-07-24 14:49:49 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/sendToDevice/{eventType}/{txnID}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00: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 16:50:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
2022-03-29 12:14:35 +00:00
|
|
|
return SendToDevice(req, device, syncProducer, transactionsCache, vars["eventType"], &txnID)
|
2022-11-11 09:52:08 +00: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 16:50:19 +00: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 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00: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 16:50:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
2022-03-29 12:14:35 +00:00
|
|
|
return SendToDevice(req, device, syncProducer, transactionsCache, vars["eventType"], &txnID)
|
2022-11-11 09:52:08 +00: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 16:50:19 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/account/whoami",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("whoami", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2018-08-04 09:32:02 +00:00
|
|
|
return Whoami(req, device)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-08-04 09:32:02 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/account/password",
|
2020-09-04 14:16:13 +00:00
|
|
|
httputil.MakeAuthAPI("password", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-04 14:16:13 +00:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return Password(req, userAPI, device, cfg)
|
2020-09-04 14:16:13 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/account/deactivate",
|
2020-10-02 16:18:20 +00:00
|
|
|
httputil.MakeAuthAPI("deactivate", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-10-02 16:18:20 +00:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return Deactivate(req, userInteractiveAuth, userAPI, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2021-04-07 12:26:20 +00:00
|
|
|
// Stub endpoints required by Element
|
2017-04-20 16:11:53 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/login",
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeExternalAPI("login", func(req *http.Request) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, nil); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return Login(req, userAPI, cfg)
|
2017-05-18 12:47:23 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
2017-04-20 16:11:53 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/auth/{authType}/fallback/web",
|
2023-03-22 08:21:32 +00:00
|
|
|
httputil.MakeHTMLAPI("auth_fallback", enableMetrics, func(w http.ResponseWriter, req *http.Request) {
|
2019-08-14 17:34:49 +00:00
|
|
|
vars := mux.Vars(req)
|
2022-12-23 13:11:11 +00:00
|
|
|
AuthFallback(w, req, vars["authType"], cfg)
|
2019-08-14 17:34:49 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-03-03 11:40:53 +00: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,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.InvalidParam("missing trailing slash"),
|
2022-03-03 11:40:53 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/pushrules/",
|
2022-03-03 11:40:53 +00: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 16:11:53 +00:00
|
|
|
return util.JSONResponse{
|
2022-03-03 11:40:53 +00:00
|
|
|
Code: http.StatusBadRequest,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.InvalidParam("scope, kind and rule ID must be specified"),
|
2022-03-03 11:40:53 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
).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,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.InvalidParam("missing trailing slash after scope"),
|
2022-03-03 11:40:53 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
).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,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.InvalidParam("kind and rule ID must be specified"),
|
2022-03-03 11:40:53 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
).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,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.InvalidParam("missing trailing slash after kind"),
|
2022-03-03 11:40:53 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
).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,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.InvalidParam("rule ID must be specified"),
|
2022-03-03 11:40:53 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
).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 16:11:53 +00:00
|
|
|
}
|
2022-03-03 11:40:53 +00:00
|
|
|
return GetPushRuleByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], device, userAPI)
|
2017-05-18 12:47:23 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 16:11:53 +00:00
|
|
|
|
2022-03-03 11:40:53 +00:00
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2022-03-03 11:40:53 +00: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 12:26:20 +00:00
|
|
|
// Element user settings
|
2017-04-20 16:11:53 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/profile/{userID}",
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeExternalAPI("profile", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return GetProfile(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-05-18 12:47:23 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 16:11:53 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/profile/{userID}/avatar_url",
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeExternalAPI("profile_avatar_url", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return GetAvatarURL(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 13:52:41 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 13:52:41 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/profile/{userID}/avatar_url",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("profile_avatar_url", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return SetAvatarURL(req, userAPI, device, vars["userID"], cfg, rsAPI)
|
2017-07-10 13:52:41 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 13:52:41 +00: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 17:38:22 +00:00
|
|
|
v3mux.Handle("/profile/{userID}/displayname",
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeExternalAPI("profile_displayname", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return GetDisplayName(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 13:52:41 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 13:52:41 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/profile/{userID}/displayname",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("profile_displayname", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 21:45:44 +00:00
|
|
|
return SetDisplayName(req, userAPI, device, vars["userID"], cfg, rsAPI)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 13:52:41 +00:00
|
|
|
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows
|
|
|
|
// PUT requests, so we need to allow this method
|
|
|
|
|
2023-04-03 19:42:46 +00:00
|
|
|
threePIDClient := base.CreateClient(dendriteCfg, nil) // TODO: Move this somewhere else, e.g. pass in as parameter
|
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/account/3pid",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 21:45:44 +00:00
|
|
|
return GetAssociated3PIDs(req, userAPI, device)
|
2017-05-18 12:47:23 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-01 09:13:10 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/account/3pid",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-04-03 19:42:46 +00:00
|
|
|
return CheckAndSave3PIDAssociation(req, userAPI, device, cfg, threePIDClient)
|
2017-09-01 09:13:10 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 09:13:10 +00:00
|
|
|
|
2023-04-03 19:42:46 +00:00
|
|
|
v3mux.Handle("/account/3pid/delete",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 21:45:44 +00:00
|
|
|
return Forget3PID(req, userAPI)
|
2017-09-01 09:13:10 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 09:13:10 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/{path:(?:account/3pid|register)}/email/requestToken",
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeExternalAPI("account_3pid_request_token", func(req *http.Request) util.JSONResponse {
|
2023-04-03 19:42:46 +00:00
|
|
|
return RequestEmailToken(req, userAPI, cfg, threePIDClient)
|
2017-09-01 09:13:10 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-04-20 16:11:53 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/voip/turnServer",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("turn_server", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2017-11-09 09:58:45 +00:00
|
|
|
return RequestTurnServer(req, device, cfg)
|
2017-06-27 11:37:25 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 11:37:25 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/thirdparty/protocols",
|
2022-11-02 10:17:53 +00:00
|
|
|
httputil.MakeAuthAPI("thirdparty_protocols", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return Protocols(req, asAPI, device, "")
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2022-11-02 10:17:53 +00: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 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2022-11-02 10:17:53 +00: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 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2022-11-02 10:17:53 +00: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 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2022-11-02 10:17:53 +00: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 11:37:25 +00:00
|
|
|
}
|
2022-11-02 10:17:53 +00:00
|
|
|
return Location(req, asAPI, device, vars["protocolID"], req.URL.Query())
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2022-11-02 10:17:53 +00: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 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 11:37:25 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/initialSync",
|
2020-06-12 13:55:57 +00:00
|
|
|
httputil.MakeExternalAPI("rooms_initial_sync", func(req *http.Request) util.JSONResponse {
|
2017-06-27 11:37:25 +00:00
|
|
|
// TODO: Allow people to peek into rooms.
|
|
|
|
return util.JSONResponse{
|
2018-03-13 15:55:45 +00:00
|
|
|
Code: http.StatusForbidden,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.GuestAccessForbidden("Guest access not implemented"),
|
2017-06-27 11:37:25 +00:00
|
|
|
}
|
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 11:37:25 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/user/{userID}/account_data/{type}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 17:36:03 +00:00
|
|
|
return SaveAccountData(req, userAPI, device, vars["userID"], "", vars["type"], syncProducer)
|
2017-07-26 13:53:11 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-26 13:53:11 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 17:36:03 +00:00
|
|
|
return SaveAccountData(req, userAPI, device, vars["userID"], vars["roomID"], vars["type"], syncProducer)
|
2017-06-27 11:37:25 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-06-27 11:37:25 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/user/{userID}/account_data/{type}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-01-29 17:53:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 17:36:03 +00:00
|
|
|
return GetAccountData(req, userAPI, device, vars["userID"], "", vars["type"])
|
2020-01-29 17:53:05 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-01-29 17:53:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 17:36:03 +00:00
|
|
|
return GetAccountData(req, userAPI, device, vars["userID"], vars["roomID"], vars["type"])
|
2020-01-29 17:53:05 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/admin/whois/{userID}",
|
2020-11-17 10:07:03 +00: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 17:38:22 +00:00
|
|
|
v3mux.Handle("/user/{userID}/openid/request_token",
|
2021-04-07 12:26:20 +00:00
|
|
|
httputil.MakeAuthAPI("openid_request_token", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2021-04-07 12:26:20 +00: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 17:38:22 +00:00
|
|
|
v3mux.Handle("/user_directory/search",
|
2020-07-28 09:53:17 +00:00
|
|
|
httputil.MakeAuthAPI("userdirectory_search", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2020-07-28 09:53:17 +00:00
|
|
|
postContent := struct {
|
|
|
|
SearchString string `json:"search_term"`
|
|
|
|
Limit int `json:"limit"`
|
|
|
|
}{}
|
2020-10-09 08:15:51 +00:00
|
|
|
|
|
|
|
if resErr := clientutil.UnmarshalJSONRequest(req, &postContent); resErr != nil {
|
|
|
|
return *resErr
|
2020-07-28 09:53:17 +00:00
|
|
|
}
|
2022-05-05 12:17:38 +00:00
|
|
|
return SearchUserDirectory(
|
2020-07-28 09:53:17 +00:00
|
|
|
req.Context(),
|
|
|
|
device,
|
2020-09-04 10:46:01 +00:00
|
|
|
rsAPI,
|
2022-03-28 15:25:26 +00:00
|
|
|
userDirectoryProvider,
|
2020-07-28 09:53:17 +00:00
|
|
|
postContent.SearchString,
|
|
|
|
postContent.Limit,
|
2022-08-12 11:33:31 +00:00
|
|
|
federation,
|
|
|
|
cfg.Matrix.ServerName,
|
2020-07-28 09:53:17 +00:00
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/read_markers",
|
2020-10-09 08:15:35 +00:00
|
|
|
httputil.MakeAuthAPI("rooms_read_markers", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2020-10-09 08:15:35 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-29 12:14:35 +00:00
|
|
|
return SaveReadMarker(req, userAPI, rsAPI, syncProducer, device, vars["roomID"])
|
2017-06-27 11:37:25 +00:00
|
|
|
}),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-06-27 11:37:25 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomID}/forget",
|
2020-11-05 10:19:23 +00:00
|
|
|
httputil.MakeAuthAPI("rooms_forget", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-11-05 10:19:23 +00: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 09:04:08 +00: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 17:38:22 +00:00
|
|
|
v3mux.Handle("/devices",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("get_devices", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 17:53:40 +00:00
|
|
|
return GetDevicesByLocalpart(req, userAPI, device)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 18:12:54 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("get_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-08-27 17:53:40 +00:00
|
|
|
return GetDeviceByID(req, userAPI, device, vars["deviceID"])
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 18:12:54 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("device_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 15:38:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-07-31 13:40:45 +00:00
|
|
|
return UpdateDeviceByID(req, userAPI, device, vars["deviceID"])
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-11-14 09:59:02 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("delete_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-02-11 12:13:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-07-30 17:00:56 +00:00
|
|
|
return DeleteDeviceById(req, userInteractiveAuth, userAPI, device, vars["deviceID"])
|
2020-02-11 12:13:38 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/delete_devices",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("delete_devices", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-03-31 08:15:01 +00:00
|
|
|
return DeleteDevices(req, userInteractiveAuth, userAPI, device)
|
2020-02-11 12:13:38 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-03-03 11:40:53 +00: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 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2022-03-03 11:40:53 +00:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return SetPusher(req, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2017-09-22 16:28:29 +00:00
|
|
|
// Stub implementations for sytest
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/events",
|
2022-11-11 09:52:08 +00:00
|
|
|
httputil.MakeAuthAPI("events", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2018-03-13 15:55:45 +00:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 16:28:29 +00:00
|
|
|
"chunk": []interface{}{},
|
|
|
|
"start": "",
|
|
|
|
"end": "",
|
|
|
|
}}
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-22 16:28:29 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/initialSync",
|
2022-11-11 09:52:08 +00:00
|
|
|
httputil.MakeAuthAPI("initial_sync", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2018-03-13 15:55:45 +00:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 16:28:29 +00:00
|
|
|
"end": "",
|
|
|
|
}}
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2018-03-13 15:55:45 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2019-08-02 11:17:51 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("get_tags", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 11:17:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 17:36:03 +00:00
|
|
|
return GetTags(req, userAPI, device, vars["userId"], vars["roomId"], syncProducer)
|
2019-08-02 11:17:51 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("put_tag", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 11:17:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 17:36:03 +00:00
|
|
|
return PutTag(req, userAPI, device, vars["userId"], vars["roomId"], vars["tag"], syncProducer)
|
2019-08-02 11:17:51 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("delete_tag", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 13:55:57 +00:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 11:17:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 17:36:03 +00:00
|
|
|
return DeleteTag(req, userAPI, device, vars["userId"], vars["roomId"], vars["tag"], syncProducer)
|
2019-08-02 11:17:51 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
2020-02-05 18:06:39 +00:00
|
|
|
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/capabilities",
|
2020-07-02 16:11:33 +00:00
|
|
|
httputil.MakeAuthAPI("capabilities", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-09-03 09:12:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
2023-04-03 19:42:46 +00:00
|
|
|
return GetCapabilities()
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-09-27 21:23:42 +00:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2020-07-13 15:02:35 +00:00
|
|
|
|
2021-07-27 18:29:32 +00:00
|
|
|
// Key Backup Versions (Metadata)
|
|
|
|
|
2021-07-28 09:25:45 +00: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 17:38:22 +00: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 09:25:45 +00: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 11:47:32 +00:00
|
|
|
|
2021-07-27 18:29:32 +00:00
|
|
|
// Inserting E2E Backup Keys
|
|
|
|
|
2021-07-27 16:08:53 +00:00
|
|
|
// Bulk room and session
|
2021-07-28 09:25:45 +00: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,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.InvalidParam("version must be specified"),
|
2021-07-27 16:08:53 +00:00
|
|
|
}
|
2021-07-28 09:25:45 +00:00
|
|
|
}
|
|
|
|
var reqBody keyBackupSessionRequest
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &reqBody)
|
|
|
|
if resErr != nil {
|
|
|
|
return *resErr
|
|
|
|
}
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &reqBody)
|
|
|
|
})
|
|
|
|
|
2021-07-27 16:08:53 +00:00
|
|
|
// Single room bulk session
|
2021-07-28 09:25:45 +00: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,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.InvalidParam("version must be specified"),
|
2021-07-27 16:08:53 +00:00
|
|
|
}
|
2021-07-28 09:25:45 +00: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 16:08:53 +00:00
|
|
|
// Single room, single session
|
2021-07-28 09:25:45 +00: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,
|
2023-05-09 22:46:49 +00:00
|
|
|
JSON: spec.InvalidParam("version must be specified"),
|
2021-07-27 18:29:32 +00:00
|
|
|
}
|
2021-07-28 09:25:45 +00: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 17:38:22 +00: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 09:25:45 +00: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 16:08:53 +00:00
|
|
|
|
2021-07-27 18:29:32 +00:00
|
|
|
// Querying E2E Backup Keys
|
|
|
|
|
2021-07-28 09:25:45 +00: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 17:38:22 +00: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 09:25:45 +00: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 18:29:32 +00:00
|
|
|
|
|
|
|
// Deleting E2E Backup Keys
|
|
|
|
|
2021-08-04 16:56:29 +00:00
|
|
|
// Cross-signing device keys
|
|
|
|
|
|
|
|
postDeviceSigningKeys := httputil.MakeAuthAPI("post_device_signing_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-02-20 13:58:03 +00:00
|
|
|
return UploadCrossSigningDeviceKeys(req, userInteractiveAuth, userAPI, device, userAPI, cfg)
|
2021-08-04 16:56:29 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
postDeviceSigningSignatures := httputil.MakeAuthAPI("post_device_signing_signatures", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-02-20 13:58:03 +00:00
|
|
|
return UploadCrossSigningDeviceSignatures(req, userAPI, device)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests())
|
2021-08-04 16:56:29 +00:00
|
|
|
|
2022-02-17 17:38:22 +00: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 16:56:29 +00: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 15:02:35 +00:00
|
|
|
// Supplying a device ID is deprecated.
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/keys/upload/{deviceID}",
|
2020-07-13 15:02:35 +00:00
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-02-20 13:58:03 +00:00
|
|
|
return UploadKeys(req, userAPI, device)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-07-15 11:02:34 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/keys/upload",
|
2020-07-15 11:02:34 +00:00
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-02-20 13:58:03 +00:00
|
|
|
return UploadKeys(req, userAPI, device)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-07-13 15:02:35 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/keys/query",
|
2020-07-15 17:40:41 +00:00
|
|
|
httputil.MakeAuthAPI("keys_query", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-02-20 13:58:03 +00:00
|
|
|
return QueryKeys(req, userAPI, device)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-07-15 17:40:41 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/keys/claim",
|
2020-07-21 13:47:53 +00:00
|
|
|
httputil.MakeAuthAPI("keys_claim", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2023-02-20 13:58:03 +00:00
|
|
|
return ClaimKeys(req, userAPI)
|
2022-11-11 09:52:08 +00:00
|
|
|
}, httputil.WithAllowGuests()),
|
2020-07-21 13:47:53 +00:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 17:38:22 +00:00
|
|
|
v3mux.Handle("/rooms/{roomId}/receipt/{receiptType}/{eventId}",
|
2023-04-19 14:50:33 +00:00
|
|
|
httputil.MakeAuthAPI(spec.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-06-07 13:24:04 +00:00
|
|
|
if r := rateLimits.Limit(req, device); r != nil {
|
2020-11-09 18:46:11 +00:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
|
2022-10-11 11:27:21 +00:00
|
|
|
return SetReceipt(req, userAPI, syncProducer, device, vars["roomId"], vars["receiptType"], vars["eventId"])
|
2020-11-09 18:46:11 +00:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-04-06 11:11:19 +00: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 15:41:29 +00:00
|
|
|
}
|