2017-03-12 19:37:53 +00:00
|
|
|
package board
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/pressly/chi"
|
|
|
|
"github.com/tidwall/buntdb"
|
|
|
|
"go.rls.moe/nyx/http/errw"
|
|
|
|
"go.rls.moe/nyx/http/middle"
|
|
|
|
"go.rls.moe/nyx/resources"
|
2017-03-13 17:45:23 +00:00
|
|
|
_ "image/gif"
|
|
|
|
_ "image/jpeg"
|
2017-03-12 19:37:53 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func handleNewReply(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
|
|
|
errw.ErrorWriter(err, w, r)
|
|
|
|
return
|
|
|
|
}
|
2017-03-15 08:13:15 +00:00
|
|
|
err = r.ParseMultipartForm(4 * 1024 * 1024)
|
2017-03-13 17:45:23 +00:00
|
|
|
if err != nil {
|
|
|
|
errw.ErrorWriter(err, w, r)
|
|
|
|
return
|
|
|
|
}
|
2017-03-12 19:37:53 +00:00
|
|
|
|
2017-03-13 15:04:00 +00:00
|
|
|
if !resources.VerifyCaptcha(r) {
|
|
|
|
http.Redirect(w, r,
|
|
|
|
fmt.Sprintf("/%s/%s/thread.html?err=wrong_captcha",
|
|
|
|
chi.URLParam(r, "board"), chi.URLParam(r, "thread")),
|
|
|
|
http.StatusSeeOther)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-03-12 19:37:53 +00:00
|
|
|
var reply = &resources.Reply{}
|
|
|
|
|
2017-03-15 08:13:15 +00:00
|
|
|
err = parseReply(r, reply)
|
|
|
|
if err == trollThrottle {
|
2017-03-13 15:04:00 +00:00
|
|
|
http.Redirect(w, r,
|
|
|
|
fmt.Sprintf("/%s/%s/thread.html?err=trollthrottle",
|
|
|
|
chi.URLParam(r, "board"), chi.URLParam(r, "thread")),
|
|
|
|
http.StatusSeeOther)
|
|
|
|
return
|
2017-03-15 08:13:15 +00:00
|
|
|
} else if err != nil {
|
|
|
|
errw.ErrorWriter(err, w, r)
|
|
|
|
return
|
2017-03-12 19:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
db := middle.GetDB(r)
|
|
|
|
if err = db.Update(func(tx *buntdb.Tx) error {
|
|
|
|
thread, err := resources.GetThread(tx, r.Host, reply.Board, reply.Thread)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return resources.NewReply(tx, r.Host, reply.Board, thread, reply, false)
|
|
|
|
}); err != nil {
|
|
|
|
errw.ErrorWriter(err, w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
http.Redirect(w, r, fmt.Sprintf("/%s/%d/thread.html", chi.URLParam(r, "board"), reply.Thread), http.StatusSeeOther)
|
|
|
|
}
|