fix: validate message request fields

This commit is contained in:
2026-10-30 14:01:03 +03:00
parent 3815be3493
commit 05d9bb0ff2
3 changed files with 65 additions and 6 deletions
+4 -6
View File
@@ -208,18 +208,16 @@ func (s *Server) messages(w http.ResponseWriter, r *http.Request) *apiError {
if !valid {
return invalidRequest()
}
var input struct {
Text string `json:"text"`
AttachmentIDs []string `json:"attachment_ids"`
}
var input createMessageRequest
if err := readJSON(w, r, &input); err != nil {
return err
}
if !validMessage(input.Text, input.AttachmentIDs) || !canonicalAttachmentIDs(input.AttachmentIDs) {
text, attachmentIDs, valid := input.values()
if !valid || !validMessage(text, attachmentIDs) || !canonicalAttachmentIDs(attachmentIDs) {
return invalidRequest()
}
message, replay, err := s.messageRepository.CreateMessage(
r.Context(), chatID, user.ID, input.Text, input.AttachmentIDs, key, s.idempotencyTTL,
r.Context(), chatID, user.ID, text, attachmentIDs, key, s.idempotencyTTL,
)
if errors.Is(err, model.ErrNotFound) {
return notFound()