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

Function IsCompatibleUploadMediaType

coderd/x/chatfiles/mime.go:149–166  ·  view source on GitHub ↗

IsCompatibleUploadMediaType reports whether an upload request that declared declaredMediaType may be stored as storedMediaType after byte classification. Exact matches are always compatible. Clients that declare application/octet-stream are treated as "unknown", so the classified bytes decide the st

(declaredMediaType, storedMediaType string)

Source from the content-addressed store, hash-verified

147// refinements like text/plain uploads that safely store as richer text
148// subtypes.
149func IsCompatibleUploadMediaType(declaredMediaType, storedMediaType string) bool {
150 declaredMediaType = BaseMediaType(declaredMediaType)
151 storedMediaType = BaseMediaType(storedMediaType)
152
153 if declaredMediaType == storedMediaType || declaredMediaType == "application/octet-stream" {
154 return true
155 }
156 if declaredMediaType != "text/plain" {
157 return false
158 }
159
160 switch storedMediaType {
161 case "text/markdown", "text/csv", "application/json":
162 return true
163 default:
164 return false
165 }
166}
167
168// HasSVGRootElement reports whether the provided file bytes decode to an SVG
169// root element. This catches SVG content even when generic sniffers classify it

Callers 2

postChatFileMethod · 0.92

Calls 1

BaseMediaTypeFunction · 0.85

Tested by 1