Change blacklist to comprise domains.

This commit is contained in:
2024-10-22 15:50:28 +03:00
parent cd60c1363b
commit 3c5206ae43
4 changed files with 13 additions and 10 deletions

View File

@@ -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
}

View File

@@ -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
}