MCPcopy Index your code
hub / github.com/docker/docker-agent / processDocumentPart

Function processDocumentPart

pkg/chat/attach.go:192–210  ·  view source on GitHub ↗

processDocumentPart handles MessagePartTypeDocument. Images with InlineData are transcoded; other already-resolved documents pass through.

(part MessagePart)

Source from the content-addressed store, hash-verified

190// processDocumentPart handles MessagePartTypeDocument.
191// Images with InlineData are transcoded; other already-resolved documents pass through.
192func processDocumentPart(part MessagePart) (Document, *ImageResizeResult, error) {
193 if part.Document == nil {
194 return Document{}, nil, errors.New("ProcessAttachment: document part has nil Document field")
195 }
196 doc := *part.Document
197
198 if len(doc.Source.InlineData) > 0 {
199 if IsImageMimeType(doc.MimeType) {
200 return transcodeImageWithMeta(doc.Name, doc.Source.InlineData, doc.MimeType)
201 }
202 return doc, nil, nil
203 }
204
205 if doc.Source.InlineText != "" {
206 return doc, nil, nil
207 }
208
209 return Document{}, nil, fmt.Errorf("ProcessAttachment: document %q has no inline content (InlineData and InlineText are both empty)", doc.Name)
210}
211
212// transcodeImageWithMeta runs bytes through ResizeImage to normalise the image
213// to JPEG or PNG within provider limits, then wraps the result in a Document.

Callers 1

Calls 3

IsImageMimeTypeFunction · 0.85
transcodeImageWithMetaFunction · 0.85
NewMethod · 0.45

Tested by

no test coverage detected