diff --git a/src/github.com/turt2live/matrix-media-repo/api/custom/datastores.go b/src/github.com/turt2live/matrix-media-repo/api/custom/datastores.go index bc81d973252421366019b1b64b1ff446c6be0908..28211ba4ca060203a671546f2c9fc1fc3d975ede 100644 --- a/src/github.com/turt2live/matrix-media-repo/api/custom/datastores.go +++ b/src/github.com/turt2live/matrix-media-repo/api/custom/datastores.go @@ -22,6 +22,25 @@ type DatastoreMigrationEstimate struct { TotalBytes int64 `json:"total_bytes"` } +func GetDatastores(r *http.Request, log *logrus.Entry, user api.UserInfo) interface{} { + datastores, err := storage.GetDatabase().GetMediaStore(r.Context(), log).GetAllDatastores() + if err != nil { + log.Error(err) + return api.InternalServerError("Error getting datastores") + } + + response := make(map[string]interface{}) + + for _, ds := range datastores { + dsMap := make(map[string]interface{}) + dsMap["type"] = ds.Type + dsMap["uri"] = ds.Uri + response[ds.DatastoreId] = dsMap + } + + return response +} + func GetDatastoreStorageEstimate(r *http.Request, log *logrus.Entry, user api.UserInfo) interface{} { beforeTsStr := r.URL.Query().Get("before_ts") beforeTs := util.NowMillis() diff --git a/src/github.com/turt2live/matrix-media-repo/api/webserver/webserver.go b/src/github.com/turt2live/matrix-media-repo/api/webserver/webserver.go index 1d5e2cd55d0aa5fd5b6d204d3a90379baf68ccaf..df07d70b132cd2ff7aeca9b43f2057b90277402d 100644 --- a/src/github.com/turt2live/matrix-media-repo/api/webserver/webserver.go +++ b/src/github.com/turt2live/matrix-media-repo/api/webserver/webserver.go @@ -38,6 +38,7 @@ func Init() { infoHandler := handler{api.AccessTokenRequiredRoute(unstable.MediaInfo), "info", counter} configHandler := handler{api.AccessTokenRequiredRoute(r0.PublicConfig), "config", counter} storageEstimateHandler := handler{api.RepoAdminRoute(custom.GetDatastoreStorageEstimate), "get_storage_estimate", counter} + datastoreListHandler := handler{api.RepoAdminRoute(custom.GetDatastores), "list_datastores", counter} routes := make(map[string]route) versions := []string{"r0", "v1", "unstable"} // r0 is typically clients and v1 is typically servers. v1 is deprecated. @@ -56,7 +57,8 @@ func Init() { routes["/_matrix/media/"+version+"/admin/purge_remote"] = route{"POST", purgeHandler} routes["/_matrix/media/"+version+"/admin/quarantine/{server:[a-zA-Z0-9.:\\-_]+}/{mediaId:[a-zA-Z0-9.\\-_]+}"] = route{"POST", quarantineHandler} routes["/_matrix/media/"+version+"/admin/room/{roomId:[^/]+}/quarantine"] = route{"POST", quarantineRoomHandler} - routes["/_matrix/media/"+version+"/admin/datastore/{datastoreId:[^/]+}/size_estimate"] = route{"GET", storageEstimateHandler} + routes["/_matrix/media/"+version+"/admin/datastores/{datastoreId:[^/]+}/size_estimate"] = route{"GET", storageEstimateHandler} + routes["/_matrix/media/"+version+"/admin/datastores"] = route{"GET", datastoreListHandler} // Routes that we should handle but aren't in the media namespace (synapse compat) routes["/_matrix/client/"+version+"/admin/purge_media_cache"] = route{"POST", purgeHandler}