From 356ea3b3c253f0de18b08fc418aa3b035e48b91e Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Tue, 25 Feb 2025 16:42:23 -0700 Subject: [PATCH] Use originally requested service if not using URL redirect The specified service (i.e. whoogle) should be used for the redirect if explicitly stated, rather than randomly fetching an instance for the provided URL. For instance: - farside.link/https://google.com/search?q=balatro can redirect to a whoogle or searxng instance. - farside.link/whoogle/search?q=balatro will always redirect to a whoogle instance. --- services/mappings.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/mappings.go b/services/mappings.go index aae36f5..d4c3a9d 100644 --- a/services/mappings.go +++ b/services/mappings.go @@ -4,6 +4,7 @@ import ( "errors" "math/rand" "regexp" + "strings" ) type RegexMapping struct { @@ -30,7 +31,7 @@ var regexMap = []RegexMapping{ { // Google Search Pattern: regexp.MustCompile(`google\.com|whoogle|searx|searxng`), - Targets: []string{"whoogle", "searx", "searxng"}, + Targets: []string{"whoogle", "searxng"}, }, { // Instagram @@ -122,12 +123,17 @@ var regexMap = []RegexMapping{ } func MatchRequest(service string) (string, error) { + for _, mapping := range regexMap { hasMatch := mapping.Pattern.MatchString(service) if !hasMatch { continue } + if !strings.Contains(service, ".") { + return service, nil + } + index := rand.Intn(len(mapping.Targets)) value := mapping.Targets[index] return value, nil