Add testing of ExcludeRegex
This commit is contained in:
parent
acf0721ba5
commit
09e5a81227
|
@ -29,6 +29,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"regexp"
|
||||||
"rss"
|
"rss"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -375,6 +376,32 @@ func (b *memoryBackend) Fetch3(channel, fetchURL string) (*http.Response, error)
|
||||||
func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item microsub.Item) error {
|
func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item microsub.Item) error {
|
||||||
zchannelKey := fmt.Sprintf("zchannel:%s:posts", channel)
|
zchannelKey := fmt.Sprintf("zchannel:%s:posts", channel)
|
||||||
|
|
||||||
|
var excludeRegex regexp.Regexp
|
||||||
|
testExcludeRegex := false
|
||||||
|
|
||||||
|
if setting, e := b.Settings[channel]; e {
|
||||||
|
if setting.ExcludeRegex != "" {
|
||||||
|
excludeRegex, err := regexp.Compile(setting.ExcludeRegex)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error in regexp: %q\n", excludeRegex)
|
||||||
|
} else {
|
||||||
|
testExcludeRegex = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if testExcludeRegex {
|
||||||
|
if item.Content != nil && excludeRegex.MatchString(item.Content.Text) {
|
||||||
|
log.Printf("Excluded %#v\n", item)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if excludeRegex.MatchString(item.Name) {
|
||||||
|
log.Printf("Excluded %#v\n", item)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if item.Published == "" {
|
if item.Published == "" {
|
||||||
item.Published = time.Now().Format(time.RFC3339)
|
item.Published = time.Now().Format(time.RFC3339)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user