Compare commits
3 Commits
09e5a81227
...
aa22931786
Author | SHA1 | Date | |
---|---|---|---|
aa22931786 | |||
f2d9d450d0 | |||
023209c5d5 |
|
@ -373,11 +373,30 @@ func (b *memoryBackend) Fetch3(channel, fetchURL string) (*http.Response, error)
|
|||
return Fetch2(fetchURL)
|
||||
}
|
||||
|
||||
func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item microsub.Item) error {
|
||||
zchannelKey := fmt.Sprintf("zchannel:%s:posts", channel)
|
||||
func (b *memoryBackend) channelAddItemWithMatcher(conn redis.Conn, channel string, item microsub.Item) error {
|
||||
for channelKey, setting := range b.Settings {
|
||||
if setting.IncludeRegex != "" {
|
||||
included := false
|
||||
includeRegex, err := regexp.Compile(setting.IncludeRegex)
|
||||
if err != nil {
|
||||
log.Printf("error in regexp: %q\n", includeRegex)
|
||||
} else {
|
||||
if item.Content != nil && includeRegex.MatchString(item.Content.Text) {
|
||||
log.Printf("Included %#v\n", item)
|
||||
included = true
|
||||
}
|
||||
|
||||
var excludeRegex regexp.Regexp
|
||||
testExcludeRegex := false
|
||||
if includeRegex.MatchString(item.Name) {
|
||||
log.Printf("Included %#v\n", item)
|
||||
included = true
|
||||
}
|
||||
}
|
||||
|
||||
if included {
|
||||
b.channelAddItem(conn, channelKey, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if setting, e := b.Settings[channel]; e {
|
||||
if setting.ExcludeRegex != "" {
|
||||
|
@ -385,12 +404,6 @@ func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item mic
|
|||
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
|
||||
|
@ -401,6 +414,14 @@ func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item mic
|
|||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return b.channelAddItem(conn, channel, item)
|
||||
}
|
||||
|
||||
func (b *memoryBackend) channelAddItem(conn redis.Conn, channel string, item microsub.Item) error {
|
||||
zchannelKey := fmt.Sprintf("zchannel:%s:posts", channel)
|
||||
|
||||
if item.Published == "" {
|
||||
item.Published = time.Now().Format(time.RFC3339)
|
||||
|
|
|
@ -569,6 +569,18 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
h.Backend.Settings[uid] = setting
|
||||
}
|
||||
|
||||
includeRegex := r.FormValue("include_regex")
|
||||
|
||||
if setting, e := h.Backend.Settings[uid]; e {
|
||||
setting.IncludeRegex = includeRegex
|
||||
h.Backend.Settings[uid] = setting
|
||||
} else {
|
||||
setting = channelSetting{
|
||||
IncludeRegex: includeRegex,
|
||||
}
|
||||
h.Backend.Settings[uid] = setting
|
||||
}
|
||||
|
||||
h.Backend.Debug()
|
||||
|
||||
http.Redirect(w, r, "/settings", 302)
|
||||
|
|
|
@ -48,6 +48,7 @@ type memoryBackend struct {
|
|||
|
||||
type channelSetting struct {
|
||||
ExcludeRegex string
|
||||
IncludeRegex string
|
||||
}
|
||||
|
||||
type Debug interface {
|
||||
|
|
|
@ -57,10 +57,16 @@
|
|||
<input type="hidden" name="uid" value="{{ .CurrentChannel.UID }}" />
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<label class="label">Exclude regex</label>
|
||||
<label class="label">Blocking Regex</label>
|
||||
<input type="text" class="input" name="exclude_regex" value="{{ .CurrentSetting.ExcludeRegex }}" placeholder="enter regex to block" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<label class="label">Tracking Regex</label>
|
||||
<input type="text" class="input" name="include_regex" value="{{ .CurrentSetting.IncludeRegex }}" placeholder="enter regex to track items" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<button type="submit" class="button is-primary">Save</button>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user