Merge branch 'missing-files' into new-microsub-package
All checks were successful
the build was successful

This commit is contained in:
Peter Stuifzand 2018-09-15 15:57:05 +02:00
commit b3fe5c17ed
Signed by: peter
GPG Key ID: 374322D56E5209E8
2 changed files with 21 additions and 18 deletions

View File

@ -1,11 +1,6 @@
# ekster
a microsub server
## Warning!
Very alpha: no warranty.
a [Microsub](https://indieweb.org/Microsub) server
## Installing and running ekster
@ -19,7 +14,7 @@ you need a Go environment. Use these commands to install the programs.
go get -u p83.nl/go/ekster/cmd/eksterd
go get -u p83.nl/go/ekster/cmd/ek
`eksterd` uses [Redis](https://redis.io/) as the database, to temporarily save
`eksterd` uses [Redis](https://redis.io/) as the database to temporarily save
the items and feeds. The more permanent information is saved in `backend.json`.
#### Running eksterd
@ -162,3 +157,7 @@ Micropub client.
`ekster` will check every 10 minutes, if the token is still valid. This could
be retrieved automatically, but this doesn't happen at the moment.
## Other Microsub projects
* <https://indieweb.org/Microsub>
* Aperture: [code](https://github.com/aaronparecki/Aperture), [hosted](https://aperture.p3k.io)

View File

@ -31,6 +31,10 @@ var (
entryRegex = regexp.MustCompile("^entry\\[\\d+\\]$")
)
const (
OutputContentType = "application/json; charset=utf-8"
)
type microsubHandler struct {
backend microsub.Microsub
}
@ -63,7 +67,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(map[string][]microsub.Channel{
"channels": channels,
})
@ -78,7 +82,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", OutputContentType)
jw.SetIndent("", " ")
jw.SetEscapeHTML(false)
err = jw.Encode(timeline)
@ -94,7 +98,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
jw := json.NewEncoder(w)
jw.SetIndent("", " ")
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(timeline)
if err != nil {
http.Error(w, err.Error(), 500)
@ -108,7 +112,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(map[string][]microsub.Feed{
"items": following,
})
@ -140,7 +144,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500)
return
}
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", OutputContentType)
fmt.Fprintln(w, "[]")
return
}
@ -152,7 +156,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500)
return
}
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(channel)
if err != nil {
http.Error(w, err.Error(), 500)
@ -164,7 +168,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500)
return
}
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(channel)
if err != nil {
http.Error(w, err.Error(), 500)
@ -180,7 +184,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500)
return
}
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", OutputContentType)
jw := json.NewEncoder(w)
err = jw.Encode(feed)
if err != nil {
@ -195,7 +199,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500)
return
}
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", OutputContentType)
fmt.Fprintln(w, "[]")
} else if action == "search" {
query := values.Get("query")
@ -205,7 +209,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", OutputContentType)
err = jw.Encode(map[string][]microsub.Feed{
"results": feeds,
})
@ -245,7 +249,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, fmt.Sprintf("unknown method in timeline %s\n", method), 500)
return
}
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Content-Type", OutputContentType)
fmt.Fprintln(w, "[]")
} else {
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 500)