/
validator.go
61 lines (51 loc) 路 1.13 KB
/
validator.go
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
package validator
import "strings"
func GetErrorMessage(title, domain string) string {
if strings.Contains(title, "[video]") {
return "Reader Mode not supported for videos"
}
if strings.Contains(title, "[pdf]") {
return "Reader Mode not supported for PDFs"
}
if strings.Contains(title, "[audio]") {
return "Reader Mode not supported for audio"
}
if isInvalidDomain(domain) {
return "Reader Mode not supported for this domain"
}
if domain == "" {
return "Reader Mode only supported on submissions with link"
}
return ""
}
func isInvalidDomain(domain string) bool {
invalidDomains := [...]string{
"scmp.com",
"blog.chromium.org",
"bloomberg.com",
"chrome.google.com",
"drive.google.com",
"facebook.com",
"gizmodo.com",
"jalopnik.com",
"marketplace.atlassian.com",
"newsweek.com",
"npr.org",
"old.reddit.com",
"play.google.com",
"reddit.com",
"sciencedirect.com",
"security.googleblog.com",
"twitter.com",
"washingtonpost.com",
"wsj.com",
"xkcd.com",
"youtube.com",
}
for _, invalidDomain := range invalidDomains {
if domain == invalidDomain {
return true
}
}
return false
}