forked from mtusi2026/mtusi2026lab4
feat: two-store reconciler with safe repair and cost measurement (grade 5, track 2)
This commit is contained in:
@@ -53,7 +53,13 @@ func (h *Handler) DownloadAttachment(w http.ResponseWriter, r *http.Request) {
|
||||
h.fail(w, r, err)
|
||||
return
|
||||
}
|
||||
attachment, content, err := h.attachments.Open(r.Context(), actor(r), id, r.URL.Query().Get("variant"))
|
||||
query := r.URL.Query()
|
||||
variant := query.Get("variant")
|
||||
if query.Has("variant") && variant == "" {
|
||||
h.fail(w, r, badRequest("variant must be original"))
|
||||
return
|
||||
}
|
||||
attachment, content, err := h.attachments.Open(r.Context(), actor(r), id, variant)
|
||||
if err != nil {
|
||||
h.fail(w, r, err)
|
||||
return
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
"uuid"
|
||||
|
||||
@@ -19,8 +20,8 @@ type createChatRequest struct {
|
||||
}
|
||||
|
||||
type createMessageRequest struct {
|
||||
Text *string `json:"text"`
|
||||
AttachmentIDs *[]string `json:"attachment_ids"`
|
||||
Text *string `json:"text"`
|
||||
AttachmentIDs json.RawMessage `json:"attachment_ids"`
|
||||
}
|
||||
|
||||
type userResponse struct {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"uuid"
|
||||
@@ -31,10 +33,19 @@ func (h *Handler) SendMessage(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
var attachmentIDs []uuid.UUID
|
||||
if req.AttachmentIDs != nil {
|
||||
attachmentIDs = make([]uuid.UUID, len(*req.AttachmentIDs))
|
||||
for i, raw := range *req.AttachmentIDs {
|
||||
id, ok := parseUUID(raw)
|
||||
if len(req.AttachmentIDs) > 0 {
|
||||
if bytes.Equal(bytes.TrimSpace(req.AttachmentIDs), []byte("null")) {
|
||||
h.fail(w, r, badRequest("attachment_ids must be an array of UUIDs"))
|
||||
return
|
||||
}
|
||||
var raw []string
|
||||
if err := json.Unmarshal(req.AttachmentIDs, &raw); err != nil {
|
||||
h.fail(w, r, badRequest("attachment_ids must be an array of UUIDs"))
|
||||
return
|
||||
}
|
||||
attachmentIDs = make([]uuid.UUID, len(raw))
|
||||
for i, value := range raw {
|
||||
id, ok := parseUUID(value)
|
||||
if !ok {
|
||||
h.fail(w, r, badRequest("attachment_ids must contain UUIDs"))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user