46 lines
834 B
Go
46 lines
834 B
Go
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
|
|
}
|