Fix problem with names
This commit is contained in:
parent
274acd45d1
commit
ed0c535b76
|
@ -223,6 +223,8 @@ func convertMfToItem(mf *microformats.Microformat) microsub.Item {
|
||||||
if item.Name == strings.TrimSpace(item.Content.Text) {
|
if item.Name == strings.TrimSpace(item.Content.Text) {
|
||||||
item.Name = ""
|
item.Name = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: for like name is the field that is set
|
||||||
if item.Content.HTML == "" && len(item.LikeOf) > 0 {
|
if item.Content.HTML == "" && len(item.LikeOf) > 0 {
|
||||||
item.Name = ""
|
item.Name = ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,16 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
// "github.com/garyburd/redigo/redis"
|
||||||
"github.com/pstuifzand/microsub-server/microsub"
|
"github.com/pstuifzand/microsub-server/microsub"
|
||||||
"willnorris.com/go/microformats"
|
"willnorris.com/go/microformats"
|
||||||
)
|
)
|
||||||
|
|
||||||
var port int
|
var (
|
||||||
|
// pool redis.Pool
|
||||||
|
port int
|
||||||
|
// redisServer = flag.String("redis", "redis:6379", "")
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.IntVar(&port, "port", 80, "port for serving api")
|
flag.IntVar(&port, "port", 80, "port for serving api")
|
||||||
|
@ -54,14 +59,21 @@ func simplify(item map[string][]interface{}) map[string]interface{} {
|
||||||
if content, ok := v[0].(map[string]interface{}); ok {
|
if content, ok := v[0].(map[string]interface{}); ok {
|
||||||
if text, e := content["value"]; e {
|
if text, e := content["value"]; e {
|
||||||
delete(content, "value")
|
delete(content, "value")
|
||||||
if _, e := content["html"]; !e {
|
content["text"] = text
|
||||||
content["text"] = text
|
// if _, e := content["html"]; !e {
|
||||||
}
|
// content["text"] = text
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
feedItem[k] = content
|
feedItem[k] = content
|
||||||
}
|
}
|
||||||
} else if k == "photo" {
|
} else if k == "photo" {
|
||||||
feedItem[k] = v
|
if len(v) == 1 {
|
||||||
|
if value, ok := v[0].(string); ok {
|
||||||
|
feedItem[k] = value
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
feedItem[k] = v
|
||||||
|
}
|
||||||
} else if k == "video" {
|
} else if k == "video" {
|
||||||
feedItem[k] = v
|
feedItem[k] = v
|
||||||
} else if k == "featured" {
|
} else if k == "featured" {
|
||||||
|
@ -78,6 +90,20 @@ func simplify(item map[string][]interface{}) map[string]interface{} {
|
||||||
feedItem[k] = value
|
feedItem[k] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove "name" when it's equals to "content[text]"
|
||||||
|
if name, e := feedItem["name"]; e {
|
||||||
|
if content, e2 := feedItem["content"]; e2 {
|
||||||
|
if contentMap, ok := content.(map[string]interface{}); ok {
|
||||||
|
if text, e3 := contentMap["text"]; e3 {
|
||||||
|
if name == text {
|
||||||
|
delete(feedItem, "name")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return feedItem
|
return feedItem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,8 +146,64 @@ func simplifyMicroformatData(md *microformats.Data) []map[string]interface{} {
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TokenResponse is the information that we get back from the token endpoint of the user...
|
||||||
|
type TokenResponse struct {
|
||||||
|
Me string `json:"me"`
|
||||||
|
ClientID string `json:"client_id"`
|
||||||
|
Scope string `json:"scope"`
|
||||||
|
IssuedAt int64 `json:"issued_at"`
|
||||||
|
Nonce int64 `json:"nonce"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *microsubHandler) checkAuthToken(header string, token *TokenResponse) bool {
|
||||||
|
req, err := http.NewRequest("GET", "https://publog.stuifzandapp.com/authtoken", nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Add("Authorization", header)
|
||||||
|
req.Header.Add("Accept", "application/json")
|
||||||
|
|
||||||
|
client := http.Client{}
|
||||||
|
res, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
dec := json.NewDecoder(res.Body)
|
||||||
|
err = dec.Decode(&token)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Println(r.URL.String())
|
//conn := pool.Get()
|
||||||
|
//defer conn.Close()
|
||||||
|
|
||||||
|
//authorization := r.Header.Get("Authorization")
|
||||||
|
|
||||||
|
// var token TokenResponse
|
||||||
|
|
||||||
|
// if !h.checkAuthToken(authorization, &token) {
|
||||||
|
// http.Error(w, "Can't validate token", 403)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if token.Me != "https://publog.stuifzandapp.com/" {
|
||||||
|
// http.Error(w, "Wrong me", 403)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
if r.Method == http.MethodGet {
|
if r.Method == http.MethodGet {
|
||||||
values := r.URL.Query()
|
values := r.URL.Query()
|
||||||
|
@ -219,6 +301,14 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func newPool(addr string) *redis.Pool {
|
||||||
|
// return &redis.Pool{
|
||||||
|
// MaxIdle: 3,
|
||||||
|
// IdleTimeout: 240 * time.Second,
|
||||||
|
// Dial: func() (redis.Conn, error) { return redis.Dial("tcp", addr) },
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -239,6 +329,8 @@ func main() {
|
||||||
backend = loadMemoryBackend()
|
backend = loadMemoryBackend()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pool = newPool(*redisServer)
|
||||||
|
|
||||||
http.Handle("/microsub", µsubHandler{backend})
|
http.Handle("/microsub", µsubHandler{backend})
|
||||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,7 @@ import (
|
||||||
type memoryBackend struct {
|
type memoryBackend struct {
|
||||||
Channels map[string]microsub.Channel
|
Channels map[string]microsub.Channel
|
||||||
Feeds map[string][]microsub.Feed
|
Feeds map[string][]microsub.Feed
|
||||||
//Items map[string]map[string][]microsub.Item
|
NextUid int
|
||||||
NextUid int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Debug interface {
|
type Debug interface {
|
||||||
|
@ -71,10 +70,10 @@ func createMemoryBackend() microsub.Microsub {
|
||||||
backend.Channels = make(map[string]microsub.Channel)
|
backend.Channels = make(map[string]microsub.Channel)
|
||||||
backend.Feeds = make(map[string][]microsub.Feed)
|
backend.Feeds = make(map[string][]microsub.Feed)
|
||||||
channels := []microsub.Channel{
|
channels := []microsub.Channel{
|
||||||
microsub.Channel{"0000", "default"},
|
microsub.Channel{UID: "0000", Name: "default"},
|
||||||
microsub.Channel{"0001", "notifications"},
|
microsub.Channel{UID: "0001", Name: "notifications"},
|
||||||
microsub.Channel{"1000", "Friends"},
|
microsub.Channel{UID: "1000", Name: "Friends"},
|
||||||
microsub.Channel{"1001", "Family"},
|
microsub.Channel{UID: "1001", Name: "Family"},
|
||||||
}
|
}
|
||||||
for _, c := range channels {
|
for _, c := range channels {
|
||||||
backend.Channels[c.UID] = c
|
backend.Channels[c.UID] = c
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Package microsub describes the protocol methods of the Microsub protocol
|
||||||
package microsub
|
package microsub
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user