aboutsummaryrefslogtreecommitdiff
path: root/mediaapi
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-03-22 09:21:32 +0100
committerGitHub <noreply@github.com>2023-03-22 09:21:32 +0100
commit5e85a00cb36c3d343cd5b6f6a18435989724a135 (patch)
treeb22c34dd0a6cdc04025b90086843f9084a876412 /mediaapi
parentec6879e5ae2919c903707475ce8d72244b2a6847 (diff)
Remove `BaseDendrite` (#3023)
Removes `BaseDendrite` to, hopefully, make testing and composing of components easier in the future.
Diffstat (limited to 'mediaapi')
-rw-r--r--mediaapi/mediaapi.go15
-rw-r--r--mediaapi/routing/routing.go15
-rw-r--r--mediaapi/routing/upload_test.go2
-rw-r--r--mediaapi/storage/storage_test.go2
4 files changed, 17 insertions, 17 deletions
diff --git a/mediaapi/mediaapi.go b/mediaapi/mediaapi.go
index 42e0ea88..5d517ef2 100644
--- a/mediaapi/mediaapi.go
+++ b/mediaapi/mediaapi.go
@@ -15,9 +15,11 @@
package mediaapi
import (
+ "github.com/gorilla/mux"
+ "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/mediaapi/routing"
"github.com/matrix-org/dendrite/mediaapi/storage"
- "github.com/matrix-org/dendrite/setup/base"
+ "github.com/matrix-org/dendrite/setup/config"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/sirupsen/logrus"
@@ -25,19 +27,18 @@ import (
// AddPublicRoutes sets up and registers HTTP handlers for the MediaAPI component.
func AddPublicRoutes(
- base *base.BaseDendrite,
+ mediaRouter *mux.Router,
+ cm sqlutil.Connections,
+ cfg *config.Dendrite,
userAPI userapi.MediaUserAPI,
client *gomatrixserverlib.Client,
) {
- cfg := &base.Cfg.MediaAPI
- rateCfg := &base.Cfg.ClientAPI.RateLimiting
-
- mediaDB, err := storage.NewMediaAPIDatasource(base.ConnectionManager, &cfg.Database)
+ mediaDB, err := storage.NewMediaAPIDatasource(cm, &cfg.MediaAPI.Database)
if err != nil {
logrus.WithError(err).Panicf("failed to connect to media db")
}
routing.Setup(
- base.Routers.Media, cfg, rateCfg, mediaDB, userAPI, client,
+ mediaRouter, cfg, mediaDB, userAPI, client,
)
}
diff --git a/mediaapi/routing/routing.go b/mediaapi/routing/routing.go
index 8a4a5afc..98e6a82e 100644
--- a/mediaapi/routing/routing.go
+++ b/mediaapi/routing/routing.go
@@ -45,13 +45,12 @@ type configResponse struct {
// nolint: gocyclo
func Setup(
publicAPIMux *mux.Router,
- cfg *config.MediaAPI,
- rateLimit *config.RateLimiting,
+ cfg *config.Dendrite,
db storage.Database,
userAPI userapi.MediaUserAPI,
client *gomatrixserverlib.Client,
) {
- rateLimits := httputil.NewRateLimits(rateLimit)
+ rateLimits := httputil.NewRateLimits(&cfg.ClientAPI.RateLimiting)
v3mux := publicAPIMux.PathPrefix("/{apiversion:(?:r0|v1|v3)}/").Subrouter()
@@ -65,7 +64,7 @@ func Setup(
if r := rateLimits.Limit(req, dev); r != nil {
return *r
}
- return Upload(req, cfg, dev, db, activeThumbnailGeneration)
+ return Upload(req, &cfg.MediaAPI, dev, db, activeThumbnailGeneration)
},
)
@@ -73,8 +72,8 @@ func Setup(
if r := rateLimits.Limit(req, device); r != nil {
return *r
}
- respondSize := &cfg.MaxFileSizeBytes
- if cfg.MaxFileSizeBytes == 0 {
+ respondSize := &cfg.MediaAPI.MaxFileSizeBytes
+ if cfg.MediaAPI.MaxFileSizeBytes == 0 {
respondSize = nil
}
return util.JSONResponse{
@@ -90,12 +89,12 @@ func Setup(
MXCToResult: map[string]*types.RemoteRequestResult{},
}
- downloadHandler := makeDownloadAPI("download", cfg, rateLimits, db, client, activeRemoteRequests, activeThumbnailGeneration)
+ downloadHandler := makeDownloadAPI("download", &cfg.MediaAPI, rateLimits, db, client, activeRemoteRequests, activeThumbnailGeneration)
v3mux.Handle("/download/{serverName}/{mediaId}", downloadHandler).Methods(http.MethodGet, http.MethodOptions)
v3mux.Handle("/download/{serverName}/{mediaId}/{downloadName}", downloadHandler).Methods(http.MethodGet, http.MethodOptions)
v3mux.Handle("/thumbnail/{serverName}/{mediaId}",
- makeDownloadAPI("thumbnail", cfg, rateLimits, db, client, activeRemoteRequests, activeThumbnailGeneration),
+ makeDownloadAPI("thumbnail", &cfg.MediaAPI, rateLimits, db, client, activeRemoteRequests, activeThumbnailGeneration),
).Methods(http.MethodGet, http.MethodOptions)
}
diff --git a/mediaapi/routing/upload_test.go b/mediaapi/routing/upload_test.go
index d4fb45d1..d088950c 100644
--- a/mediaapi/routing/upload_test.go
+++ b/mediaapi/routing/upload_test.go
@@ -50,7 +50,7 @@ func Test_uploadRequest_doUpload(t *testing.T) {
// create testdata folder and remove when done
_ = os.Mkdir(testdataPath, os.ModePerm)
defer fileutils.RemoveDir(types.Path(testdataPath), nil)
- cm := sqlutil.NewConnectionManager()
+ cm := sqlutil.NewConnectionManager(nil, config.DatabaseOptions{})
db, err := storage.NewMediaAPIDatasource(cm, &config.DatabaseOptions{
ConnectionString: "file::memory:?cache=shared",
MaxOpenConnections: 100,
diff --git a/mediaapi/storage/storage_test.go b/mediaapi/storage/storage_test.go
index 11febd27..8cd29a54 100644
--- a/mediaapi/storage/storage_test.go
+++ b/mediaapi/storage/storage_test.go
@@ -14,7 +14,7 @@ import (
func mustCreateDatabase(t *testing.T, dbType test.DBType) (storage.Database, func()) {
connStr, close := test.PrepareDBConnectionString(t, dbType)
- cm := sqlutil.NewConnectionManager()
+ cm := sqlutil.NewConnectionManager(nil, config.DatabaseOptions{})
db, err := storage.NewMediaAPIDatasource(cm, &config.DatabaseOptions{
ConnectionString: config.DataSource(connStr),
})