Fixed Content-Type checking. Get DB as an argument.
This commit is contained in:
parent
6ce598d193
commit
66be82d6b2
@ -11,7 +11,6 @@ import (
|
||||
"git.arav.su/Arav/justcaptcha/pkg/captcha"
|
||||
"git.arav.su/Arav/justcaptcha/pkg/captcha/inmemdb"
|
||||
"git.arav.su/Arav/justcaptcha/pkg/dwcaptcha"
|
||||
gbsqlite "git.arav.su/Arav/justguestbook/database/sqlite"
|
||||
"git.arav.su/Arav/justguestbook/guestbook"
|
||||
)
|
||||
|
||||
@ -23,12 +22,7 @@ type GuestbookApiHandlers struct {
|
||||
db guestbook.Guestbook
|
||||
}
|
||||
|
||||
func NewGuestbookApiHandlers(dbPath, owner string, pageSz int64) *GuestbookApiHandlers {
|
||||
db, err := gbsqlite.New(dbPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
func NewGuestbookApiHandlers(owner string, pageSz int64, db guestbook.Guestbook) *GuestbookApiHandlers {
|
||||
return &GuestbookApiHandlers{Owner: owner, PageSize: pageSz, db: db}
|
||||
}
|
||||
|
||||
@ -36,7 +30,7 @@ func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) {
|
||||
var entry *guestbook.Entry
|
||||
var err error
|
||||
|
||||
if r.Header.Get("Content-Type") == "application/x-www-form-urlencoded" {
|
||||
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
|
||||
r.ParseForm()
|
||||
|
||||
if !inmemdb.Solve(captcha.ID(r.FormValue("captcha_id")), captcha.Answer(r.FormValue("captcha_answer"))) {
|
||||
@ -72,7 +66,7 @@ func (h *GuestbookApiHandlers) Edit(w http.ResponseWriter, r *http.Request) {
|
||||
var entry *guestbook.Entry
|
||||
var err error
|
||||
|
||||
if r.Header.Get("Content-Type") == "application/x-www-form-urlencoded" {
|
||||
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
|
||||
r.ParseForm()
|
||||
|
||||
if r.FormValue("name") == "" {
|
||||
@ -112,7 +106,7 @@ func (h *GuestbookApiHandlers) Reply(w http.ResponseWriter, r *http.Request) {
|
||||
var reply *guestbook.Reply
|
||||
var err error
|
||||
|
||||
if r.Header.Get("Content-Type") == "application/x-www-form-urlencoded" {
|
||||
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
|
||||
r.ParseForm()
|
||||
id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
|
||||
reply, err = guestbook.NewReply(id, r.FormValue("message"))
|
||||
@ -132,7 +126,7 @@ func (h *GuestbookApiHandlers) EditReply(w http.ResponseWriter, r *http.Request)
|
||||
var reply *guestbook.Reply
|
||||
var err error
|
||||
|
||||
if r.Header.Get("Content-Type") == "application/x-www-form-urlencoded" {
|
||||
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
|
||||
r.ParseForm()
|
||||
id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
|
||||
reply, err = guestbook.NewReply(id, r.FormValue("message"))
|
||||
|
Loading…
Reference in New Issue
Block a user