Add improve logging and handling of errors

This commit is contained in:
Peter Stuifzand 2018-03-28 02:08:20 +02:00
parent 3cc34dbfe8
commit 7b867434f6
2 changed files with 8 additions and 2 deletions

View File

@ -303,10 +303,10 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
jw.Encode(map[string][]microsub.Feed{
"results": feeds,
})
} else if action == "timeline" {
} else if action == "timeline" || r.PostForm.Get("action") == "timeline" {
method := values.Get("method")
if method == "mark_read" {
if method == "mark_read" || r.PostForm.Get("method") == "mark_read" {
values = r.PostForm
channel := values.Get("channel")
if uids, e := values["entry"]; e {
@ -315,7 +315,11 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.Backend.MarkRead(channel, uids)
} else if uids, e := values["entry[0]"]; e {
h.Backend.MarkRead(channel, uids)
} else {
log.Println("timeline mark_read value not found")
}
} else {
log.Println("unknown method in timeline %s")
}
w.Header().Add("Content-Type", "application/json")
fmt.Fprintln(w, "[]")

View File

@ -273,8 +273,10 @@ func (b *memoryBackend) PreviewURL(previewURL string) microsub.Timeline {
}
func (b *memoryBackend) MarkRead(channel string, itemUids []string) {
log.Printf("Marking read for %s %v\n", channel, itemUids)
args := redis.Args{}.Add(fmt.Sprintf("timeline:%s:read", channel)).AddFlat(itemUids)
if _, err := b.Redis.Do("SADD", args...); err != nil {
log.Printf("Marking read for channel %s has failed\n", channel)
}
log.Printf("Marking read success for %s %v\n", channel, itemUids)
}