refactor(routes): remove old HomepageCategories method

This commit is contained in:
yusing
2025-09-14 00:11:32 +08:00
parent 6077a1d70b
commit b72f3bde53

View File

@@ -4,11 +4,8 @@ import (
"encoding/json"
"fmt"
"math"
"net/url"
"strings"
"time"
"github.com/yusing/go-proxy/internal/homepage"
"github.com/yusing/go-proxy/internal/types"
)
@@ -78,71 +75,6 @@ func getHealthInfo(r types.Route) *HealthInfo {
}
}
func HomepageCategories() []string {
check := make(map[string]struct{})
categories := make([]string, 0)
for _, r := range HTTP.Iter {
item := r.HomepageConfig()
if item == nil || item.Category == "" {
continue
}
if _, ok := check[item.Category]; ok {
continue
}
check[item.Category] = struct{}{}
categories = append(categories, item.Category)
}
return categories
}
func HomepageItems(proto, hostname, categoryFilter, providerFilter string) homepage.Homepage {
switch proto {
case "http", "https":
default:
proto = "http"
}
hp := make(homepage.Homepage)
if strings.Count(hostname, ".") > 1 {
_, hostname, _ = strings.Cut(hostname, ".") // remove the subdomain
}
for _, r := range HTTP.Iter {
if providerFilter != "" && r.ProviderName() != providerFilter {
continue
}
item := *r.HomepageItem()
if categoryFilter != "" && item.Category != categoryFilter {
continue
}
// clear url if invalid
_, err := url.Parse(item.URL)
if err != nil {
item.URL = ""
}
// append hostname if provided and only if alias is not FQDN
if hostname != "" && item.URL == "" {
isFQDNAlias := strings.Contains(item.Alias, ".")
if !isFQDNAlias {
item.URL = fmt.Sprintf("%s://%s.%s", proto, item.Alias, hostname)
} else {
item.URL = fmt.Sprintf("%s://%s", proto, item.Alias)
}
}
// prepend protocol if not exists
if !strings.HasPrefix(item.URL, "http://") && !strings.HasPrefix(item.URL, "https://") {
item.URL = fmt.Sprintf("%s://%s", proto, item.URL)
}
hp.Add(&item)
}
return hp
}
func ByProvider() map[string][]types.Route {
rts := make(map[string][]types.Route)
for r := range Iter {