Documentation
¶
Index ¶
- Constants
- Variables
- func AllowedStoredMediaTypesString() string
- func BaseMediaType(mediaType string) string
- func ClassifyStoredMediaType(name string, data []byte) string
- func DetectMediaType(data []byte) string
- func HasSVGRootElement(data []byte) bool
- func IsAllowedStoredMediaType(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") // ErrUnsupportedStoredFileType indicates that classified file bytes do not // map to an allowed durable file type. ErrUnsupportedStoredFileType = xerrors.New("unsupported attachment type") )
Functions ¶
func AllowedStoredMediaTypesString ¶
func AllowedStoredMediaTypesString() string
AllowedStoredMediaTypesString returns the supported durable chat file 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 IsAllowedStoredMediaType ¶
IsAllowedStoredMediaType reports whether the media type is supported for durable chat file storage.
func IsCompatibleUploadMediaType ¶
IsCompatibleUploadMediaType reports whether an upload request that declared declaredMediaType may be stored as storedMediaType after byte classification. Exact matches are always compatible; the compatibility table only 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 preserve subtype detection even when the user-facing filename is overridden.
Types ¶
This section is empty.