blob: 5ee548e96b917409eac8e5a03e68c00525315d1c (
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
|
package util
import (
"regexp"
"strings"
)
func IsOnion(url string) bool {
re := regexp.MustCompile(`\.onion`)
if re.MatchString(url) {
return true
}
return false
}
func GetActorInstance(path string) (string, string) {
re := regexp.MustCompile(`([@]?([\w\d.-_]+)[@](.+))`)
atFormat := re.MatchString(path)
if atFormat {
match := re.FindStringSubmatch(path)
if len(match) > 2 {
return match[2], match[3]
}
}
re = regexp.MustCompile(`(https?://)(www)?([\w\d-_.:]+)(/|\s+|\r|\r\n)?$`)
mainActor := re.MatchString(path)
if mainActor {
match := re.FindStringSubmatch(path)
if len(match) > 2 {
return "main", match[3]
}
}
re = regexp.MustCompile(`(https?://)?(www)?([\w\d-_.:]+)\/([\w\d-_.]+)(\/([\w\d-_.]+))?`)
httpFormat := re.MatchString(path)
if httpFormat {
match := re.FindStringSubmatch(path)
if len(match) > 3 {
if match[4] == "users" {
return match[6], match[3]
}
return match[4], match[3]
}
}
return "", ""
}
func GetActorFollowNameFromPath(path string) string {
var actor string
re := regexp.MustCompile("f\\w+-")
actor = re.FindString(path)
actor = strings.Replace(actor, "f", "", 1)
actor = strings.Replace(actor, "-", "", 1)
return actor
}
|