Compare commits
No commits in common. "b34604607d4b254989c8f3252486b1b8ca779d89" and "7d7d55099e81338002a43131be4aa04e6d1a7a95" have entirely different histories.
b34604607d
...
7d7d55099e
|
@ -182,7 +182,7 @@ Commands:
|
|||
if len(commands) == 2 && commands[0] == "channels" {
|
||||
name := commands[1]
|
||||
channel := sub.ChannelsCreate(name)
|
||||
fmt.Printf("%s\n", channel.UID)
|
||||
fmt.Printf("Channel created %s %s\n", channel.Name, channel.UID)
|
||||
}
|
||||
|
||||
if len(commands) == 3 && commands[0] == "channels" {
|
||||
|
|
|
@ -162,10 +162,6 @@ func (b *memoryBackend) ChannelsGetList() []microsub.Channel {
|
|||
// ChannelsCreate creates a channels
|
||||
func (b *memoryBackend) ChannelsCreate(name string) microsub.Channel {
|
||||
defer b.save()
|
||||
|
||||
conn := pool.Get()
|
||||
defer conn.Close()
|
||||
|
||||
uid := fmt.Sprintf("%04d", b.NextUid)
|
||||
channel := microsub.Channel{
|
||||
UID: uid,
|
||||
|
@ -175,9 +171,6 @@ func (b *memoryBackend) ChannelsCreate(name string) microsub.Channel {
|
|||
b.Channels[channel.UID] = channel
|
||||
b.Feeds[channel.UID] = []microsub.Feed{}
|
||||
b.NextUid++
|
||||
|
||||
conn.Do("SADD", "channels", uid)
|
||||
conn.Do("SETNX", "channel_sortorder_"+uid, 99999)
|
||||
return channel
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,10 @@ import (
|
|||
"crypto/sha1"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/garyburd/redigo/redis"
|
||||
"github.com/pstuifzand/ekster/microsub"
|
||||
"willnorris.com/go/microformats"
|
||||
)
|
||||
|
||||
type micropubHandler struct {
|
||||
|
@ -22,12 +20,6 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
conn := pool.Get()
|
||||
defer conn.Close()
|
||||
|
||||
r.ParseForm()
|
||||
log.Printf("%s %s\n", r.Method, r.URL)
|
||||
log.Println(r.URL.Query())
|
||||
log.Println(r.PostForm)
|
||||
log.Println(r.Header)
|
||||
|
||||
if r.Method == http.MethodPost {
|
||||
sourceID := r.URL.Query().Get("source_id")
|
||||
|
||||
|
@ -37,39 +29,26 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
var item microsub.Item
|
||||
ok := false
|
||||
if r.Header.Get("Content-Type") == "application/jf2+json" {
|
||||
var item microsub.Item
|
||||
|
||||
dec := json.NewDecoder(r.Body)
|
||||
|
||||
err := dec.Decode(&item)
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("Error decoding: %v", err), 400)
|
||||
return
|
||||
}
|
||||
ok = true
|
||||
} else if r.Header.Get("Content-Type") == "application/json" {
|
||||
var mfItem microformats.Microformat
|
||||
dec := json.NewDecoder(r.Body)
|
||||
err := dec.Decode(&mfItem)
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("Error decoding: %v", err), 400)
|
||||
return
|
||||
}
|
||||
|
||||
item = mapToItem(simplifyMicroformat(&mfItem))
|
||||
ok = true
|
||||
item.Read = false
|
||||
id, err := redis.Int(conn.Do("INCR", "source:"+sourceID+"next_id"))
|
||||
item.ID = fmt.Sprintf("%x", sha1.Sum([]byte(fmt.Sprintf("source:%s:%d", sourceID, id))))
|
||||
h.Backend.channelAddItem(channel, item)
|
||||
} else {
|
||||
http.Error(w, "Unsupported Content-Type", 400)
|
||||
return
|
||||
}
|
||||
|
||||
if ok {
|
||||
item.Read = false
|
||||
id, _ := redis.Int(conn.Do("INCR", "source:"+sourceID+"next_id"))
|
||||
item.ID = fmt.Sprintf("%x", sha1.Sum([]byte(fmt.Sprintf("source:%s:%d", sourceID, id))))
|
||||
h.Backend.channelAddItem(channel, item)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
enc := json.NewEncoder(w)
|
||||
|
|
Loading…
Reference in New Issue
Block a user