0

Add mediaType to federated attachments + fix image description. For #1840

This commit is contained in:
Gabe Kangas 2022-04-27 16:31:49 -07:00
parent a1377c3338
commit b378728eba
No known key found for this signature in database
GPG Key ID: 9A56337728BC81EA
2 changed files with 11 additions and 4 deletions

View File

@ -20,7 +20,7 @@ func CreateCreateActivity(id string, localAccountIRI *url.URL) vocab.ActivityStr
} }
// AddImageAttachmentToNote will add the provided image URL to the provided note object. // AddImageAttachmentToNote will add the provided image URL to the provided note object.
func AddImageAttachmentToNote(note vocab.ActivityStreamsNote, image string) { func AddImageAttachmentToNote(note vocab.ActivityStreamsNote, image, mediaType string) {
imageURL, err := url.Parse(image) imageURL, err := url.Parse(image)
if err != nil { if err != nil {
return return
@ -40,9 +40,13 @@ func AddImageAttachmentToNote(note vocab.ActivityStreamsNote, image string) {
imageProp := streams.NewActivityStreamsImageProperty() imageProp := streams.NewActivityStreamsImageProperty()
imageProp.AppendActivityStreamsImage(apImage) imageProp.AppendActivityStreamsImage(apImage)
imageDescription := streams.NewActivityStreamsContentProperty() imageDescription := streams.NewActivityStreamsNameProperty()
imageDescription.AppendXMLSchemaString("Live stream preview") imageDescription.AppendXMLSchemaString("Live stream preview")
apImage.SetActivityStreamsContent(imageDescription) apImage.SetActivityStreamsName(imageDescription)
mediaTypeProperty := streams.NewActivityStreamsMediaTypeProperty()
mediaTypeProperty.Set(mediaType)
apImage.SetActivityStreamsMediaType(mediaTypeProperty)
attachments.AppendActivityStreamsImage(apImage) attachments.AppendActivityStreamsImage(apImage)

View File

@ -76,18 +76,21 @@ func SendLive() error {
previewURL, err := url.Parse(data.GetServerURL()) previewURL, err := url.Parse(data.GetServerURL())
if err == nil { if err == nil {
var imageToAttach string var imageToAttach string
var mediaType string
previewGif := filepath.Join(config.WebRoot, "preview.gif") previewGif := filepath.Join(config.WebRoot, "preview.gif")
thumbnailJpg := filepath.Join(config.WebRoot, "thumbnail.jpg") thumbnailJpg := filepath.Join(config.WebRoot, "thumbnail.jpg")
uniquenessString := shortid.MustGenerate() uniquenessString := shortid.MustGenerate()
if utils.DoesFileExists(previewGif) { if utils.DoesFileExists(previewGif) {
imageToAttach = "preview.gif" imageToAttach = "preview.gif"
mediaType = "image/gif"
} else if utils.DoesFileExists(thumbnailJpg) { } else if utils.DoesFileExists(thumbnailJpg) {
imageToAttach = "thumbnail.jpg" imageToAttach = "thumbnail.jpg"
mediaType = "image/jpeg"
} }
if imageToAttach != "" { if imageToAttach != "" {
previewURL.Path = imageToAttach previewURL.Path = imageToAttach
previewURL.RawQuery = "us=" + uniquenessString previewURL.RawQuery = "us=" + uniquenessString
apmodels.AddImageAttachmentToNote(note, previewURL.String()) apmodels.AddImageAttachmentToNote(note, previewURL.String(), mediaType)
} }
} }