-
Notifications
You must be signed in to change notification settings - Fork 1
/
tombstone.go
79 lines (65 loc) · 1.35 KB
/
tombstone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package handlers
import (
"fmt"
"net/http"
"strconv"
"strings"
DM "github.com/kycklingar/PBooru/DataManager"
paginate "github.com/kycklingar/PBooru/handlers/paginator"
)
func tombstoneSearchHandler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
http.Redirect(w, r, "/tombstone/?"+r.Form.Encode(), http.StatusSeeOther)
}
func tombstoneHandler(w http.ResponseWriter, r *http.Request) {
var (
err error
limit = 30
page struct {
UserInfo UserInfo
Tombstone []DM.Tombstone
Paginator paginate.Paginator
Total int
}
)
_, page.UserInfo = getUser(w, r)
var query = r.FormValue("reason")
var currentPage int
uri := splitURI(r.URL.Path)
if len(uri) <= 1 {
currentPage = 1
} else {
currentPage, err = strconv.Atoi(uri[1])
if err != nil {
currentPage = 1
}
}
page.Total, page.Tombstone, err = DM.GetTombstonedPosts(query, limit, (currentPage-1)*limit)
if internalError(w, err) {
return
}
for _, p := range page.Tombstone {
err := p.Post.QMul(
DM.DB,
DM.PFCid,
DM.PFThumbnails,
DM.PFMime,
DM.PFRemoved,
)
if internalError(w, err) {
return
}
}
var q = r.Form.Encode()
if q != "" {
q = "?" + q
}
page.Paginator = paginate.New(
currentPage,
page.Total,
limit,
30,
fmt.Sprintf("/tombstone/%%d/%s", strings.ReplaceAll(q, "%", "%%")),
)
renderTemplate(w, "tombstone", page)
}