Improve handling of authors and checkins
This commit is contained in:
parent
04841aa652
commit
9c7d11cb68
|
|
@ -156,7 +156,6 @@ func (b *memoryBackend) feedHeader(fetchURL, contentType string, body io.Reader)
|
||||||
log.Printf("Error while parsing rss/atom feed: %s\n", err)
|
log.Printf("Error while parsing rss/atom feed: %s\n", err)
|
||||||
return feed, err
|
return feed, err
|
||||||
}
|
}
|
||||||
log.Printf("%#v\n", xfeed)
|
|
||||||
|
|
||||||
feed.Type = "feed"
|
feed.Type = "feed"
|
||||||
feed.Name = xfeed.Title
|
feed.Name = xfeed.Title
|
||||||
|
|
@ -258,7 +257,7 @@ func (b *memoryBackend) feedItems(fetchURL, contentType string, body io.Reader)
|
||||||
return items, err
|
return items, err
|
||||||
}
|
}
|
||||||
|
|
||||||
author := microsub.Author{}
|
author := microsub.Card{}
|
||||||
author.Type = "card"
|
author.Type = "card"
|
||||||
author.Name = feed.Author.Name
|
author.Name = feed.Author.Name
|
||||||
author.URL = feed.Author.URL
|
author.URL = feed.Author.URL
|
||||||
|
|
@ -428,8 +427,6 @@ func Fetch2(fetchURL string) (*http.Response, error) {
|
||||||
cur := b.Bytes()
|
cur := b.Bytes()
|
||||||
copy(cachedCopy, cur)
|
copy(cachedCopy, cur)
|
||||||
|
|
||||||
log.Println(string(cachedCopy))
|
|
||||||
|
|
||||||
cache[u.String()] = cacheItem{item: cachedCopy, created: time.Now()}
|
cache[u.String()] = cacheItem{item: cachedCopy, created: time.Now()}
|
||||||
|
|
||||||
cachedResp, err := http.ReadResponse(bufio.NewReader(bytes.NewReader(cachedCopy)), req)
|
cachedResp, err := http.ReadResponse(bufio.NewReader(bytes.NewReader(cachedCopy)), req)
|
||||||
|
|
@ -465,7 +462,7 @@ func Fetch(fetchURL string) []microsub.Item {
|
||||||
jw.SetIndent("", " ")
|
jw.SetIndent("", " ")
|
||||||
jw.Encode(data)
|
jw.Encode(data)
|
||||||
|
|
||||||
author := microsub.Author{}
|
author := microsub.Card{}
|
||||||
|
|
||||||
for _, item := range data.Items {
|
for _, item := range data.Items {
|
||||||
if item.Type[0] == "h-feed" {
|
if item.Type[0] == "h-feed" {
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,10 @@ type Debug interface {
|
||||||
Debug()
|
Debug()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime)
|
||||||
|
}
|
||||||
|
|
||||||
func (b *memoryBackend) Debug() {
|
func (b *memoryBackend) Debug() {
|
||||||
fmt.Println(b.Channels)
|
fmt.Println(b.Channels)
|
||||||
}
|
}
|
||||||
|
|
@ -165,17 +169,29 @@ func (b *memoryBackend) ChannelsDelete(uid string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapToAuthor(result map[string]interface{}) microsub.Author {
|
func mapToAuthor(result map[string]string) microsub.Card {
|
||||||
item := microsub.Author{}
|
item := microsub.Card{}
|
||||||
item.Type = "card"
|
item.Type = "card"
|
||||||
if name, e := result["name"]; e {
|
if name, e := result["name"]; e {
|
||||||
item.Name = name.(string)
|
item.Name = name
|
||||||
}
|
}
|
||||||
if u, e := result["url"]; e {
|
if u, e := result["url"]; e {
|
||||||
item.URL = u.(string)
|
item.URL = u
|
||||||
}
|
}
|
||||||
if photo, e := result["photo"]; e {
|
if photo, e := result["photo"]; e {
|
||||||
item.Photo = photo.(string)
|
item.Photo = photo
|
||||||
|
}
|
||||||
|
if value, e := result["longitude"]; e {
|
||||||
|
item.Longitude = value
|
||||||
|
}
|
||||||
|
if value, e := result["latitude"]; e {
|
||||||
|
item.Latitude = value
|
||||||
|
}
|
||||||
|
if value, e := result["country-name"]; e {
|
||||||
|
item.CountryName = value
|
||||||
|
}
|
||||||
|
if value, e := result["locality"]; e {
|
||||||
|
item.Locality = value
|
||||||
}
|
}
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
@ -198,7 +214,11 @@ func mapToItem(result map[string]interface{}) microsub.Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
if author, e := result["author"]; e {
|
if author, e := result["author"]; e {
|
||||||
item.Author = mapToAuthor(author.(map[string]interface{}))
|
item.Author = mapToAuthor(author.(map[string]string))
|
||||||
|
}
|
||||||
|
|
||||||
|
if checkin, e := result["checkin"]; e {
|
||||||
|
item.Checkin = mapToAuthor(checkin.(map[string]string))
|
||||||
}
|
}
|
||||||
|
|
||||||
if content, e := result["content"]; e {
|
if content, e := result["content"]; e {
|
||||||
|
|
@ -214,50 +234,49 @@ func mapToItem(result map[string]interface{}) microsub.Item {
|
||||||
|
|
||||||
// TODO: Check how to improve this
|
// TODO: Check how to improve this
|
||||||
|
|
||||||
// if value, e := result["like-of"]; e {
|
if value, e := result["like-of"]; e {
|
||||||
// for _, v := range value.([]interface{}) {
|
for _, v := range value.([]interface{}) {
|
||||||
// item.LikeOf = append(item.LikeOf, v.(string))
|
item.LikeOf = append(item.LikeOf, v.(string))
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if value, e := result["repost-of"]; e {
|
if value, e := result["repost-of"]; e {
|
||||||
// for _, v := range value.([]interface{}) {
|
for _, v := range value.([]interface{}) {
|
||||||
// item.RepostOf = append(item.RepostOf, v.(string))
|
item.RepostOf = append(item.RepostOf, v.(string))
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if value, e := result["bookmark-of"]; e {
|
if value, e := result["bookmark-of"]; e {
|
||||||
// for _, v := range value.([]interface{}) {
|
for _, v := range value.([]interface{}) {
|
||||||
// item.BookmarkOf = append(item.BookmarkOf, v.(string))
|
item.BookmarkOf = append(item.BookmarkOf, v.(string))
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if value, e := result["in-reply-to"]; e {
|
if value, e := result["in-reply-to"]; e {
|
||||||
// for _, v := range value.([]interface{}) {
|
for _, v := range value.([]interface{}) {
|
||||||
// if replyTo, ok := v.(string); ok {
|
if replyTo, ok := v.(string); ok {
|
||||||
// item.InReplyTo = append(item.InReplyTo, replyTo)
|
item.InReplyTo = append(item.InReplyTo, replyTo)
|
||||||
// } else if cite, ok := v.(map[string]interface{}); ok {
|
} else if cite, ok := v.(map[string]interface{}); ok {
|
||||||
// item.InReplyTo = append(item.InReplyTo, cite["url"].(string))
|
item.InReplyTo = append(item.InReplyTo, cite["url"].(string))
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if value, e := result["photo"]; e {
|
if value, e := result["photo"]; e {
|
||||||
// for _, v := range value.([]interface{}) {
|
for _, v := range value.([]interface{}) {
|
||||||
// item.Photo = append(item.Photo, v.(string))
|
item.Photo = append(item.Photo, v.(string))
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if value, e := result["category"]; e {
|
if value, e := result["category"]; e {
|
||||||
|
if cats, ok := value.([]string); ok {
|
||||||
// if cats, ok := value.([]string); ok {
|
for _, v := range cats {
|
||||||
// for _, v := range cats {
|
item.Category = append(item.Category, v)
|
||||||
// item.Category = append(item.Category, v)
|
}
|
||||||
// }
|
} else {
|
||||||
// } else {
|
item.Category = append(item.Category, value.(string))
|
||||||
// item.Category = append(item.Category, value.(string))
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
if published, e := result["published"]; e {
|
if published, e := result["published"]; e {
|
||||||
item.Published = published.(string)
|
item.Published = published.(string)
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,15 @@ func simplify(itemType string, item map[string][]interface{}) map[string]interfa
|
||||||
feedItem[k] = v
|
feedItem[k] = v
|
||||||
} else if k == "featured" {
|
} else if k == "featured" {
|
||||||
feedItem[k] = v
|
feedItem[k] = v
|
||||||
|
} else if k == "checkin" || k == "author" {
|
||||||
|
if value, ok := v[0].(*microformats.Microformat); ok {
|
||||||
|
card := make(map[string]string)
|
||||||
|
card["type"] = "card"
|
||||||
|
for ik, vk := range value.Properties {
|
||||||
|
card[ik] = vk[0].(string)
|
||||||
|
}
|
||||||
|
feedItem[k] = card
|
||||||
|
}
|
||||||
} else if value, ok := v[0].(*microformats.Microformat); ok {
|
} else if value, ok := v[0].(*microformats.Microformat); ok {
|
||||||
mType := value.Type[0][2:]
|
mType := value.Type[0][2:]
|
||||||
m := simplify(mType, value.Properties)
|
m := simplify(mType, value.Properties)
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,17 @@ type Channel struct {
|
||||||
Unread bool `json:"unread"`
|
Unread bool `json:"unread"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Author struct {
|
type Card struct {
|
||||||
Filled bool `json:"-,omitempty"`
|
Filled bool `json:"-,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
URL string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
Photo string `json:"photo,omitempty"`
|
Photo string `json:"photo,omitempty"`
|
||||||
|
Locality string `json:"locality,omitempty"`
|
||||||
|
Region string `json:"region,omitempty"`
|
||||||
|
CountryName string `json:"country-name,omitempty"`
|
||||||
|
Longitude string `json:"longitude,omitempty"`
|
||||||
|
Latitude string `json:"latitude,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Content struct {
|
type Content struct {
|
||||||
|
|
@ -57,18 +62,19 @@ type Item struct {
|
||||||
Published string `json:"published"`
|
Published string `json:"published"`
|
||||||
Updated string `json:"updated"`
|
Updated string `json:"updated"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
UID string `json:"uid"`
|
UID string `json:"uid,omitempty"`
|
||||||
Author Author `json:"author"`
|
Author Card `json:"author,omitempty"`
|
||||||
Category []string `json:"category"`
|
Category []string `json:"category,omitempty"`
|
||||||
Photo []string `json:"photo"`
|
Photo []string `json:"photo,omitempty"`
|
||||||
LikeOf []string `json:"like-of"`
|
LikeOf []string `json:"like-of,omitempty"`
|
||||||
BookmarkOf []string `json:"bookmark-of"`
|
BookmarkOf []string `json:"bookmark-of,omitempty"`
|
||||||
RepostOf []string `json:"repost-of"`
|
RepostOf []string `json:"repost-of,omitempty"`
|
||||||
InReplyTo []string `json:"in-reply-to"`
|
InReplyTo []string `json:"in-reply-to,omitempty"`
|
||||||
Summary []string `json:"summary,omitempty"`
|
Summary []string `json:"summary,omitempty"`
|
||||||
Content Content `json:"content,omitempty"`
|
Content Content `json:"content,omitempty"`
|
||||||
Latitude string `json:"latitude,omitempty"`
|
Latitude string `json:"latitude,omitempty"`
|
||||||
Longitude string `json:"longitude,omitempty"`
|
Longitude string `json:"longitude,omitempty"`
|
||||||
|
Checkin Card `json:"checkin,omitempty"`
|
||||||
Id string `json:"_id"`
|
Id string `json:"_id"`
|
||||||
Read bool `json:"_is_read"`
|
Read bool `json:"_is_read"`
|
||||||
}
|
}
|
||||||
|
|
@ -91,7 +97,7 @@ type Feed struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Photo string `json:"photo,omitempty"`
|
Photo string `json:"photo,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Author Author `json:"author,omitempty"`
|
Author Card `json:"author,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Microsub is the main protocol that should be implemented by a backend
|
// Microsub is the main protocol that should be implemented by a backend
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user