summaryrefslogtreecommitdiff
path: root/services/mappings.go
blob: 53731a6182c226262cb7be99004aa9094477cb9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package services

import (
	"errors"
	"math/rand"
	"regexp"
)

type RegexMapping struct {
	Pattern *regexp.Regexp
	Targets []string
}

var regexMap = []RegexMapping{
	{
		// YouTube
		Pattern: regexp.MustCompile(`youtu(\.be|be\.com)|invidious|piped`),
		Targets: []string{"piped", "invidious"},
	},
	{
		// Twitter / X
		Pattern: regexp.MustCompile(`twitter\.com|x\.com|nitter`),
		Targets: []string{"nitter"},
	},
	{
		// Reddit
		Pattern: regexp.MustCompile(`reddit\.com|libreddit|redlib`),
		Targets: []string{"libreddit", "redlib"},
	},
	{
		// Google Search
		Pattern: regexp.MustCompile(`google\.com|whoogle|searx|searxng`),
		Targets: []string{"whoogle", "searx", "searxng"},
	},
	{
		// Instagram
		Pattern: regexp.MustCompile(`instagram\.com|proxigram`),
		Targets: []string{"proxigram"},
	},
	{
		// Wikipedia
		Pattern: regexp.MustCompile(`wikipedia\.org|wikiless`),
		Targets: []string{"wikiless"},
	},
	{
		// Medium
		Pattern: regexp.MustCompile(`medium\.com|scribe`),
		Targets: []string{"scribe"},
	},
	{
		// Odysee
		Pattern: regexp.MustCompile(`odysee\.com|librarian`),
		Targets: []string{"librarian"},
	},
	{
		// Imgur
		Pattern: regexp.MustCompile(`imgur\.com|rimgo`),
		Targets: []string{"rimgo"},
	},
	{
		// Google Translate
		Pattern: regexp.MustCompile(`translate\.google\.com|lingva`),
		Targets: []string{"lingva"},
	},
	{
		// TikTok
		Pattern: regexp.MustCompile(`tiktok\.com|proxitok`),
		Targets: []string{"proxitok"},
	},
	{
		// Fandom
		Pattern: regexp.MustCompile(`fandom\.com|breezewiki`),
		Targets: []string{"breezewiki"},
	},
	{
		// IMDB
		Pattern: regexp.MustCompile(`imdb\.com|libremdb`),
		Targets: []string{"libremdb"},
	},
	{
		// Quora
		Pattern: regexp.MustCompile(`quora\.com|quetre`),
		Targets: []string{"quetre"},
	},
	{
		// GitHub
		Pattern: regexp.MustCompile(`github\.com|gothub`),
		Targets: []string{"gothub"},
	},
	{
		// StackOverflow
		Pattern: regexp.MustCompile(`stackoverflow\.com|anonymousoverflow`),
		Targets: []string{"anonymousoverflow"},
	},
}

func MatchRequest(service string) (string, error) {
	for _, mapping := range regexMap {
		hasMatch := mapping.Pattern.MatchString(service)
		if !hasMatch {
			continue
		}

		index := rand.Intn(len(mapping.Targets))
		value := mapping.Targets[index]
		return value, nil
	}

	return "", errors.New("no match found")
}