fix(homepage): incorrect url

- fixed url being overridden
- fixed sub-subdomain being stripped
- fixed empty url for routes with FQDN aliases
This commit is contained in:
yusing
2025-08-19 21:01:04 +08:00
parent dfe0014609
commit a057f0e956
2 changed files with 11 additions and 6 deletions

View File

@@ -45,6 +45,7 @@ func (c *OverrideConfig) GetOverride(alias string, item *ItemConfig) *ItemConfig
c.mu.RLock() c.mu.RLock()
defer c.mu.RUnlock() defer c.mu.RUnlock()
if itemOverride, hasOverride := c.ItemOverrides[alias]; hasOverride { if itemOverride, hasOverride := c.ItemOverrides[alias]; hasOverride {
itemOverride.URL = item.URL // NOTE: we don't want to override the URL
item = itemOverride item = itemOverride
} }
if show, ok := c.ItemVisibility[alias]; ok { if show, ok := c.ItemVisibility[alias]; ok {

View File

@@ -104,11 +104,15 @@ func HomepageItems(proto, hostname, categoryFilter, providerFilter string) homep
hp := make(homepage.Homepage) hp := make(homepage.Homepage)
if strings.Count(hostname, ".") > 1 {
_, hostname, _ = strings.Cut(hostname, ".") // remove the subdomain
}
for _, r := range HTTP.Iter { for _, r := range HTTP.Iter {
if providerFilter != "" && r.ProviderName() != providerFilter { if providerFilter != "" && r.ProviderName() != providerFilter {
continue continue
} }
item := r.HomepageItem() item := *r.HomepageItem()
if categoryFilter != "" && item.Category != categoryFilter { if categoryFilter != "" && item.Category != categoryFilter {
continue continue
} }
@@ -121,11 +125,11 @@ func HomepageItems(proto, hostname, categoryFilter, providerFilter string) homep
// append hostname if provided and only if alias is not FQDN // append hostname if provided and only if alias is not FQDN
if hostname != "" && item.URL == "" { if hostname != "" && item.URL == "" {
if !strings.Contains(item.Alias, ".") { isFQDNAlias := strings.Contains(item.Alias, ".")
if strings.Count(hostname, ".") > 1 { if !isFQDNAlias {
_, hostname, _ = strings.Cut(hostname, ".") // remove the subdomain
}
item.URL = fmt.Sprintf("%s://%s.%s", proto, item.Alias, hostname) item.URL = fmt.Sprintf("%s://%s.%s", proto, item.Alias, hostname)
} else {
item.URL = fmt.Sprintf("%s://%s", proto, item.Alias)
} }
} }
@@ -134,7 +138,7 @@ func HomepageItems(proto, hostname, categoryFilter, providerFilter string) homep
item.URL = fmt.Sprintf("%s://%s", proto, item.URL) item.URL = fmt.Sprintf("%s://%s", proto, item.URL)
} }
hp.Add(item) hp.Add(&item)
} }
return hp return hp
} }