mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-08-28 11:56:19 +00:00
Treat wildcard domains and preview domains as public suffixes.
This commit is contained in:
+1
-6
@@ -4,8 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/publicsuffix"
|
||||
)
|
||||
|
||||
type StorageSize struct {
|
||||
@@ -32,10 +30,7 @@ func AnalyzeStorage(ctx context.Context) ([]*StorageSize, error) {
|
||||
thinStats := []*StorageSize{}
|
||||
|
||||
getStats := func(domain string) *storageData {
|
||||
eTLDPlusOne, err := publicsuffix.EffectiveTLDPlusOne(domain)
|
||||
if err == nil {
|
||||
domain = eTLDPlusOne
|
||||
}
|
||||
domain = EffectiveTLDPlusOne(domain)
|
||||
if _, found := thickStats[domain]; !found {
|
||||
thickStats[domain] = &storageData{
|
||||
siteBlobs: map[string]int64{},
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package git_pages
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/publicsuffix"
|
||||
)
|
||||
|
||||
func EffectiveTLDPlusOne(domain string) string {
|
||||
domainParts := strings.Split(domain, ".")
|
||||
for _, pattern := range wildcards {
|
||||
for _, suffix := range [][]string{pattern.PreviewDomain, pattern.Domain} {
|
||||
if len(domainParts) < len(suffix)+1 {
|
||||
continue
|
||||
}
|
||||
if slices.Equal(domainParts[len(domainParts)-len(suffix):], suffix) {
|
||||
return strings.Join(domainParts[len(domainParts)-len(suffix)-1:], ".")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result, err := publicsuffix.EffectiveTLDPlusOne(domain)
|
||||
if err == nil {
|
||||
return result
|
||||
}
|
||||
|
||||
return domain
|
||||
}
|
||||
Reference in New Issue
Block a user