chatfiles

package
v2.33.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MaxStoredFileNameBytes = 255

Variables

View Source
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

func BaseMediaType(mediaType string) string

BaseMediaType strips parameters from a media type.

func ClassifyStoredMediaType

func ClassifyStoredMediaType(name string, data []byte) string

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

func DetectMediaType(data []byte) string

DetectMediaType detects the base media type of the given file contents.

func HasSVGRootElement

func HasSVGRootElement(data []byte) bool

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

func IsAllowedStoredMediaType(mediaType string) bool

IsAllowedStoredMediaType reports whether the media type is supported for durable chat file storage.

func IsCompatibleUploadMediaType

func IsCompatibleUploadMediaType(declaredMediaType, storedMediaType string) bool

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

func IsInlineRenderableStoredMediaType(mediaType string) bool

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

func NormalizeStoredFileName(name string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL