MCPcopy Index your code
hub / github.com/coder/coder / PrepareStoredFile

Function PrepareStoredFile

coderd/x/chatfiles/mime.go:107–120  ·  view source on GitHub ↗

PrepareStoredFile normalizes the display name, rejects empty normalized names, and classifies the file bytes using detectName when provided, so callers can preserve subtype detection even when the user-facing filename is overridden.

(name, detectName string, data []byte)

Source from the content-addressed store, hash-verified

105// callers can preserve subtype detection even when the user-facing filename is
106// overridden.
107func PrepareStoredFile(name, detectName string, data []byte) (storedName, mediaType string, err error) {
108 storedName = NormalizeStoredFileName(name)
109 if storedName == "" {
110 return "", "", ErrStoredFileNameRequired
111 }
112 if strings.TrimSpace(detectName) == "" {
113 detectName = storedName
114 }
115 mediaType = ClassifyStoredMediaType(detectName, data)
116 if !IsAllowedStoredMediaType(mediaType) {
117 return "", "", xerrors.Errorf("%w %q", ErrUnsupportedStoredFileType, mediaType)
118 }
119 return storedName, mediaType, nil
120}
121
122// PrepareRecordingArtifact normalizes the recording artifact name, rejects
123// empty normalized names, and verifies that the bytes match the expected

Callers 3

postChatFileMethod · 0.92
storeChatAttachmentMethod · 0.92
TestPrepareStoredFileFunction · 0.92

Calls 4

NormalizeStoredFileNameFunction · 0.85
ClassifyStoredMediaTypeFunction · 0.85
IsAllowedStoredMediaTypeFunction · 0.85
ErrorfMethod · 0.45

Tested by 1

TestPrepareStoredFileFunction · 0.74