MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / handleGetAttachment

Method handleGetAttachment

internal/httpapi/attachments.go:172–208  ·  view source on GitHub ↗
(ctx context.Context, in *attachmentParam)

Source from the content-addressed store, hash-verified

170}
171
172func (s *Server) handleGetAttachment(ctx context.Context, in *attachmentParam) (*attachmentOutput, error) {
173 ag, err := s.resolveOwnedAgent(ctx, in.Address)
174 if err != nil {
175 return nil, err
176 }
177 if s.deps.GetMessage == nil || s.deps.AttachmentStore == nil {
178 return nil, NewError(http.StatusInternalServerError, "internal_error", "attachment retrieval unavailable")
179 }
180 msg, err := s.deps.GetMessage(ctx, in.MessageID, ag.ID)
181 if err != nil || msg == nil {
182 return nil, NewError(http.StatusNotFound, "not_found", "message not found")
183 }
184 att, ok := mailparse.AttachmentAt(msg.RawMessage, in.Index)
185 if !ok {
186 return nil, NewError(http.StatusNotFound, "attachment_not_found", "no attachment at that index")
187 }
188 dl, exp, err := s.deps.AttachmentStore.DownloadURL(in.Address, in.MessageID, in.Index, attachmentDownloadTTL)
189 if err != nil {
190 return nil, NewError(http.StatusInternalServerError, "internal_error", "failed to mint download url")
191 }
192 view := AttachmentView{
193 Index: in.Index,
194 Filename: att.Filename,
195 ContentType: att.ContentType,
196 SizeBytes: len(att.Data),
197 DownloadURL: dl,
198 ExpiresAt: exp.UTC().Format(time.RFC3339),
199 }
200 if in.Inline {
201 if len(att.Data) > attachmentInlineMaxBytes {
202 return nil, NewError(http.StatusRequestEntityTooLarge, "attachment_too_large",
203 fmt.Sprintf("attachment is %d bytes; inline is capped at %d — use download_url instead", len(att.Data), attachmentInlineMaxBytes))
204 }
205 view.Data = base64.StdEncoding.EncodeToString(att.Data)
206 }
207 return &attachmentOutput{Body: view}, nil
208}
209
210// handleAttachmentDownload streams one attachment's bytes. It is a RAW chi route
211// (not Huma, not bearer): the capability TOKEN authorizes the download, so the

Callers

nothing calls this directly

Calls 4

resolveOwnedAgentMethod · 0.95
AttachmentAtFunction · 0.92
NewErrorFunction · 0.85
DownloadURLMethod · 0.65

Tested by

no test coverage detected