diff --git a/internal/homepage/favicon.go b/internal/homepage/favicon.go index e611022..945a547 100644 --- a/internal/homepage/favicon.go +++ b/internal/homepage/favicon.go @@ -114,12 +114,18 @@ func fetchKnownIcon(ctx context.Context, url *IconURL) *FetchResult { return fetchIconAbsolute(ctx, url.URL()) } -func fetchIcon(ctx context.Context, filetype, filename string) *FetchResult { - result := fetchKnownIcon(ctx, NewSelfhStIconURL(filename, filetype)) - if result.OK() { - return result +func fetchIcon(ctx context.Context, filename string) *FetchResult { + for _, fileType := range []string{"svg", "webp", "png"} { + result := fetchKnownIcon(ctx, NewSelfhStIconURL(filename, fileType)) + if result.OK() { + return result + } + result = fetchKnownIcon(ctx, NewWalkXCodeIconURL(filename, fileType)) + if result.OK() { + return result + } } - return fetchKnownIcon(ctx, NewWalkXCodeIconURL(filename, filetype)) + return &FetchResult{StatusCode: http.StatusNotFound, ErrMsg: "no icon found"} } func FindIcon(ctx context.Context, r route, uri string) *FetchResult { @@ -127,17 +133,18 @@ func FindIcon(ctx context.Context, r route, uri string) *FetchResult { return result } - result := fetchIcon(ctx, "png", sanitizeName(r.Reference())) - if !result.OK() { - if r, ok := r.(httpRoute); ok { - // fallback to parse html - result = findIconSlow(ctx, r, uri, nil) + for _, ref := range r.References() { + result := fetchIcon(ctx, sanitizeName(ref)) + if result.OK() { + storeIconCache(r.Key(), result) + return result } } - if result.OK() { - storeIconCache(r.Key(), result) + if r, ok := r.(httpRoute); ok { + // fallback to parse html + return findIconSlow(ctx, r, uri, nil) } - return result + return &FetchResult{StatusCode: http.StatusNotFound, ErrMsg: "no icon found"} } func findIconSlow(ctx context.Context, r httpRoute, uri string, stack []string) *FetchResult { diff --git a/internal/homepage/route.go b/internal/homepage/route.go index 9c5aa56..2c0e712 100644 --- a/internal/homepage/route.go +++ b/internal/homepage/route.go @@ -10,7 +10,7 @@ import ( type route interface { pool.Object ProviderName() string - Reference() string + References() []string TargetURL() *gpnet.URL } diff --git a/internal/route/route.go b/internal/route/route.go index f8f70d4..62a1ad5 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -243,11 +243,14 @@ func (r *Route) TargetURL() *net.URL { return r.ProxyURL } -func (r *Route) Reference() string { +func (r *Route) References() []string { if r.Container != nil { - return r.Container.Image.Name + if r.Container.ContainerName != r.Alias { + return []string{r.Container.Image.Name, r.Container.ContainerName, r.Alias, r.Container.Image.Author} + } + return []string{r.Container.Image.Name, r.Alias, r.Container.Image.Author} } - return r.Alias + return []string{r.Alias} } // Name implements pool.Object. @@ -476,21 +479,24 @@ func (r *Route) FinalizeHomepageConfig() { r.Homepage = r.Homepage.GetOverride(r.Alias) hp := r.Homepage - ref := r.Reference() - meta, ok := homepage.GetHomepageMeta(ref) - if ok { - if hp.Name == "" { - hp.Name = meta.DisplayName - } - if hp.Category == "" { - hp.Category = meta.Tag + refs := r.References() + for _, ref := range refs { + meta, ok := homepage.GetHomepageMeta(ref) + if ok { + if hp.Name == "" { + hp.Name = meta.DisplayName + } + if hp.Category == "" { + hp.Category = meta.Tag + } + break } } if hp.Name == "" { hp.Name = strutils.Title( strings.ReplaceAll( - strings.ReplaceAll(ref, "-", " "), + strings.ReplaceAll(refs[0], "-", " "), "_", " ", ), ) @@ -498,8 +504,11 @@ func (r *Route) FinalizeHomepageConfig() { if hp.Category == "" { if config.GetInstance().Value().Homepage.UseDefaultCategories { - if category, ok := homepage.PredefinedCategories[ref]; ok { - hp.Category = category + for _, ref := range refs { + if category, ok := homepage.PredefinedCategories[ref]; ok { + hp.Category = category + break + } } } diff --git a/internal/route/routes/route.go b/internal/route/routes/route.go index 13bd686..b87b4d2 100644 --- a/internal/route/routes/route.go +++ b/internal/route/routes/route.go @@ -25,7 +25,7 @@ type ( ProviderName() string TargetURL() *net.URL HealthMonitor() health.HealthMonitor - Reference() string + References() []string Started() bool