This commit is contained in:
2026-11-12 17:28:28 +03:00
parent 276dbdad8a
commit 4fae7d7e87
103 changed files with 10742 additions and 54 deletions
+54
View File
@@ -0,0 +1,54 @@
package httpapi
import (
"net/http"
"strings"
"unicode"
"unicode/utf8"
"mtusi2026/internal/idgen"
)
func validText(s string, max int) bool {
n := utf8.RuneCountInString(s)
if n < 1 || n > max {
return false
}
hasContent := false
for _, r := range s {
if r == 0 {
return false
}
if !unicode.IsSpace(r) {
hasContent = true
}
}
return hasContent
}
func parseCursor(r *http.Request) (string, bool) {
q := r.URL.Query()
if !q.Has("cursor") {
return "", true
}
c := q.Get("cursor")
return c, c != ""
}
func chatIDParam(w http.ResponseWriter, r *http.Request, requestID string) (string, bool) {
id := r.PathValue("chat_id")
if !idgen.IsValidUUID(id) {
writeError(w, http.StatusBadRequest, requestID, codeInvalidRequest, "invalid chat_id")
return "", false
}
return strings.ToLower(id), true
}
func uuidParam(w http.ResponseWriter, r *http.Request, requestID, name string) (string, bool) {
id := r.PathValue(name)
if !idgen.IsValidUUID(id) {
writeError(w, http.StatusBadRequest, requestID, codeInvalidRequest, "invalid "+name)
return "", false
}
return strings.ToLower(id), true
}