Add deduplication of strings in link rewriting process in main.go to ensure unique links are returned, enhancing link handling efficiency.
Publish telemt-bot Docker image / build-and-push (push) Successful in 55s
Publish telemt-bot Docker image / build-and-push (push) Successful in 55s
This commit is contained in:
@@ -389,6 +389,22 @@ func hasAnyLinks(links userLinks) bool {
|
||||
// serverParamRe matches server=... in tg://proxy URLs
|
||||
var serverParamRe = regexp.MustCompile(`server=[^&]+`)
|
||||
|
||||
func deduplicateStrings(items []string) []string {
|
||||
if len(items) <= 1 {
|
||||
return items
|
||||
}
|
||||
seen := make(map[string]struct{}, len(items))
|
||||
out := make([]string, 0, len(items))
|
||||
for _, s := range items {
|
||||
if _, ok := seen[s]; ok {
|
||||
continue
|
||||
}
|
||||
seen[s] = struct{}{}
|
||||
out = append(out, s)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (b *bot) rewriteLinksWithHost(links userLinks) userLinks {
|
||||
host := strings.TrimSpace(b.cfg.TelemtLinkHost)
|
||||
if host == "" {
|
||||
@@ -403,7 +419,7 @@ func (b *bot) rewriteLinksWithHost(links userLinks) userLinks {
|
||||
for i, s := range items {
|
||||
out[i] = serverParamRe.ReplaceAllString(s, replacement)
|
||||
}
|
||||
return out
|
||||
return deduplicateStrings(out)
|
||||
}
|
||||
return userLinks{
|
||||
Classic: rewrite(links.Classic),
|
||||
|
||||
Reference in New Issue
Block a user