mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-15 01:54:03 +02:00
feat: improved icon and category lookup mechanism
This commit is contained in:
parent
5fce4b445b
commit
8ef8015a7f
4 changed files with 45 additions and 29 deletions
|
@ -114,12 +114,18 @@ func fetchKnownIcon(ctx context.Context, url *IconURL) *FetchResult {
|
||||||
return fetchIconAbsolute(ctx, url.URL())
|
return fetchIconAbsolute(ctx, url.URL())
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchIcon(ctx context.Context, filetype, filename string) *FetchResult {
|
func fetchIcon(ctx context.Context, filename string) *FetchResult {
|
||||||
result := fetchKnownIcon(ctx, NewSelfhStIconURL(filename, filetype))
|
for _, fileType := range []string{"svg", "webp", "png"} {
|
||||||
if result.OK() {
|
result := fetchKnownIcon(ctx, NewSelfhStIconURL(filename, fileType))
|
||||||
return result
|
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 {
|
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
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
result := fetchIcon(ctx, "png", sanitizeName(r.Reference()))
|
for _, ref := range r.References() {
|
||||||
if !result.OK() {
|
result := fetchIcon(ctx, sanitizeName(ref))
|
||||||
if r, ok := r.(httpRoute); ok {
|
if result.OK() {
|
||||||
// fallback to parse html
|
storeIconCache(r.Key(), result)
|
||||||
result = findIconSlow(ctx, r, uri, nil)
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if result.OK() {
|
if r, ok := r.(httpRoute); ok {
|
||||||
storeIconCache(r.Key(), result)
|
// 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 {
|
func findIconSlow(ctx context.Context, r httpRoute, uri string, stack []string) *FetchResult {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
type route interface {
|
type route interface {
|
||||||
pool.Object
|
pool.Object
|
||||||
ProviderName() string
|
ProviderName() string
|
||||||
Reference() string
|
References() []string
|
||||||
TargetURL() *gpnet.URL
|
TargetURL() *gpnet.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,11 +243,14 @@ func (r *Route) TargetURL() *net.URL {
|
||||||
return r.ProxyURL
|
return r.ProxyURL
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Route) Reference() string {
|
func (r *Route) References() []string {
|
||||||
if r.Container != nil {
|
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.
|
// Name implements pool.Object.
|
||||||
|
@ -476,21 +479,24 @@ func (r *Route) FinalizeHomepageConfig() {
|
||||||
r.Homepage = r.Homepage.GetOverride(r.Alias)
|
r.Homepage = r.Homepage.GetOverride(r.Alias)
|
||||||
|
|
||||||
hp := r.Homepage
|
hp := r.Homepage
|
||||||
ref := r.Reference()
|
refs := r.References()
|
||||||
meta, ok := homepage.GetHomepageMeta(ref)
|
for _, ref := range refs {
|
||||||
if ok {
|
meta, ok := homepage.GetHomepageMeta(ref)
|
||||||
if hp.Name == "" {
|
if ok {
|
||||||
hp.Name = meta.DisplayName
|
if hp.Name == "" {
|
||||||
}
|
hp.Name = meta.DisplayName
|
||||||
if hp.Category == "" {
|
}
|
||||||
hp.Category = meta.Tag
|
if hp.Category == "" {
|
||||||
|
hp.Category = meta.Tag
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if hp.Name == "" {
|
if hp.Name == "" {
|
||||||
hp.Name = strutils.Title(
|
hp.Name = strutils.Title(
|
||||||
strings.ReplaceAll(
|
strings.ReplaceAll(
|
||||||
strings.ReplaceAll(ref, "-", " "),
|
strings.ReplaceAll(refs[0], "-", " "),
|
||||||
"_", " ",
|
"_", " ",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -498,8 +504,11 @@ func (r *Route) FinalizeHomepageConfig() {
|
||||||
|
|
||||||
if hp.Category == "" {
|
if hp.Category == "" {
|
||||||
if config.GetInstance().Value().Homepage.UseDefaultCategories {
|
if config.GetInstance().Value().Homepage.UseDefaultCategories {
|
||||||
if category, ok := homepage.PredefinedCategories[ref]; ok {
|
for _, ref := range refs {
|
||||||
hp.Category = category
|
if category, ok := homepage.PredefinedCategories[ref]; ok {
|
||||||
|
hp.Category = category
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ type (
|
||||||
ProviderName() string
|
ProviderName() string
|
||||||
TargetURL() *net.URL
|
TargetURL() *net.URL
|
||||||
HealthMonitor() health.HealthMonitor
|
HealthMonitor() health.HealthMonitor
|
||||||
Reference() string
|
References() []string
|
||||||
|
|
||||||
Started() bool
|
Started() bool
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue