From 1abd1e257fe92ad51f958fd241eff73728122e07 Mon Sep 17 00:00:00 2001 From: yusing Date: Mon, 13 Jan 2025 00:15:10 +0800 Subject: [PATCH] fix favicon path and try dashboard icon first then fallback to html parsing --- internal/api/v1/favicon/favicon.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/api/v1/favicon/favicon.go b/internal/api/v1/favicon/favicon.go index d04c65b..508da98 100644 --- a/internal/api/v1/favicon/favicon.go +++ b/internal/api/v1/favicon/favicon.go @@ -174,10 +174,14 @@ func findIcon(r route.HTTPRoute, req *http.Request, uri string) (icon []byte, st return icon, http.StatusOK, "" } - icon, status, errMsg = findIconSlow(r, req, uri) + icon, status, errMsg = getIconAbsolute(homepage.DashboardIconBaseURL + "png/" + sanitizeName(r.TargetName()) + ".png") + cont := r.RawEntry().Container + if icon == nil && cont != nil { + icon, status, errMsg = getIconAbsolute(homepage.DashboardIconBaseURL + "png/" + sanitizeName(cont.ImageName) + ".png") + } if icon == nil { - // fallback to dashboard icon - icon, status, errMsg = getIconAbsolute(homepage.DashboardIconBaseURL + "png/" + sanitizeName(r.TargetName()) + ".png") + // fallback to parse html + icon, status, errMsg = findIconSlow(r, req, uri) } // set even if error (nil) storeIconCache(key, icon) @@ -190,6 +194,9 @@ func findIconSlow(r route.HTTPRoute, req *http.Request, uri string) (icon []byte defer cancel() newReq := req.WithContext(ctx) newReq.Header.Set("Accept-Encoding", "identity") // disable compression + if !strings.HasPrefix(uri, "/") { + uri = "/" + uri + } u, err := url.ParseRequestURI(uri) if err != nil { logging.Error().Err(err).