Add cache control to Files API static assets
Brand assets served at /api/files/v1/static had no cache headers. Introduce brand.Assets to own the embedded filesystem, content-hash ETags, and HTTP serving. Responses now carry Cache-Control and ETag so clients can cache and revalidate; stable email URLs stay revalidatable (max-age=3600, no immutable). Replace hardcoded Default*Path constants with StaticPathPrefix, logical filename constants, and StaticPath(). NewAssets validates required assets at startup so a rename fails fast instead of 404ing in sent emails. The files handler keeps routing and 404 rendering; ServeAssets sets cache headers and serves the file. Signed-off-by: Ludovic Vielle <ludovic@probo.com>
This commit is contained in:
@@ -2,24 +2,18 @@ package brand
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed assets
|
||||
staticAssets embed.FS
|
||||
//go:embed assets
|
||||
var staticAssets embed.FS
|
||||
|
||||
Assets fs.FS
|
||||
|
||||
DefaultPoweredByLogoPath string = "/api/files/v1/static/probo-gray-small.png"
|
||||
DefaultSenderCompanyLogoPath string = "/api/files/v1/static/probo.png"
|
||||
// Logical brand assets. These filenames must exist under assets/; NewAssets
|
||||
// verifies their presence at startup so a rename or removal fails fast instead
|
||||
// of silently producing a 404 in the consumers (e.g. emails).
|
||||
const (
|
||||
PoweredByLogo = "probo-gray-small.png"
|
||||
SenderCompanyLogo = "probo.png"
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
Assets, err = fs.Sub(staticAssets, "assets")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
// requiredAssets are validated to exist whenever an Assets is constructed.
|
||||
var requiredAssets = []string{PoweredByLogo, SenderCompanyLogo}
|
||||
|
||||
Reference in New Issue
Block a user