mirror of https://github.com/jlelse/GoBlog
Allow requesting webmentions with status using query param
This commit is contained in:
parent
8fb6d8e177
commit
a47a1719eb
|
@ -54,7 +54,7 @@ func authMiddleware(next http.Handler) http.Handler {
|
|||
return
|
||||
}
|
||||
// 3. Show login form
|
||||
w.Header().Set("Cache-Control", "no-cache,no-store,must-revalidate")
|
||||
w.Header().Set("Cache-Control", "no-store,max-age=0")
|
||||
h, _ := json.Marshal(r.Header.Clone())
|
||||
b, _ := io.ReadAll(io.LimitReader(r.Body, 2000000)) // Only allow 20 Megabyte
|
||||
_ = r.Body.Close()
|
||||
|
|
2
go.mod
2
go.mod
|
@ -58,7 +58,7 @@ require (
|
|||
golang.org/x/mod v0.4.1 // indirect
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 // indirect
|
||||
golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b // indirect
|
||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
|
||||
golang.org/x/text v0.3.5 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -411,8 +411,8 @@ golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 h1:cEhElsAv9LUt9ZUUocxzWe05oFLVd+AA2nstydTeI8g=
|
||||
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b h1:ggRgirZABFolTmi3sn6Ivd9SipZwLedQ5wR0aAKnFxU=
|
||||
golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
|
@ -36,7 +37,14 @@ func (p *webmentionPaginationAdapter) Slice(offset, length int, data interface{}
|
|||
func webmentionAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
pageNoString := chi.URLParam(r, "page")
|
||||
pageNo, _ := strconv.Atoi(pageNoString)
|
||||
p := paginator.New(&webmentionPaginationAdapter{config: &webmentionsRequestConfig{}}, 10)
|
||||
var status webmentionStatus = ""
|
||||
switch webmentionStatus(r.URL.Query().Get("status")) {
|
||||
case webmentionStatusVerified:
|
||||
status = webmentionStatusVerified
|
||||
case webmentionStatusApproved:
|
||||
status = webmentionStatusApproved
|
||||
}
|
||||
p := paginator.New(&webmentionPaginationAdapter{config: &webmentionsRequestConfig{status: status}}, 10)
|
||||
p.SetPage(pageNo)
|
||||
var mentions []*mention
|
||||
err := p.Results(&mentions)
|
||||
|
@ -66,14 +74,23 @@ func webmentionAdmin(w http.ResponseWriter, r *http.Request) {
|
|||
nextPage, _ = p.Page()
|
||||
}
|
||||
nextPath = fmt.Sprintf("%s/page/%d", webmentionPath, nextPage)
|
||||
// Query
|
||||
query := ""
|
||||
params := url.Values{}
|
||||
if status != "" {
|
||||
params.Add("status", string(status))
|
||||
}
|
||||
if len(params) > 0 {
|
||||
query = "?" + params.Encode()
|
||||
}
|
||||
// Render
|
||||
render(w, r, templateWebmentionAdmin, &renderData{
|
||||
Data: map[string]interface{}{
|
||||
"Mentions": mentions,
|
||||
"HasPrev": hasPrev,
|
||||
"HasNext": hasNext,
|
||||
"Prev": slashIfEmpty(prevPath),
|
||||
"Next": slashIfEmpty(nextPath),
|
||||
"Prev": slashIfEmpty(prevPath) + query,
|
||||
"Next": slashIfEmpty(nextPath) + query,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue