diff --git a/web/history.go b/web/history.go index 0be4c1c..667f45b 100644 --- a/web/history.go +++ b/web/history.go @@ -5,7 +5,6 @@ import ( "log" "net/http" "strconv" - "strings" "github.com/gorilla/mux" @@ -18,7 +17,11 @@ import ( func initHistory(r *mux.Router) { r.PathPrefix("/history/").HandlerFunc(handlerHistory) - r.PathPrefix("/recent-changes/").HandlerFunc(handlerRecentChanges) + r.HandleFunc("/recent-changes/{count:[0-9]+}", handlerRecentChanges) + r.HandleFunc("/recent-changes/", func(w http.ResponseWriter, rq *http.Request) { + http.Redirect(w, rq, "/recent-changes/20", http.StatusSeeOther) + }) + r.HandleFunc("/recent-changes-rss", handlerRecentChangesRSS) r.HandleFunc("/recent-changes-atom", handlerRecentChangesAtom) r.HandleFunc("/recent-changes-json", handlerRecentChangesJSON) @@ -26,7 +29,6 @@ func initHistory(r *mux.Router) { // handlerHistory lists all revisions of a hypha. func handlerHistory(w http.ResponseWriter, rq *http.Request) { - util.PrepareRq(rq) hyphaName := util.HyphaNameFromRq(rq, "history") var list string @@ -43,21 +45,13 @@ func handlerHistory(w http.ResponseWriter, rq *http.Request) { // handlerRecentChanges displays the /recent-changes/ page. func handlerRecentChanges(w http.ResponseWriter, rq *http.Request) { - util.PrepareRq(rq) - var ( - noPrefix = strings.TrimPrefix(rq.URL.String(), "/recent-changes/") - n, err = strconv.Atoi(noPrefix) - ) - if err == nil && n < 101 { - util.HTTP200Page(w, views.BaseHTML(strconv.Itoa(n)+" recent changes", views.RecentChangesHTML(n), user.FromRequest(rq))) - } else { - http.Redirect(w, rq, "/recent-changes/20", http.StatusSeeOther) - } + // Error ignored: filtered by regex + n, _ := strconv.Atoi(mux.Vars(rq)["count"]) + util.HTTP200Page(w, views.BaseHTML(strconv.Itoa(n)+" recent changes", views.RecentChangesHTML(n), user.FromRequest(rq))) } // genericHandlerOfFeeds is a helper function for the web feed handlers. func genericHandlerOfFeeds(w http.ResponseWriter, rq *http.Request, f func() (string, error), name string) { - util.PrepareRq(rq) if content, err := f(); err != nil { w.Header().Set("Content-Type", "text/plain;charset=utf-8") w.WriteHeader(http.StatusInternalServerError) diff --git a/web/web.go b/web/web.go index ce736fe..a563a89 100644 --- a/web/web.go +++ b/web/web.go @@ -42,8 +42,6 @@ func httpErr(w http.ResponseWriter, status int, name, title, errMsg string) { } func handlerStyle(w http.ResponseWriter, rq *http.Request) { - util.PrepareRq(rq) - w.Header().Set("Content-Type", mime.TypeByExtension(".css")) for _, name := range stylesheets { file, err := static.FS.Open(name) @@ -65,7 +63,8 @@ func handlerRobotsTxt(w http.ResponseWriter, rq *http.Request) { w.Header().Set("Content-Type", "text/plain; charset=utf-8") file, err := static.FS.Open("robots.txt") - if err != nil { return + if err != nil { + return } io.Copy(w, file) file.Close()