mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-08-06 22:04:11 +00:00
History: Isolate feeds
This commit is contained in:
parent
2b8ffc69bd
commit
3e8d1fd161
@ -4,6 +4,7 @@ package histview
|
|||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
"github.com/bouncepaw/mycorrhiza/history"
|
"github.com/bouncepaw/mycorrhiza/history"
|
||||||
"github.com/bouncepaw/mycorrhiza/hyphae"
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
||||||
@ -23,6 +24,9 @@ func InitHandlers(rtr *mux.Router) {
|
|||||||
http.Redirect(w, rq, "/recent-changes/20", http.StatusSeeOther)
|
http.Redirect(w, rq, "/recent-changes/20", http.StatusSeeOther)
|
||||||
})
|
})
|
||||||
rtr.PathPrefix("/history/").HandlerFunc(handlerHistory)
|
rtr.PathPrefix("/history/").HandlerFunc(handlerHistory)
|
||||||
|
rtr.HandleFunc("/recent-changes-rss", handlerRecentChangesRSS)
|
||||||
|
rtr.HandleFunc("/recent-changes-atom", handlerRecentChangesAtom)
|
||||||
|
rtr.HandleFunc("/recent-changes-json", handlerRecentChangesJSON)
|
||||||
|
|
||||||
chainPrimitiveDiff = viewutil.CopyEnRuWith(fs, "view_primitive_diff.html", ruTranslation)
|
chainPrimitiveDiff = viewutil.CopyEnRuWith(fs, "view_primitive_diff.html", ruTranslation)
|
||||||
chainRecentChanges = viewutil.CopyEnRuWith(fs, "view_recent_changes.html", ruTranslation)
|
chainRecentChanges = viewutil.CopyEnRuWith(fs, "view_recent_changes.html", ruTranslation)
|
||||||
@ -83,6 +87,37 @@ func handlerHistory(w http.ResponseWriter, rq *http.Request) {
|
|||||||
historyView(viewutil.MetaFrom(w, rq), hyphaName, list)
|
historyView(viewutil.MetaFrom(w, rq), hyphaName, list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// genericHandlerOfFeeds is a helper function for the web feed handlers.
|
||||||
|
func genericHandlerOfFeeds(w http.ResponseWriter, rq *http.Request, f func(history.FeedOptions) (string, error), name string, contentType string) {
|
||||||
|
opts, err := history.ParseFeedOptions(rq.URL.Query())
|
||||||
|
var content string
|
||||||
|
if err == nil {
|
||||||
|
content, err = f(opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
w.Header().Set("Content-Type", "text/plain;charset=utf-8")
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
fmt.Fprint(w, "An error while generating "+name+": "+err.Error())
|
||||||
|
} else {
|
||||||
|
w.Header().Set("Content-Type", fmt.Sprintf("%s;charset=utf-8", contentType))
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
fmt.Fprint(w, content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handlerRecentChangesRSS(w http.ResponseWriter, rq *http.Request) {
|
||||||
|
genericHandlerOfFeeds(w, rq, history.RecentChangesRSS, "RSS", "application/rss+xml")
|
||||||
|
}
|
||||||
|
|
||||||
|
func handlerRecentChangesAtom(w http.ResponseWriter, rq *http.Request) {
|
||||||
|
genericHandlerOfFeeds(w, rq, history.RecentChangesAtom, "Atom", "application/atom+xml")
|
||||||
|
}
|
||||||
|
|
||||||
|
func handlerRecentChangesJSON(w http.ResponseWriter, rq *http.Request) {
|
||||||
|
genericHandlerOfFeeds(w, rq, history.RecentChangesJSON, "JSON feed", "application/json")
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//go:embed *.html
|
//go:embed *.html
|
||||||
fs embed.FS
|
fs embed.FS
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
package web
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/history"
|
|
||||||
)
|
|
||||||
|
|
||||||
func initHistory(r *mux.Router) {
|
|
||||||
|
|
||||||
r.HandleFunc("/recent-changes-rss", handlerRecentChangesRSS)
|
|
||||||
r.HandleFunc("/recent-changes-atom", handlerRecentChangesAtom)
|
|
||||||
r.HandleFunc("/recent-changes-json", handlerRecentChangesJSON)
|
|
||||||
}
|
|
||||||
|
|
||||||
// genericHandlerOfFeeds is a helper function for the web feed handlers.
|
|
||||||
func genericHandlerOfFeeds(w http.ResponseWriter, rq *http.Request, f func(history.FeedOptions) (string, error), name string, contentType string) {
|
|
||||||
opts, err := history.ParseFeedOptions(rq.URL.Query())
|
|
||||||
var content string
|
|
||||||
if err == nil {
|
|
||||||
content, err = f(opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
w.Header().Set("Content-Type", "text/plain;charset=utf-8")
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
fmt.Fprint(w, "An error while generating "+name+": "+err.Error())
|
|
||||||
} else {
|
|
||||||
w.Header().Set("Content-Type", fmt.Sprintf("%s;charset=utf-8", contentType))
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
fmt.Fprint(w, content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func handlerRecentChangesRSS(w http.ResponseWriter, rq *http.Request) {
|
|
||||||
genericHandlerOfFeeds(w, rq, history.RecentChangesRSS, "RSS", "application/rss+xml")
|
|
||||||
}
|
|
||||||
|
|
||||||
func handlerRecentChangesAtom(w http.ResponseWriter, rq *http.Request) {
|
|
||||||
genericHandlerOfFeeds(w, rq, history.RecentChangesAtom, "Atom", "application/atom+xml")
|
|
||||||
}
|
|
||||||
|
|
||||||
func handlerRecentChangesJSON(w http.ResponseWriter, rq *http.Request) {
|
|
||||||
genericHandlerOfFeeds(w, rq, history.RecentChangesJSON, "JSON feed", "application/json")
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user