1
0
Fork 0

Replaced GetURLParam with httpr.Param.

This commit is contained in:
Alexander Andreev 2023-05-27 20:56:32 +04:00
parent 7d9dc27411
commit 2324d720f5
Signed by: Arav
GPG Key ID: D22A817D95815393
3 changed files with 14 additions and 11 deletions

View File

@ -6,6 +6,7 @@ import (
"net/http"
"time"
"git.arav.su/Arav/httpr"
"git.arav.su/Arav/justcaptcha/pkg/captcha"
"git.arav.su/Arav/justcaptcha/pkg/captcha/inmemdb"
"git.arav.su/Arav/justcaptcha/pkg/dwcaptcha"
@ -28,7 +29,7 @@ func (h *CaptchaApiHandlers) New(w http.ResponseWriter, r *http.Request) {
}
func (h *CaptchaApiHandlers) Solve(w http.ResponseWriter, r *http.Request) {
captchaID := captcha.ID(GetURLParam(r, "id"))
captchaID := captcha.ID(httpr.Param(r, "id"))
if r.URL.Query().Has("remove") {
inmemdb.Remove(captchaID)
@ -45,7 +46,7 @@ func (h *CaptchaApiHandlers) Solve(w http.ResponseWriter, r *http.Request) {
}
func (h *CaptchaApiHandlers) Image(w http.ResponseWriter, r *http.Request) {
id := captcha.ID(GetURLParam(r, "id"))
id := captcha.ID(httpr.Param(r, "id"))
image := inmemdb.Image(id, r.URL.Query().Get("style"))
if image == nil {

View File

@ -5,6 +5,7 @@ import (
"strconv"
"strings"
"git.arav.su/Arav/httpr"
"git.arav.su/Arav/justcaptcha/pkg/captcha"
"git.arav.su/Arav/justcaptcha/pkg/captcha/inmemdb"
"git.arav.su/Arav/justguestbook"
@ -78,7 +79,7 @@ func (h *GuestbookApiHandlers) Edit(w http.ResponseWriter, r *http.Request) {
return
}
entry.ID, _ = strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
entry.ID, _ = strconv.ParseInt(httpr.Param(r, "id"), 10, 64)
}
if err = h.db.EditEntry(entry); err != nil {
@ -89,7 +90,7 @@ func (h *GuestbookApiHandlers) Edit(w http.ResponseWriter, r *http.Request) {
}
func (h *GuestbookApiHandlers) Delete(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
id, _ := strconv.ParseInt(httpr.Param(r, "id"), 10, 64)
if err := h.db.DeleteEntry(id); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@ -103,7 +104,7 @@ func (h *GuestbookApiHandlers) Reply(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
r.ParseForm()
id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
id, _ := strconv.ParseInt(httpr.Param(r, "id"), 10, 64)
message := strings.ReplaceAll(r.FormValue("message"), "\r\n", "\n")
message = strings.ReplaceAll(message, "\n\r", "\n")
@ -129,7 +130,7 @@ func (h *GuestbookApiHandlers) EditReply(w http.ResponseWriter, r *http.Request)
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
r.ParseForm()
id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
id, _ := strconv.ParseInt(httpr.Param(r, "id"), 10, 64)
message := strings.ReplaceAll(r.FormValue("message"), "\r\n", "\n")
message = strings.ReplaceAll(message, "\n\r", "\n")
@ -148,7 +149,7 @@ func (h *GuestbookApiHandlers) EditReply(w http.ResponseWriter, r *http.Request)
}
func (h *GuestbookApiHandlers) DeleteReply(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
id, _ := strconv.ParseInt(httpr.Param(r, "id"), 10, 64)
if err := h.db.DeleteReply(id); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}

View File

@ -6,6 +6,7 @@ import (
"strings"
"git.arav.su/Arav/dwelling-home/pkg/mindflow"
"git.arav.su/Arav/httpr"
)
type MindflowApiHandlers struct {
@ -96,7 +97,7 @@ func (h *MindflowApiHandlers) EditPost(w http.ResponseWriter, r *http.Request) {
return
}
post.ID, _ = strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
post.ID, _ = strconv.ParseInt(httpr.Param(r, "id"), 10, 64)
}
if err = h.db.EditPost(post); err != nil {
@ -106,7 +107,7 @@ func (h *MindflowApiHandlers) EditPost(w http.ResponseWriter, r *http.Request) {
}
func (h *MindflowApiHandlers) DeletePost(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
id, _ := strconv.ParseInt(httpr.Param(r, "id"), 10, 64)
if err := h.db.DeletePost(id); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@ -147,7 +148,7 @@ func (h *MindflowApiHandlers) EditCategory(w http.ResponseWriter, r *http.Reques
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
category.ID, _ = strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
category.ID, _ = strconv.ParseInt(httpr.Param(r, "id"), 10, 64)
} else {
http.Error(w, "empty category id passed", http.StatusBadRequest)
return
@ -160,7 +161,7 @@ func (h *MindflowApiHandlers) EditCategory(w http.ResponseWriter, r *http.Reques
}
func (h *MindflowApiHandlers) DeleteCategory(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
id, _ := strconv.ParseInt(httpr.Param(r, "id"), 10, 64)
if err := h.db.DeleteCategory(id); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return