Add dynamic favicon for trust center using file API

Use the trust center's logo as favicon via the public file API URL,
falling back to the default favicon when no logo is configured.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-18 20:15:31 +01:00
parent f01b28aad9
commit 1e5f4012f0
3 changed files with 16 additions and 6 deletions

View File

@@ -98,7 +98,7 @@ func NewServer(cfg Config) (*Server, error) {
return nil, err
}
trustWebServer, err := trust_web.NewServer(compliancePageHeadData(cfg.Trust))
trustWebServer, err := trust_web.NewServer(compliancePageHeadData(cfg.BaseURL, cfg.Trust))
if err != nil {
return nil, err
}
@@ -197,7 +197,7 @@ func (s *Server) TrustCenterHandler() http.Handler {
return r
}
func compliancePageHeadData(trustService *trust.Service) trust_web.HeadDataFunc {
func compliancePageHeadData(baseURL *baseurl.BaseURL, trustService *trust.Service) trust_web.HeadDataFunc {
return func(r *http.Request) trust_web.HeadData {
tc := compliancepage.CompliancePageFromContext(r.Context())
if tc == nil {
@@ -209,12 +209,21 @@ func compliancePageHeadData(trustService *trust.Service) trust_web.HeadDataFunc
return trust_web.HeadData{Title: "Compliance Page"}
}
baseURL := compliancepage.CompliancePageBaseURLFromContext(r.Context())
compliancePageBaseURL := compliancepage.CompliancePageBaseURLFromContext(r.Context())
return trust_web.HeadData{
headData := trust_web.HeadData{
Title: org.Name + " — Compliance",
Description: org.Name + " Compliance Page",
OGURL: ref.UnrefOrZero(baseURL),
OGURL: ref.UnrefOrZero(compliancePageBaseURL),
}
if tc.LogoFileID != nil {
faviconURL, err := baseURL.WithPath("/api/files/v1/" + tc.LogoFileID.String()).String()
if err == nil {
headData.FaviconURL = faviconURL
}
}
return headData
}
}

View File

@@ -31,6 +31,7 @@ type (
Title string
Description string
OGURL string
FaviconURL string
}
HeadDataFunc func(r *http.Request) HeadData