mirror of https://github.com/jlelse/GoBlog
Simplify webmention routing
This commit is contained in:
parent
4b3c61022b
commit
39e999acca
6
http.go
6
http.go
|
@ -134,9 +134,9 @@ func buildHandler() (http.Handler, error) {
|
|||
r.Route("/webmention", func(webmentionRouter chi.Router) {
|
||||
webmentionRouter.Use(middleware.NoCache)
|
||||
webmentionRouter.Post("/", handleWebmention)
|
||||
webmentionRouter.With(authMiddleware, minifier.Middleware).Get("/admin", webmentionAdmin)
|
||||
webmentionRouter.With(authMiddleware).Post("/admin/delete/{id:\\d+}", webmentionAdminDelete)
|
||||
webmentionRouter.With(authMiddleware).Post("/admin/approve/{id:\\d+}", webmentionAdminApprove)
|
||||
webmentionRouter.With(authMiddleware, minifier.Middleware).Get("/", webmentionAdmin)
|
||||
webmentionRouter.With(authMiddleware).Post("/delete", webmentionAdminDelete)
|
||||
webmentionRouter.With(authMiddleware).Post("/approve", webmentionAdminApprove)
|
||||
})
|
||||
|
||||
// Posts
|
||||
|
|
|
@ -15,8 +15,9 @@
|
|||
Created: {{ unixtodate $mention.Created }}
|
||||
</p>
|
||||
<form method="post">
|
||||
<input type="submit" formaction="/webmention/admin/approve/{{ $mention.ID }}" value="{{ string $blog.Lang "approve" }}">
|
||||
<input type="submit" formaction="/webmention/admin/delete/{{ $mention.ID }}" value="{{ string $blog.Lang "delete" }}">
|
||||
<input type="hidden" name="mentionid" value="{{ $mention.ID }}">
|
||||
<input type="submit" formaction="/webmention/approve" value="{{ string $blog.Lang "approve" }}">
|
||||
<input type="submit" formaction="/webmention/delete" value="{{ string $blog.Lang "delete" }}">
|
||||
</form>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
@ -29,7 +30,8 @@
|
|||
Created: {{ unixtodate $mention.Created }}
|
||||
</p>
|
||||
<form method="post">
|
||||
<input type="submit" formaction="/webmention/admin/delete/{{ $mention.ID }}" value="{{ string $blog.Lang "delete" }}">
|
||||
<input type="hidden" name="mentionid" value="{{ $mention.ID }}">
|
||||
<input type="submit" formaction="/webmention/delete" value="{{ string $blog.Lang "delete" }}">
|
||||
</form>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
|
||||
type webmentionStatus string
|
||||
|
@ -106,7 +104,7 @@ func webmentionAdmin(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func webmentionAdminDelete(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.Atoi(chi.URLParam(r, "id"))
|
||||
id, err := strconv.Atoi(r.FormValue("mentionid"))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
|
@ -117,12 +115,12 @@ func webmentionAdminDelete(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
purgeCache()
|
||||
http.Redirect(w, r, "/webmention/admin", http.StatusFound)
|
||||
http.Redirect(w, r, "/webmention", http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
func webmentionAdminApprove(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.Atoi(chi.URLParam(r, "id"))
|
||||
id, err := strconv.Atoi(r.FormValue("mentionid"))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
|
@ -133,7 +131,7 @@ func webmentionAdminApprove(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
purgeCache()
|
||||
http.Redirect(w, r, "/webmention/admin", http.StatusFound)
|
||||
http.Redirect(w, r, "/webmention", http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue