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

Function PrepareRecordingArtifact

coderd/x/chatfiles/mime.go:125–140  ·  view source on GitHub ↗

PrepareRecordingArtifact normalizes the recording artifact name, rejects empty normalized names, and verifies that the bytes match the expected recording media type.

(name, expectedMediaType string, data []byte)

Source from the content-addressed store, hash-verified

123// empty normalized names, and verifies that the bytes match the expected
124// recording media type.
125func PrepareRecordingArtifact(name, expectedMediaType string, data []byte) (storedName, mediaType string, err error) {
126 expectedMediaType = BaseMediaType(expectedMediaType)
127 if _, ok := recordingArtifactMediaTypes[expectedMediaType]; !ok {
128 return "", "", xerrors.Errorf("unsupported recording artifact type %q", expectedMediaType)
129 }
130
131 storedName = NormalizeStoredFileName(name)
132 if storedName == "" {
133 return "", "", ErrStoredFileNameRequired
134 }
135 mediaType = DetectMediaType(data)
136 if mediaType != expectedMediaType {
137 return "", "", xerrors.Errorf("recording artifact type mismatch: expected %q, detected %q", expectedMediaType, mediaType)
138 }
139 return storedName, mediaType, nil
140}
141
142// IsCompatibleUploadMediaType reports whether an upload request that declared
143// declaredMediaType may be stored as storedMediaType after byte

Callers 2

Calls 4

BaseMediaTypeFunction · 0.85
NormalizeStoredFileNameFunction · 0.85
DetectMediaTypeFunction · 0.85
ErrorfMethod · 0.45

Tested by 1