Documentation
¶
Index ¶
- func ConvertCSV(data []byte, filename string) (string, error)
- func ConvertDOCX(data []byte, filename string) (string, error)
- func ConvertImage(ctx context.Context, data []byte, filename string, rawURL string, ...) (string, error)
- func ConvertJSON(data []byte, filename string) (string, error)
- func ConvertMD(data []byte) (string, error)
- func ConvertODT(data []byte, filename string) (string, error)
- func ConvertPDF(data []byte, filename string) (string, error)
- func ConvertTXT(data []byte, filename string) (string, error)
- func ConvertXLS(data []byte, filename string) (string, error)
- func ConvertXLSX(data []byte, filename string) (string, error)
- func ConvertXML(data []byte, filename string) (string, error)
- func DescribeImage(ctx context.Context, cfg *VisionConfig, data []byte, contentType string) (string, error)
- func FilenameFromURL(rawURL string) string
- type Type
- type VisionConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertCSV ¶
ConvertCSV converts CSV bytes to a markdown table.
func ConvertDOCX ¶
ConvertDOCX extracts text from DOCX bytes and returns markdown.
func ConvertImage ¶
func ConvertImage(ctx context.Context, data []byte, filename string, rawURL string, contentType string, vision *VisionConfig) (string, error)
ConvertImage creates a markdown representation for an image file. If VisionConfig is provided and configured, it uses Cloudflare Workers AI to generate an AI description. Otherwise, it outputs metadata + image embed.
func ConvertJSON ¶
ConvertJSON converts a JSON file to markdown with syntax highlighting.
func ConvertODT ¶
ConvertODT converts OpenDocument Text (.odt) bytes to markdown.
func ConvertPDF ¶
ConvertPDF extracts text from PDF bytes and returns markdown.
func ConvertTXT ¶
ConvertTXT converts a plain text file to markdown.
func ConvertXLS ¶
ConvertXLS converts legacy .xls (BIFF) bytes to markdown tables.
func ConvertXLSX ¶
ConvertXLSX converts XLSX bytes to markdown tables (one per sheet).
func ConvertXML ¶
ConvertXML converts an XML file to markdown with syntax highlighting.
func DescribeImage ¶
func DescribeImage(ctx context.Context, cfg *VisionConfig, data []byte, contentType string) (string, error)
DescribeImage sends the image to Cloudflare Workers AI vision and returns a text description.
func FilenameFromURL ¶
FilenameFromURL extracts a filename from a URL, decoding percent-encoding.
Types ¶
type Type ¶
type Type string
Type represents a supported file type.
const ( TypeHTML Type = "html" TypePDF Type = "pdf" TypeDOCX Type = "docx" TypeXLSX Type = "xlsx" TypeXLS Type = "xls" TypeODT Type = "odt" TypeCSV Type = "csv" TypeJSON Type = "json" TypeXML Type = "xml" TypeTXT Type = "txt" TypeMD Type = "md" TypePNG Type = "png" TypeJPEG Type = "jpeg" TypeGIF Type = "gif" TypeWEBP Type = "webp" TypeSVG Type = "svg" )
func Detect ¶
Detect determines file type using URL extension, final redirect URL, Content-Type, and magic bytes (in that order of priority).
func DetectFromBytes ¶
DetectFromBytes uses magic byte signatures to identify file types. For ZIP-based formats (DOCX/XLSX), it peeks inside the archive markers.
func DetectFromContentType ¶
DetectFromContentType determines the file type from an HTTP Content-Type header.
func DetectFromURL ¶
DetectFromURL guesses the file type from the URL path extension.
type VisionConfig ¶
VisionConfig holds configuration for Cloudflare Workers AI vision.
func (*VisionConfig) IsConfigured ¶
func (v *VisionConfig) IsConfigured() bool
IsConfigured returns true if the vision provider is configured.