mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-11 02:37:29 -06:00
encode gifs properly
This commit is contained in:
parent
2fa5519d55
commit
2e7ac10d00
15 changed files with 304 additions and 66 deletions
|
|
@ -149,7 +149,7 @@ func (m *statusModule) statusCreatePOSTHandler(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
}
|
||||
newStatus.Mentions = menchies
|
||||
newStatus.GTSMentions = menchies
|
||||
|
||||
// convert tags to *gtsmodel.Tag
|
||||
tags, err := m.db.TagStringsToTags(util.DeriveHashtags(form.Status), authed.Account.ID, thisStatusID)
|
||||
|
|
@ -158,7 +158,7 @@ func (m *statusModule) statusCreatePOSTHandler(c *gin.Context) {
|
|||
c.JSON(http.StatusInternalServerError, gin.H{"error": "error generating hashtags from status"})
|
||||
return
|
||||
}
|
||||
newStatus.Tags = tags
|
||||
newStatus.GTSTags = tags
|
||||
|
||||
// convert emojis to *gtsmodel.Emoji
|
||||
emojis, err := m.db.EmojiStringsToEmojis(util.DeriveEmojis(form.Status), authed.Account.ID, thisStatusID)
|
||||
|
|
@ -167,7 +167,7 @@ func (m *statusModule) statusCreatePOSTHandler(c *gin.Context) {
|
|||
c.JSON(http.StatusInternalServerError, gin.H{"error": "error generating emojis from status"})
|
||||
return
|
||||
}
|
||||
newStatus.Emojis = emojis
|
||||
newStatus.GTSEmojis = emojis
|
||||
|
||||
/*
|
||||
FROM THIS POINT ONWARDS WE ARE HAPPY WITH THE STATUS -- it is valid and we will try to create it
|
||||
|
|
@ -180,7 +180,7 @@ func (m *statusModule) statusCreatePOSTHandler(c *gin.Context) {
|
|||
}
|
||||
|
||||
// change the status ID of the media attachments to the new status
|
||||
for _, a := range newStatus.Attachments {
|
||||
for _, a := range newStatus.GTSMediaAttachments {
|
||||
a.StatusID = newStatus.ID
|
||||
a.UpdatedAt = time.Now()
|
||||
if err := m.db.UpdateByID(a.ID, a); err != nil {
|
||||
|
|
@ -207,7 +207,7 @@ func (m *statusModule) statusCreatePOSTHandler(c *gin.Context) {
|
|||
}
|
||||
|
||||
mastoAttachments := []mastotypes.Attachment{}
|
||||
for _, a := range newStatus.Attachments {
|
||||
for _, a := range newStatus.GTSMediaAttachments {
|
||||
ma, err := m.mastoConverter.AttachmentToMasto(a)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
|
|
@ -217,7 +217,7 @@ func (m *statusModule) statusCreatePOSTHandler(c *gin.Context) {
|
|||
}
|
||||
|
||||
mastoMentions := []mastotypes.Mention{}
|
||||
for _, gtsm := range newStatus.Mentions {
|
||||
for _, gtsm := range newStatus.GTSMentions {
|
||||
mm, err := m.mastoConverter.MentionToMasto(gtsm)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
|
|
@ -433,7 +433,8 @@ func (m *statusModule) parseMediaIDs(form *advancedStatusCreateForm, thisAccount
|
|||
return nil
|
||||
}
|
||||
|
||||
attachments := []*gtsmodel.MediaAttachment{}
|
||||
GTSMediaAttachments := []*gtsmodel.MediaAttachment{}
|
||||
Attachments := []string{}
|
||||
for _, mediaID := range form.MediaIDs {
|
||||
// check these attachments exist
|
||||
a := >smodel.MediaAttachment{}
|
||||
|
|
@ -448,9 +449,11 @@ func (m *statusModule) parseMediaIDs(form *advancedStatusCreateForm, thisAccount
|
|||
if a.StatusID != "" || a.ScheduledStatusID != "" {
|
||||
return fmt.Errorf("media with id %s is already attached to a status", mediaID)
|
||||
}
|
||||
attachments = append(attachments, a)
|
||||
GTSMediaAttachments = append(GTSMediaAttachments, a)
|
||||
Attachments = append(Attachments, a.ID)
|
||||
}
|
||||
status.Attachments = attachments
|
||||
status.GTSMediaAttachments = GTSMediaAttachments
|
||||
status.Attachments = Attachments
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@ func (suite *StatusCreateTestSuite) TearDownTest() {
|
|||
TESTING: StatusCreatePOSTHandler
|
||||
*/
|
||||
|
||||
func (suite *StatusCreateTestSuite) TestStatusCreatePOSTHandlerSuccessful() {
|
||||
// Post a new status with some custom visibility settings
|
||||
func (suite *StatusCreateTestSuite) TestPostNewStatus() {
|
||||
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.PGTokenToOauthToken(t)
|
||||
|
|
@ -160,7 +161,8 @@ func (suite *StatusCreateTestSuite) TestStatusCreatePOSTHandlerSuccessful() {
|
|||
assert.Equal(suite.T(), mastomodel.VisibilityPrivate, statusReply.Visibility)
|
||||
}
|
||||
|
||||
func (suite *StatusCreateTestSuite) TestStatusCreatePOSTHandlerReplyToFail() {
|
||||
// Try to reply to a status that doesn't exist
|
||||
func (suite *StatusCreateTestSuite) TestReplyToNonexistentStatus() {
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.PGTokenToOauthToken(t)
|
||||
|
||||
|
|
@ -190,7 +192,8 @@ func (suite *StatusCreateTestSuite) TestStatusCreatePOSTHandlerReplyToFail() {
|
|||
assert.Equal(suite.T(), `{"error":"status with id 3759e7ef-8ee1-4c0c-86f6-8b70b9ad3d50 not replyable because it doesn't exist"}`, string(b))
|
||||
}
|
||||
|
||||
func (suite *StatusCreateTestSuite) TestStatusCreatePOSTHandlerReplyToLocalSuccess() {
|
||||
// Post a reply to the status of a local user that allows replies.
|
||||
func (suite *StatusCreateTestSuite) TestReplyToLocalStatus() {
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.PGTokenToOauthToken(t)
|
||||
|
||||
|
|
@ -229,6 +232,63 @@ func (suite *StatusCreateTestSuite) TestStatusCreatePOSTHandlerReplyToLocalSucce
|
|||
assert.Len(suite.T(), statusReply.Mentions, 1)
|
||||
}
|
||||
|
||||
// Take a media file which is currently not associated with a status, and attach it to a new status.
|
||||
func (suite *StatusCreateTestSuite) TestAttachNewMediaSuccess() {
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.PGTokenToOauthToken(t)
|
||||
|
||||
// setup
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := gin.CreateTestContext(recorder)
|
||||
ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"])
|
||||
ctx.Set(oauth.SessionAuthorizedToken, oauthToken)
|
||||
ctx.Set(oauth.SessionAuthorizedUser, suite.testUsers["local_account_1"])
|
||||
ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"])
|
||||
ctx.Request = httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost:8080/%s", basePath), nil) // the endpoint we're hitting
|
||||
ctx.Request.Form = url.Values{
|
||||
"status": {"here's an image attachment"},
|
||||
"media_ids": {"7a3b9f77-ab30-461e-bdd8-e64bd1db3008"},
|
||||
}
|
||||
suite.statusModule.statusCreatePOSTHandler(ctx)
|
||||
|
||||
// check response
|
||||
suite.EqualValues(http.StatusOK, recorder.Code)
|
||||
|
||||
result := recorder.Result()
|
||||
defer result.Body.Close()
|
||||
b, err := ioutil.ReadAll(result.Body)
|
||||
assert.NoError(suite.T(), err)
|
||||
|
||||
fmt.Println(string(b))
|
||||
|
||||
statusReply := &mastomodel.Status{}
|
||||
err = json.Unmarshal(b, statusReply)
|
||||
assert.NoError(suite.T(), err)
|
||||
|
||||
assert.Equal(suite.T(), "", statusReply.SpoilerText)
|
||||
assert.Equal(suite.T(), "here's an image attachment", statusReply.Content)
|
||||
assert.False(suite.T(), statusReply.Sensitive)
|
||||
assert.Equal(suite.T(), mastomodel.VisibilityPublic, statusReply.Visibility)
|
||||
|
||||
// there should be one media attachment
|
||||
assert.Len(suite.T(), statusReply.MediaAttachments, 1)
|
||||
|
||||
// get the updated media attachment from the database
|
||||
gtsAttachment := >smodel.MediaAttachment{}
|
||||
err = suite.db.GetByID(statusReply.MediaAttachments[0].ID, gtsAttachment)
|
||||
assert.NoError(suite.T(), err)
|
||||
|
||||
// convert it to a masto attachment
|
||||
gtsAttachmentAsMasto, err := suite.mastoConverter.AttachmentToMasto(gtsAttachment)
|
||||
assert.NoError(suite.T(), err)
|
||||
|
||||
// compare it with what we have now
|
||||
assert.EqualValues(suite.T(), statusReply.MediaAttachments[0], gtsAttachmentAsMasto)
|
||||
|
||||
// the status id of the attachment should now be set to the id of the status we just created
|
||||
assert.Equal(suite.T(), statusReply.ID, gtsAttachment.StatusID)
|
||||
}
|
||||
|
||||
func TestStatusCreateTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(StatusCreateTestSuite))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue