Support creating Document attachments
In particular, this will support audio attachments. Ref T872
This commit is contained in:
@@ -14,20 +14,34 @@ type Attachment struct {
|
||||
|
||||
type AttachmentType string
|
||||
|
||||
const AttachImage AttachmentType = "Image"
|
||||
const (
|
||||
AttachImage AttachmentType = "Image"
|
||||
AttachDocument AttachmentType = "Document"
|
||||
)
|
||||
|
||||
// NewImageAttachment creates a new Attachment from the given URL, setting the
|
||||
// correct type and automatically detecting the MediaType based on the file
|
||||
// extension.
|
||||
func NewImageAttachment(url string) Attachment {
|
||||
var imgType string
|
||||
return newAttachment(url, AttachImage)
|
||||
}
|
||||
|
||||
// NewDocumentAttachment creates a new Attachment from the given URL, setting the
|
||||
// correct type and automatically detecting the MediaType based on the file
|
||||
// extension.
|
||||
func NewDocumentAttachment(url string) Attachment {
|
||||
return newAttachment(url, AttachDocument)
|
||||
}
|
||||
|
||||
func newAttachment(url string, attachType AttachmentType) Attachment {
|
||||
var fileType string
|
||||
extIdx := strings.LastIndexByte(url, '.')
|
||||
if extIdx > -1 {
|
||||
imgType = mime.TypeByExtension(url[extIdx:])
|
||||
fileType = mime.TypeByExtension(url[extIdx:])
|
||||
}
|
||||
return Attachment{
|
||||
Type: AttachImage,
|
||||
Type: attachType,
|
||||
URL: url,
|
||||
MediaType: imgType,
|
||||
MediaType: fileType,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user