[feature] Implement media v2 endpoint to accommodate Tusky 17 (#480)

* serve v2 media api

* go fmt
This commit is contained in:
tobi 2022-04-24 13:11:52 +02:00 committed by GitHub
commit 9813a044c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 12 deletions

View file

@ -26,14 +26,20 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/router"
)
// BasePath is the base API path for making media requests
const BasePath = "/api/v1/media"
// BasePathV1 is the base API path for making media requests through v1 of the api (for mastodon API compatibility)
const BasePathV1 = "/api/v1/media"
// BasePathV2 is the base API path for making media requests through v2 of the api (for mastodon API compatibility)
const BasePathV2 = "/api/v2/media"
// IDKey is the key for media attachment IDs
const IDKey = "id"
// BasePathWithID corresponds to a media attachment with the given ID
const BasePathWithID = BasePath + "/:" + IDKey
// BasePathWithIDV1 corresponds to a media attachment with the given ID
const BasePathWithIDV1 = BasePathV1 + "/:" + IDKey
// BasePathWithIDV2 corresponds to a media attachment with the given ID
const BasePathWithIDV2 = BasePathV2 + "/:" + IDKey
// Module implements the ClientAPIModule interface for media
type Module struct {
@ -49,8 +55,15 @@ func New(processor processing.Processor) api.ClientModule {
// Route satisfies the RESTAPIModule interface
func (m *Module) Route(s router.Router) error {
s.AttachHandler(http.MethodPost, BasePath, m.MediaCreatePOSTHandler)
s.AttachHandler(http.MethodGet, BasePathWithID, m.MediaGETHandler)
s.AttachHandler(http.MethodPut, BasePathWithID, m.MediaPUTHandler)
// v1 handlers
s.AttachHandler(http.MethodPost, BasePathV1, m.MediaCreatePOSTHandler)
s.AttachHandler(http.MethodGet, BasePathWithIDV1, m.MediaGETHandler)
s.AttachHandler(http.MethodPut, BasePathWithIDV1, m.MediaPUTHandler)
// v2 handlers
s.AttachHandler(http.MethodPost, BasePathV2, m.MediaCreatePOSTHandler)
s.AttachHandler(http.MethodGet, BasePathWithIDV2, m.MediaGETHandler)
s.AttachHandler(http.MethodPut, BasePathWithIDV2, m.MediaPUTHandler)
return nil
}