summaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/client/fileserver/servefile.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/internal/api/client/fileserver/servefile.go b/internal/api/client/fileserver/servefile.go
index 0858af3ce..236a2d8ac 100644
--- a/internal/api/client/fileserver/servefile.go
+++ b/internal/api/client/fileserver/servefile.go
@@ -85,20 +85,22 @@ func (m *FileServer) ServeFile(c *gin.Context) {
return
}
- if content.URL != nil {
- c.Redirect(http.StatusFound, content.URL.String())
- return
- }
-
defer func() {
- // if the content is a ReadCloser, close it when we're done
- if closer, ok := content.Content.(io.ReadCloser); ok {
- if err := closer.Close(); err != nil {
- log.Errorf("ServeFile: error closing readcloser: %s", err)
+ // if the content is a ReadCloser (ie., it's streamed from storage), close it when we're done
+ if content.Content != nil {
+ if closer, ok := content.Content.(io.ReadCloser); ok {
+ if err := closer.Close(); err != nil {
+ log.Errorf("ServeFile: error closing readcloser: %s", err)
+ }
}
}
}()
+ if content.URL != nil {
+ c.Redirect(http.StatusFound, content.URL.String())
+ return
+ }
+
// TODO: 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.