Files
web-core-fr-gp/activitystreams/attachment.go
T

34 lines
760 B
Go
Raw Normal View History

package activitystreams
2021-03-24 15:45:58 -04:00
import (
"mime"
"strings"
)
type Attachment struct {
Type AttachmentType `json:"type"`
URL string `json:"url"`
MediaType string `json:"mediaType"`
Name string `json:"name"`
}
type AttachmentType string
const AttachImage AttachmentType = "Image"
2021-03-24 15:45:58 -04:00
// 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 {
2021-03-24 15:45:58 -04:00
var imgType string
extIdx := strings.LastIndexByte(url, '.')
if extIdx > -1 {
imgType = mime.TypeByExtension(url[extIdx:])
}
return Attachment{
2021-03-24 15:45:58 -04:00
Type: AttachImage,
URL: url,
MediaType: imgType,
}
}