1
0
Fork 0
mirror of https://github.com/benbusby/farside.git synced 2025-04-25 13:10:02 +00:00

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.
This commit is contained in:
Ben Busby 2025-02-25 16:42:23 -07:00
parent e2ac4a20f8
commit 356ea3b3c2
No known key found for this signature in database
GPG key ID: B9B7231E01D924A1

View file

@ -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