You've already forked nyx
mirror of
https://github.com/rls-moe/nyx
synced 2025-12-16 09:30:41 +00:00
Added Moderation Tools, Captcha & Trollthrottle
This commit is contained in:
@@ -2,6 +2,7 @@ package board
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"github.com/GeertJohan/go.rice"
|
||||
"github.com/pressly/chi"
|
||||
"github.com/tidwall/buntdb"
|
||||
@@ -24,26 +25,48 @@ var riceConf = rice.Config{
|
||||
var box = riceConf.MustFindBox("http/board/res/")
|
||||
|
||||
var (
|
||||
dirTmpl = template.New("board/dir")
|
||||
boardTmpl = template.New("board/board")
|
||||
threadTmpl = template.New("board/thread")
|
||||
tmpls = template.New("base")
|
||||
//dirTmpl = template.New("board/dir")
|
||||
//boardTmpl = template.New("board/board")
|
||||
//threadTmpl = template.New("board/thread")
|
||||
|
||||
hdlFMap = template.FuncMap{
|
||||
"renderText": resources.OperateReplyText,
|
||||
"dict": func(values ...interface{}) (map[string]interface{}, error) {
|
||||
if len(values)%2 != 0 {
|
||||
return nil, errors.New("invalid dict call")
|
||||
}
|
||||
dict := make(map[string]interface{}, len(values)/2)
|
||||
for i := 0; i < len(values); i += 2 {
|
||||
key, ok := values[i].(string)
|
||||
if !ok {
|
||||
return nil, errors.New("dict keys must be strings")
|
||||
}
|
||||
dict[key] = values[i+1]
|
||||
}
|
||||
return dict, nil
|
||||
},
|
||||
"rateSpam": resources.SpamScore,
|
||||
"makeCaptcha": resources.MakeCaptcha,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
dirTmpl, err = dirTmpl.Parse(box.MustString("dir.html"))
|
||||
tmpls = tmpls.Funcs(hdlFMap)
|
||||
tmpls, err = tmpls.New("thread/postlists").Parse(box.MustString("thread.tmpl.html"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
boardTmpl, err = boardTmpl.Funcs(hdlFMap).Parse(box.MustString("board.html"))
|
||||
_, err = tmpls.New("board/dir").Parse(box.MustString("dir.html"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
threadTmpl, err = threadTmpl.Funcs(hdlFMap).Parse(box.MustString("thread.html"))
|
||||
_, err = tmpls.New("board/board").Parse(box.MustString("board.html"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err = tmpls.New("board/thread").Parse(box.MustString("thread.html"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -57,6 +80,9 @@ func Router(r chi.Router) {
|
||||
r.Get("/:board/:thread/thread.html", serveThread)
|
||||
r.Get("/:board/:thread/:post/post.html", servePost)
|
||||
r.Post("/:board/:thread/reply.sh", handleNewReply)
|
||||
r.Handle("/captcha/:captchaId.png", resources.ServeCaptcha)
|
||||
r.Handle("/captcha/:captchaId.wav", resources.ServeCaptcha)
|
||||
r.Handle("/captcha/download/:captchaId.wav", resources.ServeCaptcha)
|
||||
}
|
||||
|
||||
func servePost(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -79,7 +105,7 @@ func serveDir(w http.ResponseWriter, r *http.Request) {
|
||||
errw.ErrorWriter(err, w, r)
|
||||
return
|
||||
}
|
||||
err = dirTmpl.Execute(dat, ctx)
|
||||
err = tmpls.ExecuteTemplate(dat, "board/dir", ctx)
|
||||
if err != nil {
|
||||
errw.ErrorWriter(err, w, r)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user