mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2024-11-27 06:40:32 +00:00
[bugfix] Set appropriate cache-control when using presigned s3 links (#1480)
This commit is contained in:
parent
40bc03e717
commit
c223c7598d
2 changed files with 9 additions and 1 deletions
|
@ -88,7 +88,12 @@ func (m *Module) ServeFile(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if content.URL != nil {
|
if content.URL != nil {
|
||||||
// This is a non-local S3 file we're proxying to.
|
// This is a non-local S3 file we're redirecting to.
|
||||||
|
// Rewrite the cache control header to reflect the
|
||||||
|
// TTL of the generated signed link, instead of the
|
||||||
|
// default very long cache.
|
||||||
|
const cacheControl = "private,max-age=86400" // 24h
|
||||||
|
c.Header("Cache-Control", cacheControl)
|
||||||
c.Redirect(http.StatusFound, content.URL.String())
|
c.Redirect(http.StatusFound, content.URL.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,10 +232,13 @@ func (p *processor) getEmojiContent(ctx context.Context, fileName string, owning
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *processor) retrieveFromStorage(ctx context.Context, storagePath string, content *apimodel.Content) (*apimodel.Content, gtserror.WithCode) {
|
func (p *processor) retrieveFromStorage(ctx context.Context, storagePath string, content *apimodel.Content) (*apimodel.Content, gtserror.WithCode) {
|
||||||
|
// If running on S3 storage with proxying disabled then
|
||||||
|
// just fetch a pre-signed URL instead of serving the content.
|
||||||
if url := p.storage.URL(ctx, storagePath); url != nil {
|
if url := p.storage.URL(ctx, storagePath); url != nil {
|
||||||
content.URL = url
|
content.URL = url
|
||||||
return content, nil
|
return content, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
reader, err := p.storage.GetStream(ctx, storagePath)
|
reader, err := p.storage.GetStream(ctx, storagePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, gtserror.NewErrorNotFound(fmt.Errorf("error retrieving from storage: %s", err))
|
return nil, gtserror.NewErrorNotFound(fmt.Errorf("error retrieving from storage: %s", err))
|
||||||
|
|
Loading…
Reference in a new issue