Fix media API for demos and possibly Synapse (#1134)

* Fix media API for demos and possibly Synapse

* User API

* goimports
This commit is contained in:
Neil Alexander 2020-06-16 14:29:11 +01:00 committed by GitHub
parent 9c77022513
commit fc0e74ae0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 71 additions and 25 deletions

View file

@ -32,6 +32,7 @@ import (
)
const pathPrefixR0 = "/media/r0"
const pathPrefixV1 = "/media/v1" // TODO: remove when synapse is fixed
// Setup registers the media API HTTP handlers
//
@ -46,6 +47,7 @@ func Setup(
client *gomatrixserverlib.Client,
) {
r0mux := publicAPIMux.PathPrefix(pathPrefixR0).Subrouter()
v1mux := publicAPIMux.PathPrefix(pathPrefixV1).Subrouter()
activeThumbnailGeneration := &types.ActiveThumbnailGeneration{
PathToResult: map[string]*types.ThumbnailGenerationResult{},
@ -60,9 +62,11 @@ func Setup(
activeRemoteRequests := &types.ActiveRemoteRequests{
MXCToResult: map[string]*types.RemoteRequestResult{},
}
r0mux.Handle("/download/{serverName}/{mediaId}",
makeDownloadAPI("download", cfg, db, client, activeRemoteRequests, activeThumbnailGeneration),
).Methods(http.MethodGet, http.MethodOptions)
downloadHandler := makeDownloadAPI("download", cfg, db, client, activeRemoteRequests, activeThumbnailGeneration)
r0mux.Handle("/download/{serverName}/{mediaId}", downloadHandler).Methods(http.MethodGet, http.MethodOptions)
v1mux.Handle("/download/{serverName}/{mediaId}", downloadHandler).Methods(http.MethodGet, http.MethodOptions) // TODO: remove when synapse is fixed
r0mux.Handle("/thumbnail/{serverName}/{mediaId}",
makeDownloadAPI("thumbnail", cfg, db, client, activeRemoteRequests, activeThumbnailGeneration),
).Methods(http.MethodGet, http.MethodOptions)