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

Function ClassifyStoredMediaType

coderd/x/chatfiles/mime.go:203–222  ·  view source on GitHub ↗

ClassifyStoredMediaType returns the media type that durable chat storage would use for the given filename and bytes. Unsupported or blocked content is returned as its detected media type so callers can report the specific type.

(name string, data []byte)

Source from the content-addressed store, hash-verified

201// would use for the given filename and bytes. Unsupported or blocked content is
202// returned as its detected media type so callers can report the specific type.
203func ClassifyStoredMediaType(name string, data []byte) string {
204 if HasSVGRootElement(data) {
205 return "image/svg+xml"
206 }
207
208 mediaType := DetectMediaType(data)
209 switch mediaType {
210 case "image/png", "image/jpeg", "image/gif", "image/webp",
211 "text/markdown", "text/csv", "application/json",
212 "application/pdf", "application/xml", "text/xml":
213 return mediaType
214 case "text/plain":
215 return refineTextMediaType(name, data)
216 default:
217 if strings.HasPrefix(mediaType, "text/") {
218 return "text/plain"
219 }
220 return mediaType
221 }
222}
223
224func refineTextMediaType(name string, data []byte) string {
225 switch strings.ToLower(filepath.Ext(name)) {

Callers 2

PrepareStoredFileFunction · 0.85

Calls 3

HasSVGRootElementFunction · 0.85
DetectMediaTypeFunction · 0.85
refineTextMediaTypeFunction · 0.85

Tested by 1