Documentation
¶
Index ¶
- Constants
- Variables
- func AllowedPromptInputMediaTypesString() string
- func BaseMediaType(mediaType string) string
- func ClassifyStoredMediaType(name string, data []byte) string
- func DetectMediaType(data []byte) string
- func HasSVGRootElement(data []byte) bool
- func IsAllowedPromptInputMediaType(mediaType string) bool
- func IsCompatibleUploadMediaType(declaredMediaType, storedMediaType string) bool
- func IsInlineRenderableStoredMediaType(mediaType string) bool
- func NormalizeStoredFileName(name string) string
- func PrepareRecordingArtifact(name, expectedMediaType string, data []byte) (storedName, mediaType string, err error)
- func PrepareStoredFile(name, detectName string, data []byte) (storedName, mediaType string, err error)
Constants ¶
const MaxStoredFileNameBytes = 255
Variables ¶
var ( // ErrStoredFileNameRequired indicates that a durable file name is empty // after normalization. ErrStoredFileNameRequired = xerrors.New("stored file name is required") )
Functions ¶
func AllowedPromptInputMediaTypesString ¶ added in v2.35.0
func AllowedPromptInputMediaTypesString() string
AllowedPromptInputMediaTypesString returns the supported prompt input media types as a comma-separated list.
func BaseMediaType ¶
BaseMediaType strips parameters from a media type.
func ClassifyStoredMediaType ¶
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.
func DetectMediaType ¶
DetectMediaType detects the base media type of the given file contents.
func HasSVGRootElement ¶
HasSVGRootElement reports whether the provided file bytes decode to an SVG root element. This catches SVG content even when generic sniffers classify it as text or XML.
func IsAllowedPromptInputMediaType ¶ added in v2.35.0
IsAllowedPromptInputMediaType reports whether the media type is supported for user-provided prompt input.
func IsCompatibleUploadMediaType ¶
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 stored type. The compatibility table also covers explicit refinements like text/plain uploads that safely store as richer text subtypes.
func IsInlineRenderableStoredMediaType ¶
IsInlineRenderableStoredMediaType reports whether a stored chat file may be served with Content-Disposition: inline. PDFs remain storable but download-only because browser PDF viewers have a broader active-content attack surface than the other media types we allow inline.
func NormalizeStoredFileName ¶
NormalizeStoredFileName trims surrounding whitespace, strips control characters, and truncates the name to the durable storage byte limit without splitting UTF-8 runes.
func PrepareRecordingArtifact ¶
func PrepareRecordingArtifact(name, expectedMediaType string, data []byte) (storedName, mediaType string, err error)
PrepareRecordingArtifact normalizes the recording artifact name, rejects empty normalized names, and verifies that the bytes match the expected recording media type.
func PrepareStoredFile ¶
func PrepareStoredFile(name, detectName string, data []byte) (storedName, mediaType string, err error)
PrepareStoredFile normalizes the display name, rejects empty normalized names, and classifies the file bytes using detectName when provided, so callers can apply the right policy for their file source.
Types ¶
This section is empty.