summaryrefslogtreecommitdiff
path: root/internal/api/client/fileserver
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-05-10 16:29:05 +0200
committerLibravatar GitHub <noreply@github.com>2021-05-10 16:29:05 +0200
commit742f985d5b0620ad14015f9a2df9940edc254bf4 (patch)
tree5c8d469fd015efc6f8459f2d9df04132877285a3 /internal/api/client/fileserver
parentWebfinger + Small fixes (#20) (diff)
downloadgotosocial-742f985d5b0620ad14015f9a2df9940edc254bf4.tar.xz
Mediahandler (#21)
Media GET and media PUT handlers
Diffstat (limited to 'internal/api/client/fileserver')
-rw-r--r--internal/api/client/fileserver/servefile.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/internal/api/client/fileserver/servefile.go b/internal/api/client/fileserver/servefile.go
index 9823eb387..1339fbac3 100644
--- a/internal/api/client/fileserver/servefile.go
+++ b/internal/api/client/fileserver/servefile.go
@@ -78,7 +78,7 @@ func (m *FileServer) ServeFile(c *gin.Context) {
return
}
- content, err := m.processor.MediaGet(authed, &model.GetContentRequestForm{
+ content, err := m.processor.FileGet(authed, &model.GetContentRequestForm{
AccountID: accountID,
MediaType: mediaType,
MediaSize: mediaSize,
@@ -90,5 +90,14 @@ func (m *FileServer) ServeFile(c *gin.Context) {
return
}
+ // TODO: do proper content negotiation here -- if the requester only accepts text/html we should try to serve them *something*
+ // This is mostly needed because when sharing a link to a gts-hosted file on something like mastodon, the masto servers will
+ // attempt to look up the content to provide a preview of the link, and they ask for text/html.
+ if c.NegotiateFormat(content.ContentType) == "" {
+ l.Debugf("couldn't negotiate content for Accept headers %+v: we have content type %s", c.Request.Header.Get("Accepted"), content.ContentType)
+ c.AbortWithStatus(http.StatusNotAcceptable)
+ return
+ }
+
c.DataFromReader(http.StatusOK, content.ContentLength, content.ContentType, bytes.NewReader(content.Content), nil)
}