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" {
|
if len(commands) == 2 && commands[0] == "channels" {
|
||||||
name := commands[1]
|
name := commands[1]
|
||||||
channel := sub.ChannelsCreate(name)
|
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" {
|
if len(commands) == 3 && commands[0] == "channels" {
|
||||||
|
|
|
||||||
|
|
@ -162,10 +162,6 @@ func (b *memoryBackend) ChannelsGetList() []microsub.Channel {
|
||||||
// ChannelsCreate creates a channels
|
// ChannelsCreate creates a channels
|
||||||
func (b *memoryBackend) ChannelsCreate(name string) microsub.Channel {
|
func (b *memoryBackend) ChannelsCreate(name string) microsub.Channel {
|
||||||
defer b.save()
|
defer b.save()
|
||||||
|
|
||||||
conn := pool.Get()
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
uid := fmt.Sprintf("%04d", b.NextUid)
|
uid := fmt.Sprintf("%04d", b.NextUid)
|
||||||
channel := microsub.Channel{
|
channel := microsub.Channel{
|
||||||
UID: uid,
|
UID: uid,
|
||||||
|
|
@ -175,9 +171,6 @@ func (b *memoryBackend) ChannelsCreate(name string) microsub.Channel {
|
||||||
b.Channels[channel.UID] = channel
|
b.Channels[channel.UID] = channel
|
||||||
b.Feeds[channel.UID] = []microsub.Feed{}
|
b.Feeds[channel.UID] = []microsub.Feed{}
|
||||||
b.NextUid++
|
b.NextUid++
|
||||||
|
|
||||||
conn.Do("SADD", "channels", uid)
|
|
||||||
conn.Do("SETNX", "channel_sortorder_"+uid, 99999)
|
|
||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,10 @@ import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/garyburd/redigo/redis"
|
"github.com/garyburd/redigo/redis"
|
||||||
"github.com/pstuifzand/ekster/microsub"
|
"github.com/pstuifzand/ekster/microsub"
|
||||||
"willnorris.com/go/microformats"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type micropubHandler struct {
|
type micropubHandler struct {
|
||||||
|
|
@ -22,12 +20,6 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
conn := pool.Get()
|
conn := pool.Get()
|
||||||
defer conn.Close()
|
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 {
|
if r.Method == http.MethodPost {
|
||||||
sourceID := r.URL.Query().Get("source_id")
|
sourceID := r.URL.Query().Get("source_id")
|
||||||
|
|
||||||
|
|
@ -37,39 +29,26 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var item microsub.Item
|
|
||||||
ok := false
|
|
||||||
if r.Header.Get("Content-Type") == "application/jf2+json" {
|
if r.Header.Get("Content-Type") == "application/jf2+json" {
|
||||||
|
var item microsub.Item
|
||||||
|
|
||||||
dec := json.NewDecoder(r.Body)
|
dec := json.NewDecoder(r.Body)
|
||||||
|
|
||||||
err := dec.Decode(&item)
|
err := dec.Decode(&item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("Error decoding: %v", err), 400)
|
http.Error(w, fmt.Sprintf("Error decoding: %v", err), 400)
|
||||||
return
|
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))
|
item.Read = false
|
||||||
ok = true
|
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 {
|
} else {
|
||||||
http.Error(w, "Unsupported Content-Type", 400)
|
http.Error(w, "Unsupported Content-Type", 400)
|
||||||
return
|
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")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
enc := json.NewEncoder(w)
|
enc := json.NewEncoder(w)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user