chore: cleanup code of Ekster
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
39e08e6026
commit
44b73e1c79
|
@ -658,11 +658,8 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
enc := json.NewEncoder(w)
|
||||
err = enc.Encode(&res)
|
||||
if err != nil {
|
||||
if err := json.NewEncoder(w).Encode(&res); err != nil {
|
||||
log.Println(err)
|
||||
fmt.Fprintf(w, "ERROR: %q", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
|
@ -88,6 +88,7 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
if err = json.NewEncoder(w).Encode(map[string]string{"ok": "1"}); err != nil {
|
||||
http.Error(w, "internal server error", 500)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -103,40 +104,38 @@ func generateItemID(conn redis.Conn, channel string) (string, error) {
|
|||
}
|
||||
|
||||
func parseIncomingItem(r *http.Request) (*microsub.Item, error) {
|
||||
var item microsub.Item
|
||||
|
||||
contentType := r.Header.Get("content-type")
|
||||
|
||||
if contentType == "application/jf2+json" {
|
||||
dec := json.NewDecoder(r.Body)
|
||||
err := dec.Decode(&item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not decode request body as jf2: %v", err)
|
||||
var item microsub.Item
|
||||
if err := json.NewDecoder(r.Body).Decode(&item); err != nil {
|
||||
return nil, fmt.Errorf("could not decode request body as %q: %v", contentType, err)
|
||||
}
|
||||
return &item, nil
|
||||
} else if contentType == "application/json" {
|
||||
var mfItem microformats.Microformat
|
||||
dec := json.NewDecoder(r.Body)
|
||||
err := dec.Decode(&mfItem)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not decode request body as json: %v", err)
|
||||
if err := json.NewDecoder(r.Body).Decode(&mfItem); err != nil {
|
||||
return nil, fmt.Errorf("could not decode request body as %q: %v", contentType, err)
|
||||
}
|
||||
author := microsub.Card{}
|
||||
var ok bool
|
||||
item, ok = jf2.SimplifyMicroformatItem(&mfItem, author)
|
||||
item, ok := jf2.SimplifyMicroformatItem(&mfItem, author)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("could not simplify microformat item to jf2")
|
||||
}
|
||||
return &item, nil
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
// TODO: improve handling of form-urlencoded
|
||||
var item microsub.Item
|
||||
content := r.FormValue("content")
|
||||
name := r.FormValue("name")
|
||||
item.Type = "entry"
|
||||
item.Name = name
|
||||
item.Content = µsub.Content{Text: content}
|
||||
item.Published = time.Now().Format(time.RFC3339)
|
||||
} else {
|
||||
return nil, fmt.Errorf("content-type %s is not supported", contentType)
|
||||
return &item, nil
|
||||
}
|
||||
return &item, nil
|
||||
|
||||
return nil, fmt.Errorf("content-type %q is not supported", contentType)
|
||||
}
|
||||
|
||||
func getChannelFromAuthorization(r *http.Request, conn redis.Conn) (string, error) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user