mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-02 07:02:25 -06:00
[bugfix] Fix images not being processed correctly sometimes (#437)
* bump exif-terminator to latest version * add and test giant turnip from turnip.farm * don't error if content property is nil
This commit is contained in:
parent
36b2f2b4e6
commit
25cab0e1f4
22 changed files with 245 additions and 46 deletions
|
|
@ -1460,7 +1460,7 @@ type ActivityWithSignature struct {
|
|||
// A struct of accounts needs to be passed in because the activities will also be bundled along with
|
||||
// their requesting signatures.
|
||||
func NewTestActivities(accounts map[string]*gtsmodel.Account) map[string]ActivityWithSignature {
|
||||
dmForZork := newNote(
|
||||
dmForZork := newAPNote(
|
||||
URLMustParse("http://fossbros-anonymous.io/users/foss_satan/statuses/5424b153-4553-4f30-9358-7b92f7cd42f6"),
|
||||
URLMustParse("http://fossbros-anonymous.io/@foss_satan/5424b153-4553-4f30-9358-7b92f7cd42f6"),
|
||||
time.Now(),
|
||||
|
|
@ -1470,15 +1470,17 @@ func NewTestActivities(accounts map[string]*gtsmodel.Account) map[string]Activit
|
|||
[]*url.URL{URLMustParse("http://localhost:8080/users/the_mighty_zork")},
|
||||
nil,
|
||||
true,
|
||||
[]vocab.ActivityStreamsMention{})
|
||||
createDmForZork := wrapNoteInCreate(
|
||||
[]vocab.ActivityStreamsMention{},
|
||||
nil,
|
||||
)
|
||||
createDmForZork := wrapAPNoteInCreate(
|
||||
URLMustParse("http://fossbros-anonymous.io/users/foss_satan/statuses/5424b153-4553-4f30-9358-7b92f7cd42f6/activity"),
|
||||
URLMustParse("http://fossbros-anonymous.io/users/foss_satan"),
|
||||
time.Now(),
|
||||
dmForZork)
|
||||
createDmForZorkSig, createDmForZorkDigest, creatDmForZorkDate := GetSignatureForActivity(createDmForZork, accounts["remote_account_1"].PublicKeyURI, accounts["remote_account_1"].PrivateKey, URLMustParse(accounts["local_account_1"].InboxURI))
|
||||
|
||||
forwardedMessage := newNote(
|
||||
forwardedMessage := newAPNote(
|
||||
URLMustParse("http://example.org/users/some_user/statuses/afaba698-5740-4e32-a702-af61aa543bc1"),
|
||||
URLMustParse("http://example.org/@some_user/afaba698-5740-4e32-a702-af61aa543bc1"),
|
||||
time.Now(),
|
||||
|
|
@ -1488,8 +1490,10 @@ func NewTestActivities(accounts map[string]*gtsmodel.Account) map[string]Activit
|
|||
[]*url.URL{URLMustParse(pub.PublicActivityPubIRI)},
|
||||
nil,
|
||||
false,
|
||||
[]vocab.ActivityStreamsMention{})
|
||||
createForwardedMessage := wrapNoteInCreate(
|
||||
[]vocab.ActivityStreamsMention{},
|
||||
nil,
|
||||
)
|
||||
createForwardedMessage := wrapAPNoteInCreate(
|
||||
URLMustParse("http://example.org/users/some_user/statuses/afaba698-5740-4e32-a702-af61aa543bc1/activity"),
|
||||
URLMustParse("http://example.org/users/some_user"),
|
||||
time.Now(),
|
||||
|
|
@ -1520,8 +1524,14 @@ func NewTestFediPeople() map[string]vocab.ActivityStreamsPerson {
|
|||
}
|
||||
newPerson1Pub := &newPerson1Priv.PublicKey
|
||||
|
||||
turnipLover6969Priv, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
turnipLover6969Pub := &turnipLover6969Priv.PublicKey
|
||||
|
||||
return map[string]vocab.ActivityStreamsPerson{
|
||||
"https://unknown-instance.com/users/brand_new_person": newPerson(
|
||||
"https://unknown-instance.com/users/brand_new_person": newAPPerson(
|
||||
URLMustParse("https://unknown-instance.com/users/brand_new_person"),
|
||||
URLMustParse("https://unknown-instance.com/users/brand_new_person/following"),
|
||||
URLMustParse("https://unknown-instance.com/users/brand_new_person/followers"),
|
||||
|
|
@ -1541,6 +1551,26 @@ func NewTestFediPeople() map[string]vocab.ActivityStreamsPerson {
|
|||
"image/png",
|
||||
false,
|
||||
),
|
||||
"https://turnip.farm/users/turniplover6969": newAPPerson(
|
||||
URLMustParse("https://turnip.farm/users/turniplover6969"),
|
||||
URLMustParse("https://turnip.farm/users/turniplover6969/following"),
|
||||
URLMustParse("https://turnip.farm/users/turniplover6969/followers"),
|
||||
URLMustParse("https://turnip.farm/users/turniplover6969/inbox"),
|
||||
URLMustParse("https://turnip.farm/users/turniplover6969/outbox"),
|
||||
URLMustParse("https://turnip.farm/users/turniplover6969/collections/featured"),
|
||||
"turniplover6969",
|
||||
"Turnip Lover 6969",
|
||||
"I just think they're neat",
|
||||
URLMustParse("https://turnip.farm/@turniplover6969"),
|
||||
true,
|
||||
URLMustParse("https://turnip.farm/users/turniplover6969#main-key"),
|
||||
turnipLover6969Pub,
|
||||
nil,
|
||||
"image/jpeg",
|
||||
nil,
|
||||
"image/png",
|
||||
false,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1552,7 +1582,7 @@ func NewTestFediGroups() map[string]vocab.ActivityStreamsGroup {
|
|||
newGroup1Pub := &newGroup1Priv.PublicKey
|
||||
|
||||
return map[string]vocab.ActivityStreamsGroup{
|
||||
"https://unknown-instance.com/groups/some_group": newGroup(
|
||||
"https://unknown-instance.com/groups/some_group": newAPGroup(
|
||||
URLMustParse("https://unknown-instance.com/groups/some_group"),
|
||||
URLMustParse("https://unknown-instance.com/groups/some_group/following"),
|
||||
URLMustParse("https://unknown-instance.com/groups/some_group/followers"),
|
||||
|
|
@ -1592,6 +1622,11 @@ func NewTestFediAttachments(relativePath string) map[string]RemoteAttachmentFile
|
|||
panic(err)
|
||||
}
|
||||
|
||||
massiveFuckingTurnipBytes, err := os.ReadFile(fmt.Sprintf("%s/giant-turnip-world-record.jpg", relativePath))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return map[string]RemoteAttachmentFile{
|
||||
"https://s3-us-west-2.amazonaws.com/plushcity/media_attachments/files/106/867/380/219/163/828/original/88e8758c5f011439.jpg": {
|
||||
Data: beeBytes,
|
||||
|
|
@ -1601,12 +1636,16 @@ func NewTestFediAttachments(relativePath string) map[string]RemoteAttachmentFile
|
|||
Data: thoughtsOfDogBytes,
|
||||
ContentType: "image/jpeg",
|
||||
},
|
||||
"https://turnip.farm/attachments/f17843c7-015e-4251-9b5a-91389c49ee57.jpg": {
|
||||
Data: massiveFuckingTurnipBytes,
|
||||
ContentType: "image/jpeg",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NewTestFediStatuses() map[string]vocab.ActivityStreamsNote {
|
||||
return map[string]vocab.ActivityStreamsNote{
|
||||
"https://unknown-instance.com/users/brand_new_person/statuses/01FE4NTHKWW7THT67EF10EB839": newNote(
|
||||
"https://unknown-instance.com/users/brand_new_person/statuses/01FE4NTHKWW7THT67EF10EB839": newAPNote(
|
||||
URLMustParse("https://unknown-instance.com/users/brand_new_person/statuses/01FE4NTHKWW7THT67EF10EB839"),
|
||||
URLMustParse("https://unknown-instance.com/users/@brand_new_person/01FE4NTHKWW7THT67EF10EB839"),
|
||||
time.Now(),
|
||||
|
|
@ -1618,9 +1657,10 @@ func NewTestFediStatuses() map[string]vocab.ActivityStreamsNote {
|
|||
},
|
||||
[]*url.URL{},
|
||||
false,
|
||||
[]vocab.ActivityStreamsMention{},
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
"https://unknown-instance.com/users/brand_new_person/statuses/01FE5Y30E3W4P7TRE0R98KAYQV": newNote(
|
||||
"https://unknown-instance.com/users/brand_new_person/statuses/01FE5Y30E3W4P7TRE0R98KAYQV": newAPNote(
|
||||
URLMustParse("https://unknown-instance.com/users/brand_new_person/statuses/01FE5Y30E3W4P7TRE0R98KAYQV"),
|
||||
URLMustParse("https://unknown-instance.com/users/@brand_new_person/01FE5Y30E3W4P7TRE0R98KAYQV"),
|
||||
time.Now(),
|
||||
|
|
@ -1633,11 +1673,34 @@ func NewTestFediStatuses() map[string]vocab.ActivityStreamsNote {
|
|||
[]*url.URL{},
|
||||
false,
|
||||
[]vocab.ActivityStreamsMention{
|
||||
newMention(
|
||||
newAPMention(
|
||||
URLMustParse("http://localhost:8080/users/the_mighty_zork"),
|
||||
"@the_mighty_zork@localhost:8080",
|
||||
),
|
||||
},
|
||||
nil,
|
||||
),
|
||||
"https://turnip.farm/users/turniplover6969/statuses/70c53e54-3146-42d5-a630-83c8b6c7c042": newAPNote(
|
||||
URLMustParse("https://turnip.farm/users/turniplover6969/statuses/70c53e54-3146-42d5-a630-83c8b6c7c042"),
|
||||
URLMustParse("https://turnip.farm/@turniplover6969/70c53e54-3146-42d5-a630-83c8b6c7c042"),
|
||||
time.Now(),
|
||||
"",
|
||||
"",
|
||||
URLMustParse("https://turnip.farm/users/turniplover6969"),
|
||||
[]*url.URL{
|
||||
URLMustParse(pub.PublicActivityPubIRI),
|
||||
},
|
||||
[]*url.URL{},
|
||||
false,
|
||||
nil,
|
||||
[]vocab.ActivityStreamsImage{
|
||||
newAPImage(
|
||||
URLMustParse("https://turnip.farm/attachments/f17843c7-015e-4251-9b5a-91389c49ee57.jpg"),
|
||||
"image/jpeg",
|
||||
"",
|
||||
"",
|
||||
),
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
|
@ -1799,7 +1862,7 @@ func GetSignatureForDereference(pubKeyID string, privkey crypto.PrivateKey, dest
|
|||
return
|
||||
}
|
||||
|
||||
func newPerson(
|
||||
func newAPPerson(
|
||||
profileIDURI *url.URL,
|
||||
followingURI *url.URL,
|
||||
followersURI *url.URL,
|
||||
|
|
@ -1982,7 +2045,7 @@ func newPerson(
|
|||
return person
|
||||
}
|
||||
|
||||
func newGroup(
|
||||
func newAPGroup(
|
||||
profileIDURI *url.URL,
|
||||
followingURI *url.URL,
|
||||
followersURI *url.URL,
|
||||
|
|
@ -2165,7 +2228,7 @@ func newGroup(
|
|||
return group
|
||||
}
|
||||
|
||||
func newMention(uri *url.URL, namestring string) vocab.ActivityStreamsMention {
|
||||
func newAPMention(uri *url.URL, namestring string) vocab.ActivityStreamsMention {
|
||||
mention := streams.NewActivityStreamsMention()
|
||||
|
||||
hrefProp := streams.NewActivityStreamsHrefProperty()
|
||||
|
|
@ -2179,8 +2242,38 @@ func newMention(uri *url.URL, namestring string) vocab.ActivityStreamsMention {
|
|||
return mention
|
||||
}
|
||||
|
||||
// newNote returns a new activity streams note for the given parameters
|
||||
func newNote(
|
||||
func newAPImage(url *url.URL, mediaType string, imageDescription string, blurhash string) vocab.ActivityStreamsImage {
|
||||
image := streams.NewActivityStreamsImage()
|
||||
|
||||
if url != nil {
|
||||
urlProp := streams.NewActivityStreamsUrlProperty()
|
||||
urlProp.AppendIRI(url)
|
||||
image.SetActivityStreamsUrl(urlProp)
|
||||
}
|
||||
|
||||
if mediaType != "" {
|
||||
mediaTypeProp := streams.NewActivityStreamsMediaTypeProperty()
|
||||
mediaTypeProp.Set(mediaType)
|
||||
image.SetActivityStreamsMediaType(mediaTypeProp)
|
||||
}
|
||||
|
||||
if imageDescription != "" {
|
||||
nameProp := streams.NewActivityStreamsNameProperty()
|
||||
nameProp.AppendXMLSchemaString(imageDescription)
|
||||
image.SetActivityStreamsName(nameProp)
|
||||
}
|
||||
|
||||
if blurhash != "" {
|
||||
blurhashProp := streams.NewTootBlurhashProperty()
|
||||
blurhashProp.Set(blurhash)
|
||||
image.SetTootBlurhash(blurhashProp)
|
||||
}
|
||||
|
||||
return image
|
||||
}
|
||||
|
||||
// newAPNote returns a new activity streams note for the given parameters
|
||||
func newAPNote(
|
||||
noteID *url.URL,
|
||||
noteURL *url.URL,
|
||||
noteCreatedAt time.Time,
|
||||
|
|
@ -2190,7 +2283,8 @@ func newNote(
|
|||
noteTo []*url.URL,
|
||||
noteCC []*url.URL,
|
||||
noteSensitive bool,
|
||||
noteMentions []vocab.ActivityStreamsMention) vocab.ActivityStreamsNote {
|
||||
noteMentions []vocab.ActivityStreamsMention,
|
||||
noteAttachments []vocab.ActivityStreamsImage) vocab.ActivityStreamsNote {
|
||||
|
||||
// create the note itself
|
||||
note := streams.NewActivityStreamsNote()
|
||||
|
|
@ -2255,21 +2349,27 @@ func newNote(
|
|||
note.SetActivityStreamsCc(cc)
|
||||
}
|
||||
|
||||
// set note tags
|
||||
tag := streams.NewActivityStreamsTagProperty()
|
||||
|
||||
// mentions
|
||||
tag := streams.NewActivityStreamsTagProperty()
|
||||
for _, m := range noteMentions {
|
||||
tag.AppendActivityStreamsMention(m)
|
||||
}
|
||||
|
||||
note.SetActivityStreamsTag(tag)
|
||||
|
||||
// append any attachments as ActivityStreamsImage
|
||||
if noteAttachments != nil {
|
||||
attachmentProperty := streams.NewActivityStreamsAttachmentProperty()
|
||||
for _, a := range noteAttachments {
|
||||
attachmentProperty.AppendActivityStreamsImage(a)
|
||||
}
|
||||
note.SetActivityStreamsAttachment(attachmentProperty)
|
||||
}
|
||||
|
||||
return note
|
||||
}
|
||||
|
||||
// wrapNoteInCreate wraps the given activity streams note in a Create activity streams action
|
||||
func wrapNoteInCreate(createID *url.URL, createActor *url.URL, createPublished time.Time, createNote vocab.ActivityStreamsNote) vocab.ActivityStreamsCreate {
|
||||
// wrapAPNoteInCreate wraps the given activity streams note in a Create activity streams action
|
||||
func wrapAPNoteInCreate(createID *url.URL, createActor *url.URL, createPublished time.Time, createNote vocab.ActivityStreamsNote) vocab.ActivityStreamsCreate {
|
||||
// create the.... create
|
||||
create := streams.NewActivityStreamsCreate()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue