Compare commits

..

No commits in common. "7c4711da1bf4c0de742fcef51c26ca4a117c292a" and "bac33043c1da562f159bbe2a4d7e8ed30ca4d2ed" have entirely different histories.

12 changed files with 84 additions and 131 deletions

View File

@ -106,6 +106,10 @@ func newMainHandler(backend *memoryBackend, baseURL, templateDir string, pool *r
return h, nil
}
func (h *mainHandler) templateFile(filename string) string {
return fmt.Sprintf("%s/%s", h.TemplateDir, filename)
}
func (h *mainHandler) renderTemplate(w io.Writer, filename string, data interface{}) error {
fsys, err := fs.Sub(templates, "templates")
if err != nil {
@ -288,7 +292,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
log.Println(err)
http.Error(w, fmt.Sprintf("Bad Request: %s", err.Error()), http.StatusBadRequest)
http.Error(w, fmt.Sprintf("Bad Request: %s", err.Error()), 400)
return
}
@ -313,19 +317,15 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} else if r.URL.Path == "/session/callback" {
c, err := r.Cookie("session")
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
return
} else if err != nil {
http.Error(w, "could not read cookie", http.StatusInternalServerError)
http.Error(w, "could not read cookie", 500)
return
}
sessionVar := c.Value
sess, err := loadSession(sessionVar, conn)
if err != nil {
fmt.Fprintf(w, "ERROR: %q\n", err)
return
}
verified, authResponse, err := performIndieauthCallback(h.BaseURL, r, &sess)
if err != nil {
@ -338,9 +338,9 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
saveSession(sessionVar, &sess, conn)
log.Printf("SESSION: %#v\n", sess)
if sess.NextURI != "" {
http.Redirect(w, r, sess.NextURI, http.StatusFound)
http.Redirect(w, r, sess.NextURI, 302)
} else {
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
}
return
}
@ -348,16 +348,11 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} else if r.URL.Path == "/settings/channel" {
c, err := r.Cookie("session")
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
return
}
sessionVar := c.Value
sess, err := loadSession(sessionVar, conn)
if err != nil {
log.Printf("ERROR: %s\n", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
if !isLoggedIn(h.Backend, &sess) {
w.WriteHeader(401)
@ -369,17 +364,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
page.Session = sess
currentChannel := r.URL.Query().Get("uid")
page.Channels, err = h.Backend.ChannelsGetList()
if err != nil {
log.Printf("ERROR: %s\n", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
page.Feeds, err = h.Backend.FollowGetList(currentChannel)
if err != nil {
log.Printf("ERROR: %s\n", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
for _, v := range page.Channels {
if v.UID == currentChannel {
@ -419,16 +404,11 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} else if r.URL.Path == "/logs" {
c, err := r.Cookie("session")
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
return
}
sessionVar := c.Value
sess, err := loadSession(sessionVar, conn)
if err != nil {
log.Printf("ERROR: %s\n", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
if !isLoggedIn(h.Backend, &sess) {
w.WriteHeader(401)
@ -447,16 +427,11 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} else if r.URL.Path == "/settings" {
c, err := r.Cookie("session")
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
return
}
sessionVar := c.Value
sess, err := loadSession(sessionVar, conn)
if err != nil {
log.Printf("ERROR: %s\n", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
if !isLoggedIn(h.Backend, &sess) {
w.WriteHeader(401)
@ -467,11 +442,6 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var page settingsPage
page.Session = sess
page.Channels, err = h.Backend.ChannelsGetList()
if err != nil {
log.Printf("ERROR: %s\n", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
// page.Feeds = h.Backend.Feeds
err = h.renderTemplate(w, "settings.html", page)
@ -486,16 +456,11 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sessionVar := getSessionCookie(w, r)
sess, err := loadSession(sessionVar, conn)
if err != nil {
log.Printf("ERROR: %s\n", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
if !isLoggedIn(h.Backend, &sess) {
sess.NextURI = r.URL.String()
saveSession(sessionVar, &sess, conn)
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
return
}
@ -537,11 +502,6 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
page.Scope = scope
page.State = state
page.Channels, err = h.Backend.ChannelsGetList()
if err != nil {
log.Printf("ERROR: %s\n", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
app, err := getAppInfo(clientID)
if err != nil {
@ -559,7 +519,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/session" {
c, err := r.Cookie("session")
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
return
}
@ -570,7 +530,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
endpoints, err := getEndpoints(me)
if err != nil {
http.Error(w, fmt.Sprintf("Bad Request: %s, %s", err.Error(), me), http.StatusBadRequest)
http.Error(w, fmt.Sprintf("Bad Request: %s, %s", err.Error(), me), 400)
return
}
@ -580,7 +540,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sess, err := loadSession(sessionVar, conn)
if err != nil {
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
return
}
@ -592,12 +552,12 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err = saveSession(sessionVar, &sess, conn)
if err != nil {
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
return
}
authenticationURL := indieauth.CreateAuthenticationURL(*endpoints.AuthorizationEndpoint, endpoints.Me.String(), h.BaseURL, redirectURI, state)
http.Redirect(w, r, authenticationURL, http.StatusFound)
http.Redirect(w, r, authenticationURL, 302)
return
} else if r.URL.Path == "/session/logout" {
@ -650,7 +610,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
redirectURI.RawQuery = q.Encode()
log.Println(redirectURI)
http.Redirect(w, r, redirectURI.String(), http.StatusFound)
http.Redirect(w, r, redirectURI.String(), 302)
return
} else if r.URL.Path == "/auth/token" {
grantType := r.FormValue("grant_type")
@ -722,11 +682,11 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// }
// h.Backend.Settings[uid] = setting
http.Redirect(w, r, "/settings", http.StatusFound)
http.Redirect(w, r, "/settings", 302)
return
} else if r.URL.Path == "/refresh" {
h.Backend.RefreshFeeds()
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
return
}
}
@ -737,14 +697,14 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func httpSessionLogout(r *http.Request, w http.ResponseWriter, conn redis.Conn) {
c, err := r.Cookie("session")
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
return
}
if err == nil {
sessionVar := c.Value
_, _ = conn.Do("DEL", "session:"+sessionVar)
}
http.Redirect(w, r, "/", http.StatusFound)
http.Redirect(w, r, "/", 302)
}
type parsedEndpoints struct {

View File

@ -172,9 +172,6 @@ func (h *hubIncomingBackend) Feeds() ([]Feed, error) {
inner join channels c on c.id = f.channel_id
where hub is not null
`)
if err != nil {
return nil, err
}
for rows.Next() {
var feed Feed

View File

@ -51,13 +51,13 @@ func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
leaseSeconds, err := strconv.ParseInt(leaseStr, 10, 64)
if err != nil {
log.Printf("error in hub.lease_seconds format %q: %s", leaseSeconds, err)
http.Error(w, fmt.Sprintf("error in hub.lease_seconds format %q: %s", leaseSeconds, err), http.StatusBadRequest)
http.Error(w, fmt.Sprintf("error in hub.lease_seconds format %q: %s", leaseSeconds, err), 400)
return
}
err = h.Backend.FeedSetLeaseSeconds(feed, leaseSeconds)
if err != nil {
log.Printf("error in while setting hub.lease_seconds: %s", err)
http.Error(w, fmt.Sprintf("error in while setting hub.lease_seconds: %s", err), http.StatusBadRequest)
http.Error(w, fmt.Sprintf("error in while setting hub.lease_seconds: %s", err), 400)
return
}
}
@ -70,7 +70,7 @@ func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
http.Error(w, "Method not allowed", 405)
return
}
@ -78,23 +78,18 @@ func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
secret := h.Backend.GetSecret(feed)
if secret == "" {
log.Printf("missing secret for feed %d\n", feed)
http.Error(w, "Unknown", http.StatusBadRequest)
http.Error(w, "Unknown", 400)
return
}
feedContent, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Printf("ERROR: %s\n", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
// match signature
sig := r.Header.Get("X-Hub-Signature")
if sig != "" {
if err := websub.ValidateHubSignature(sig, feedContent, []byte(secret)); err != nil {
log.Printf("could not validate signature: %+v", err)
http.Error(w, fmt.Sprintf("could not validate signature: %s", err), http.StatusBadRequest)
http.Error(w, fmt.Sprintf("could not validate signature: %s", err), 400)
return
}
}
@ -102,7 +97,9 @@ func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ct := r.Header.Get("Content-Type")
err = h.Backend.UpdateFeed(h.Processor, feed, ct, bytes.NewBuffer(feedContent))
if err != nil {
http.Error(w, fmt.Sprintf("could not update feed: %s (%s)", ct, err), http.StatusBadRequest)
http.Error(w, fmt.Sprintf("could not update feed: %s (%s)", ct, err), 400)
return
}
return
}

View File

@ -86,13 +86,13 @@ func WithAuth(handler http.Handler, b *memoryBackend) http.Handler {
}
if !authorized {
log.Printf("Token could not be validated")
http.Error(w, "Can't validate token", http.StatusForbidden)
http.Error(w, "Can't validate token", 403)
return
}
if token.Me != b.Me { // FIXME: Me should be part of the request
log.Printf("Missing \"me\" in token response: %#v\n", token)
http.Error(w, "Wrong me", http.StatusForbidden)
http.Error(w, "Wrong me", 403)
return
}

View File

@ -84,6 +84,12 @@ type newItemMessage struct {
Channel string `json:"channel"`
}
type fetch2 struct{}
func (f *fetch2) Fetch(url string) (*http.Response, error) {
return Fetch2(url)
}
func (b *memoryBackend) AuthTokenAccepted(header string, r *auth.TokenResponse) (bool, error) {
conn := b.pool.Get()
defer func() {
@ -136,7 +142,10 @@ func shouldRetryWithNewUID(err error, try int) bool {
if e, ok := err.(*pq.Error); ok {
if e.Code == "23505" && e.Constraint == "channels_uid_key" {
return try <= 5
if try > 5 {
return false
}
return true
}
}
return false
@ -624,22 +633,27 @@ func (b *memoryBackend) channelAddItemWithMatcher(channel string, item microsub.
if len(item.RepostOf) > 0 {
return nil
}
break
case "like":
if len(item.LikeOf) > 0 {
return nil
}
break
case "bookmark":
if len(item.BookmarkOf) > 0 {
return nil
}
break
case "reply":
if len(item.InReplyTo) > 0 {
return nil
}
break
case "checkin":
if item.Checkin != nil {
return nil
}
break
}
}
}
@ -761,10 +775,7 @@ func WithCaching(pool *redis.Pool, ff fetch.Fetcher) fetch.Fetcher {
return nil, fmt.Errorf("error parsing %s as url: %s", fetchURL, err)
}
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, err
}
req, err := http.NewRequest("GET", u.String(), nil)
data, err := redis.Bytes(conn.Do("GET", cacheKey))
if err == nil {
@ -810,10 +821,7 @@ func Fetch2(fetchURL string) (*http.Response, error) {
return nil, fmt.Errorf("error parsing %s as url: %s", fetchURL, err)
}
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, err
}
req, err := http.NewRequest("GET", u.String(), nil)
client := http.Client{}
resp, err := client.Do(req)

View File

@ -40,7 +40,7 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
http.Error(w, "bad request", http.StatusBadRequest)
http.Error(w, "bad request", 400)
return
}
@ -50,13 +50,13 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
channel, err = getChannelFromAuthorization(r, conn)
if err != nil {
log.Println(err)
http.Error(w, "unauthorized", http.StatusUnauthorized)
http.Error(w, "unauthorized", 401)
return
}
// no channel is found
if channel == "" {
http.Error(w, "bad request, unknown channel", http.StatusBadRequest)
http.Error(w, "bad request, unknown channel", 400)
return
}
@ -64,7 +64,7 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
item, err := parseIncomingItem(r)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusBadRequest)
http.Error(w, err.Error(), 400)
return
}
log.Printf("Item published: %s", item.Published)
@ -76,7 +76,7 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
newID, err := generateItemID(conn, channel)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
item.ID = newID
@ -95,13 +95,13 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err = json.NewEncoder(w).Encode(map[string]string{"ok": "1"}); err != nil {
log.Println(err)
http.Error(w, "internal server error", http.StatusInternalServerError)
http.Error(w, "internal server error", 500)
}
return
}
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
http.Error(w, "Method not allowed", 405)
}
func generateItemID(conn redis.Conn, channel string) (string, error) {

View File

@ -48,9 +48,6 @@ func FeedHeader(fetcher Fetcher, fetchURL, contentType string, body io.Reader) (
md := microformats.Parse(resp.Body, u)
author, ok = jf2.SimplifyMicroformatDataAuthor(md)
if !ok {
log.Println("Could not simplify the author")
}
}
}

View File

@ -88,14 +88,6 @@ func simplifyContent(k string, v []interface{}) *microsub.Content {
// CleanHTML removes white-space:pre from html
func CleanHTML(s string) (string, error) {
doc, err := html.Parse(strings.NewReader(s))
if err != nil {
return "", err
}
whitespaceRegex, err := regexp.Compile(`white-space:\s*pre`)
if err != nil {
return "", err
}
if err != nil {
return "", err
@ -109,7 +101,7 @@ func CleanHTML(s string) (string, error) {
if a.Key != "style" {
continue
}
if whitespaceRegex.MatchString(a.Val) {
if m, err := regexp.MatchString("white-space:\\s*pre", a.Val); err == nil && m {
removeIndex = i
break
}

View File

@ -37,7 +37,7 @@ func (cs *charsetISO88591er) ReadByte() (b byte, err error) {
func (cs *charsetISO88591er) Read(p []byte) (int, error) {
// Use ReadByte method.
return 0, errors.New("use ReadByte()")
return 0, errors.New("Use ReadByte()")
}
func isCharsetISO88591(charset string) bool {

View File

@ -303,7 +303,7 @@ type Enclosure struct {
// Get uses http.Get to fetch an enclosure.
func (e *Enclosure) Get() (io.ReadCloser, error) {
if e == nil || e.URL == "" {
return nil, errors.New("no enclosure")
return nil, errors.New("No enclosure")
}
res, err := http.Get(e.URL)
@ -325,7 +325,7 @@ type Image struct {
// Get uses http.Get to fetch an image.
func (i *Image) Get() (io.ReadCloser, error) {
if i == nil || i.URL == "" {
return nil, errors.New("no image")
return nil, errors.New("No image")
}
res, err := http.Get(i.URL)

View File

@ -1,6 +1,7 @@
package rss
import (
"fmt"
"io/ioutil"
"path/filepath"
"testing"
@ -76,7 +77,7 @@ func TestParseItemDateOK(t *testing.T) {
t.Fatalf("Parsing %s: %v", name, err)
}
if feed.Items[0].Date.String() != want {
if fmt.Sprintf("%s", feed.Items[0].Date) != want {
t.Errorf("%s: got %q, want %q", name, feed.Items[0].Date, want)
}
}
@ -99,7 +100,7 @@ func TestParseItemDateFailure(t *testing.T) {
t.Fatalf("Parsing %s: %v", name, err)
}
if feed.Items[1].Date.String() != want {
if fmt.Sprintf("%s", feed.Items[1].Date) != want {
t.Errorf("%s: got %q, want %q", name, feed.Items[1].Date, want)
}

View File

@ -16,7 +16,7 @@ import (
)
var (
entryRegex = regexp.MustCompile(`^entry\[\d+\]$`)
entryRegex = regexp.MustCompile("^entry\\[\\d+\\]$")
)
// Constants used for the responses
@ -36,7 +36,7 @@ func respondJSON(w http.ResponseWriter, value interface{}) {
w.Header().Add("Content-Type", OutputContentType)
err := jw.Encode(value)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
}
}
@ -70,7 +70,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
channels, err := h.backend.ChannelsGetList()
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
respondJSON(w, map[string][]microsub.Channel{
@ -80,7 +80,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
timeline, err := h.backend.TimelineGet(values.Get("before"), values.Get("after"), values.Get("channel"))
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
respondJSON(w, timeline)
@ -88,7 +88,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
timeline, err := h.backend.PreviewURL(values.Get("url"))
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
respondJSON(w, timeline)
@ -97,7 +97,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
following, err := h.backend.FollowGetList(channel)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
respondJSON(w, map[string][]microsub.Feed{
@ -107,7 +107,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
events, err := h.backend.Events()
if err != nil {
log.Println(err)
http.Error(w, "could not start sse connection", http.StatusInternalServerError)
http.Error(w, "could not start sse connection", 500)
}
// Remove this client from the map of connected clients
@ -117,7 +117,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}()
// Listen to connection close and un-register messageChan
notify := r.Context().Done()
notify := w.(http.CloseNotifier).CloseNotify()
go func() {
<-notify
@ -127,10 +127,10 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err = sse.WriteMessages(w, events)
if err != nil {
log.Println(err)
http.Error(w, "internal server error", http.StatusInternalServerError)
http.Error(w, "internal server error", 500)
}
} else {
http.Error(w, fmt.Sprintf("unknown action %s", action), http.StatusBadRequest)
http.Error(w, fmt.Sprintf("unknown action %s", action), 400)
return
}
return
@ -147,7 +147,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err := h.backend.ChannelsDelete(uid)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
respondJSON(w, []string{})
@ -158,7 +158,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
channel, err := h.backend.ChannelsCreate(name)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
respondJSON(w, channel)
@ -166,7 +166,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
channel, err := h.backend.ChannelsUpdate(uid, name)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
respondJSON(w, channel)
@ -177,7 +177,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// h.HubIncomingBackend.CreateFeed(url, uid)
feed, err := h.backend.FollowURL(uid, url)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
respondJSON(w, feed)
@ -186,14 +186,14 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
url := values.Get("url")
err := h.backend.UnfollowURL(uid, url)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
respondJSON(w, []string{})
} else if action == "preview" {
timeline, err := h.backend.PreviewURL(values.Get("url"))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
respondJSON(w, timeline)
@ -250,21 +250,22 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if len(markAsRead) > 0 {
err := h.backend.MarkRead(channel, markAsRead)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), 500)
return
}
} else {
log.Println("No uids specified for mark read")
}
} else {
http.Error(w, fmt.Sprintf("unknown method in timeline %s\n", method), http.StatusInternalServerError)
http.Error(w, fmt.Sprintf("unknown method in timeline %s\n", method), 500)
return
}
respondJSON(w, []string{})
} else {
http.Error(w, fmt.Sprintf("unknown action %s\n", action), http.StatusBadRequest)
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 400)
}
return
}
return
}