Simplify handling of items
This commit is contained in:
parent
facb2c7778
commit
18f270c42c
|
|
@ -23,7 +23,6 @@ type TokenResponse struct {
|
||||||
var authHeaderRegex = regexp.MustCompile("^Bearer (.+)$")
|
var authHeaderRegex = regexp.MustCompile("^Bearer (.+)$")
|
||||||
|
|
||||||
func (h *microsubHandler) cachedCheckAuthToken(header string, r *TokenResponse) bool {
|
func (h *microsubHandler) cachedCheckAuthToken(header string, r *TokenResponse) bool {
|
||||||
r.Me = "https://publog.stuifzandapp.com/"
|
|
||||||
log.Println("Cached checking Auth Token")
|
log.Println("Cached checking Auth Token")
|
||||||
|
|
||||||
tokens := authHeaderRegex.FindStringSubmatch(header)
|
tokens := authHeaderRegex.FindStringSubmatch(header)
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ func Fetch2(fetchURL string) (*microformats.Data, error) {
|
||||||
log.Printf("MISS %s\n", u.String())
|
log.Printf("MISS %s\n", u.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.Head(u.String())
|
resp, err := http.Get(u.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error while fetching %s: %s", u, err)
|
return nil, fmt.Errorf("error while fetching %s: %s", u, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -226,22 +226,11 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
jw.SetIndent("", " ")
|
jw.SetIndent("", " ")
|
||||||
jw.Encode(timeline)
|
jw.Encode(timeline)
|
||||||
} else if action == "preview" {
|
} else if action == "preview" {
|
||||||
md, err := Fetch2(values.Get("url"))
|
timeline := h.Backend.PreviewURL(values.Get("url"))
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, "Failed parsing url", 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
results := simplifyMicroformatData(md)
|
|
||||||
|
|
||||||
jw := json.NewEncoder(w)
|
jw := json.NewEncoder(w)
|
||||||
jw.SetIndent("", " ")
|
jw.SetIndent("", " ")
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
jw.Encode(map[string]interface{}{
|
jw.Encode(timeline)
|
||||||
"items": results,
|
|
||||||
"paging": microsub.Pagination{},
|
|
||||||
})
|
|
||||||
} else if action == "follow" {
|
} else if action == "follow" {
|
||||||
channel := values.Get("channel")
|
channel := values.Get("channel")
|
||||||
following := h.Backend.FollowGetList(channel)
|
following := h.Backend.FollowGetList(channel)
|
||||||
|
|
|
||||||
|
|
@ -133,10 +133,20 @@ func (b *memoryBackend) ChannelsDelete(uid string) {
|
||||||
func mapToItem(result map[string]interface{}) microsub.Item {
|
func mapToItem(result map[string]interface{}) microsub.Item {
|
||||||
item := microsub.Item{}
|
item := microsub.Item{}
|
||||||
|
|
||||||
|
item.Type = "entry"
|
||||||
|
|
||||||
if name, e := result["name"]; e {
|
if name, e := result["name"]; e {
|
||||||
item.Name = name.(string)
|
item.Name = name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if url, e := result["url"]; e {
|
||||||
|
item.URL = url.(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if uid, e := result["uid"]; e {
|
||||||
|
item.UID = uid.(string)
|
||||||
|
}
|
||||||
|
|
||||||
if content, e := result["content"]; e {
|
if content, e := result["content"]; e {
|
||||||
if c, ok := content.(map[string]interface{}); ok {
|
if c, ok := content.(map[string]interface{}); ok {
|
||||||
if html, e2 := c["html"]; e2 {
|
if html, e2 := c["html"]; e2 {
|
||||||
|
|
@ -305,12 +315,15 @@ func (b *memoryBackend) Search(query string) []microsub.Feed {
|
||||||
func (b *memoryBackend) PreviewURL(previewURL string) microsub.Timeline {
|
func (b *memoryBackend) PreviewURL(previewURL string) microsub.Timeline {
|
||||||
md, err := Fetch2(previewURL)
|
md, err := Fetch2(previewURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
return microsub.Timeline{}
|
return microsub.Timeline{}
|
||||||
}
|
}
|
||||||
results := simplifyMicroformatData(md)
|
results := simplifyMicroformatData(md)
|
||||||
|
log.Println(results)
|
||||||
items := []microsub.Item{}
|
items := []microsub.Item{}
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
item := mapToItem(r)
|
item := mapToItem(r)
|
||||||
|
log.Println(item)
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
return microsub.Timeline{
|
return microsub.Timeline{
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ type Item struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Published string `json:"published"`
|
Published string `json:"published"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
UID string `json:"uid"`
|
||||||
Author Author `json:"author"`
|
Author Author `json:"author"`
|
||||||
Category []string `json:"category"`
|
Category []string `json:"category"`
|
||||||
Photo []string `json:"photo"`
|
Photo []string `json:"photo"`
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user