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:
parent
e2ac4a20f8
commit
356ea3b3c2
1 changed files with 7 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue