mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-01 22:12:25 -05:00
[bugfix] Set cache-control max-age dynamically for s3 (#1510)
* [bugfix] set cache-control max-age dynamically for s3 * woops * double whoops * time until, thank you linter, bless you, you're the best, no matter what kim says * aa
This commit is contained in:
parent
40b584c219
commit
6ee0dc8c7d
4 changed files with 42 additions and 29 deletions
|
|
@ -24,6 +24,7 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"codeberg.org/gruf/go-fastcopy"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
@ -89,6 +90,10 @@ func (m *Module) ServeFile(c *gin.Context) {
|
|||
|
||||
if content.URL != nil {
|
||||
// This is a non-local, non-proxied S3 file we're redirecting to.
|
||||
// Derive the max-age value from how long the link has left until
|
||||
// it expires.
|
||||
maxAge := int(time.Until(content.URL.Expiry).Seconds())
|
||||
c.Header("Cache-Control", "private,max-age="+strconv.Itoa(maxAge))
|
||||
c.Redirect(http.StatusFound, content.URL.String())
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue