package web
import (
"crypto/sha256"
_ "embed"
"encoding/hex"
"strings"
"craftdesign.group/quarry/internal/api"
)
// The badge Gmail shows in place of the wordmark text: the Q logo and the
// QUARRY wordmark in cream on the logo's dark tile. It was rendered in a
// browser from the page's own header SVG (the Q's tail included) and cut
// to alpha by matting over black and white, then taken at 2x of the two
// sizes the header (92x28) and the footer (59x18) show. It reads in both
// of Gmail's modes, neither of which reports dark to the message.
//
//go:embed assets/badge.png
var badgePNG []byte
//go:embed assets/badge-sm.png
var badgeSmPNG []byte
// AssetVersion is the short content hash of an image a message refers to,
// by site path ("/apple-touch-icon.png", "/badge.png", "/icons/x.png"). A
// mail client caches an image by its URL, so the URL has to change when
// the bytes do. "" for a path with no such image.
func AssetVersion(path string) string {
var b []byte
switch {
case path == "/apple-touch-icon.png":
b = appleTouchIcon
case path == "/badge.png":
b = badgePNG
case path == "/badge-sm.png":
b = badgeSmPNG
case strings.HasPrefix(path, "/icons/"):
b, _ = refIcons.ReadFile("assets/icons/" + strings.TrimPrefix(path, "/icons/"))
}
if b == nil {
return ""
}
sum := sha256.Sum256(b)
return hex.EncodeToString(sum[:])[:8]
}
func init() { api.AssetVersion = AssetVersion }