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 (.+)$")
|
||||
|
||||
func (h *microsubHandler) cachedCheckAuthToken(header string, r *TokenResponse) bool {
|
||||
r.Me = "https://publog.stuifzandapp.com/"
|
||||
log.Println("Cached checking Auth Token")
|
||||
|
||||
tokens := authHeaderRegex.FindStringSubmatch(header)
|
||||
|
|
|
@ -64,7 +64,7 @@ func Fetch2(fetchURL string) (*microformats.Data, error) {
|
|||
log.Printf("MISS %s\n", u.String())
|
||||
}
|
||||
|
||||
resp, err := http.Head(u.String())
|
||||
resp, err := http.Get(u.String())
|
||||
if err != nil {
|
||||
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.Encode(timeline)
|
||||
} else if action == "preview" {
|
||||
md, err := Fetch2(values.Get("url"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, "Failed parsing url", 500)
|
||||
return
|
||||
}
|
||||
|
||||
results := simplifyMicroformatData(md)
|
||||
|
||||
timeline := h.Backend.PreviewURL(values.Get("url"))
|
||||
jw := json.NewEncoder(w)
|
||||
jw.SetIndent("", " ")
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
jw.Encode(map[string]interface{}{
|
||||
"items": results,
|
||||
"paging": microsub.Pagination{},
|
||||
})
|
||||
jw.Encode(timeline)
|
||||
} else if action == "follow" {
|
||||
channel := values.Get("channel")
|
||||
following := h.Backend.FollowGetList(channel)
|
||||
|
|
|
@ -133,10 +133,20 @@ func (b *memoryBackend) ChannelsDelete(uid string) {
|
|||
func mapToItem(result map[string]interface{}) microsub.Item {
|
||||
item := microsub.Item{}
|
||||
|
||||
item.Type = "entry"
|
||||
|
||||
if name, e := result["name"]; e {
|
||||
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 c, ok := content.(map[string]interface{}); ok {
|
||||
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 {
|
||||
md, err := Fetch2(previewURL)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return microsub.Timeline{}
|
||||
}
|
||||
results := simplifyMicroformatData(md)
|
||||
log.Println(results)
|
||||
items := []microsub.Item{}
|
||||
for _, r := range results {
|
||||
item := mapToItem(r)
|
||||
log.Println(item)
|
||||
items = append(items, item)
|
||||
}
|
||||
return microsub.Timeline{
|
||||
|
|
|
@ -55,6 +55,7 @@ type Item struct {
|
|||
Name string `json:"name,omitempty"`
|
||||
Published string `json:"published"`
|
||||
URL string `json:"url"`
|
||||
UID string `json:"uid"`
|
||||
Author Author `json:"author"`
|
||||
Category []string `json:"category"`
|
||||
Photo []string `json:"photo"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user