summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Busby <contact@benbusby.com>2025-02-25 16:42:23 -0700
committerBen Busby <contact@benbusby.com>2025-02-25 16:42:23 -0700
commit356ea3b3c253f0de18b08fc418aa3b035e48b91e (patch)
tree48f4dafe109266e785ce856576a4ef01e4da5982
parente2ac4a20f8ad6026f37e95209ef1d6e2848aac11 (diff)
downloadfarside-356ea3b3c253f0de18b08fc418aa3b035e48b91e.tar.gz
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.
-rw-r--r--services/mappings.go8
1 files changed, 7 insertions, 1 deletions
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