Change blacklist to comprise domains.
This commit is contained in:
@@ -1,18 +1,22 @@
|
||||
package gemini
|
||||
|
||||
import "strings"
|
||||
import "gemini-grc/logging"
|
||||
|
||||
var Blacklist *[]string
|
||||
|
||||
func InBlacklist(s *Snapshot) bool {
|
||||
if Blacklist == nil {
|
||||
data := ReadLines("blacklist.txt")
|
||||
data := ReadLines("blacklists/domains.txt")
|
||||
Blacklist = &data
|
||||
logging.LogInfo("Loaded %d blacklisted domains", len(*Blacklist))
|
||||
}
|
||||
for _, l := range *Blacklist {
|
||||
if strings.HasPrefix(s.URL.String(), l) {
|
||||
if s.Host == l {
|
||||
return true
|
||||
}
|
||||
// if strings.HasPrefix(s.URL.String(), l) {
|
||||
// return true
|
||||
// }
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func SaveToFile(rootPath string, s *Snapshot, done chan struct{}) {
|
||||
func ReadLines(path string) []string {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Failed to read blacklist file: %s", err))
|
||||
panic(fmt.Sprintf("Failed to read file: %s", err))
|
||||
}
|
||||
lines := strings.Split(string(data), "\n")
|
||||
// Remove last line if empty
|
||||
@@ -108,6 +108,5 @@ func ReadLines(path string) []string {
|
||||
if lines[len(lines)-1] == "" {
|
||||
lines = lines[:len(lines)-1]
|
||||
}
|
||||
logging.LogInfo("Loaded %d blacklist URLs", len(lines))
|
||||
return lines
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user