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
package logic

import (
	"bufio"
	"os"
	"rss_parrot/shared"
	"strings"
)

type IBlockedFeeds interface {
	IsBlocked(feedUrl string) (bool, error)
}

type blockedFeeds struct {
	cfg *shared.Config
}

func NewBlockedFeeds(cfg *shared.Config) IBlockedFeeds {
	return &blockedFeeds{cfg}
}

func (bf *blockedFeeds) IsBlocked(feedUrl string) (bool, error) {

	feedUrl = strings.ToLower(feedUrl)
	feedUrl = strings.TrimPrefix(feedUrl, "https://")
	feedUrl = strings.TrimPrefix(feedUrl, "http://")
	readFile, err := os.Open(bf.cfg.BlockedFeedsFile)
	if err != nil {
		return false, err
	}
	defer readFile.Close()
	fileScanner := bufio.NewScanner(readFile)
	fileScanner.Split(bufio.ScanLines)

	for fileScanner.Scan() {
		line := fileScanner.Text()
		if feedUrl == line {
			return true, nil
		}
	}
	return false, nil
}