diff --git a/pkg/modules/migration/trello/trello.go b/pkg/modules/migration/trello/trello.go index 84fe82458..510ec363e 100644 --- a/pkg/modules/migration/trello/trello.go +++ b/pkg/modules/migration/trello/trello.go @@ -336,37 +336,39 @@ func convertTrelloDataToVikunja(organizationName string, trelloData []*trello.Bo log.Debugf("[Trello Migration] Downloading %d card attachments from card %s", len(card.Attachments), card.ID) } for _, attachment := range card.Attachments { - if !attachment.IsUpload { // There are other types of attachments which are not files. We can only handle files. - log.Debugf("[Trello Migration] Attachment %s does not have a mime type, not downloading", attachment.ID) + if attachment.IsUpload { + // Download file and add it as attachment + log.Debugf("[Trello Migration] Downloading card attachment %s", attachment.ID) + + buf, err := migration.DownloadFileWithHeaders(attachment.URL, map[string][]string{ + "Authorization": {`OAuth oauth_consumer_key="` + config.MigrationTrelloKey.GetString() + `", oauth_token="` + token + `"`}, + }) + if err != nil { + return nil, err + } + + vikunjaAttachment := &models.TaskAttachment{ + File: &files.File{ + Name: attachment.Name, + Mime: attachment.MimeType, + Size: uint64(buf.Len()), + FileContent: buf.Bytes(), + }, + } + + if card.IDAttachmentCover != "" && card.IDAttachmentCover == attachment.ID { + vikunjaAttachment.ID = 42 + task.CoverImageAttachmentID = 42 + } + + task.Attachments = append(task.Attachments, vikunjaAttachment) + + log.Debugf("[Trello Migration] Downloaded card attachment %s", attachment.ID) continue } - log.Debugf("[Trello Migration] Downloading card attachment %s", attachment.ID) - - buf, err := migration.DownloadFileWithHeaders(attachment.URL, map[string][]string{ - "Authorization": {`OAuth oauth_consumer_key="` + config.MigrationTrelloKey.GetString() + `", oauth_token="` + token + `"`}, - }) - if err != nil { - return nil, err - } - - vikunjaAttachment := &models.TaskAttachment{ - File: &files.File{ - Name: attachment.Name, - Mime: attachment.MimeType, - Size: uint64(buf.Len()), - FileContent: buf.Bytes(), - }, - } - - if card.IDAttachmentCover != "" && card.IDAttachmentCover == attachment.ID { - vikunjaAttachment.ID = 42 - task.CoverImageAttachmentID = 42 - } - - task.Attachments = append(task.Attachments, vikunjaAttachment) - - log.Debugf("[Trello Migration] Downloaded card attachment %s", attachment.ID) + // Other links are not attachments in Vikunja, but we can add them to the description + task.Description += `

` + attachment.Name + "

\n" } // When the cover image was set manually, we need to add it as an attachment diff --git a/pkg/modules/migration/trello/trello_test.go b/pkg/modules/migration/trello/trello_test.go index 4d94f26ce..3e6ba1a6b 100644 --- a/pkg/modules/migration/trello/trello_test.go +++ b/pkg/modules/migration/trello/trello_test.go @@ -78,6 +78,13 @@ func getTestBoard(t *testing.T) ([]*trello.Board, time.Time) { MimeType: "image/jpg", URL: "https://vikunja.io/testimage.jpg", }, + { + ID: "7cc71b16f0c7a57bed3c94e9", + Name: "Website", + IsUpload: false, + MimeType: "", + URL: "https://vikunja.io", + }, }, }, { @@ -265,10 +272,11 @@ func TestConvertTrelloToVikunja(t *testing.T) { Tasks: []*models.TaskWithComments{ { Task: models.Task{ - Title: "Test Card 1", - Description: "

Card Description bold

\n", - BucketID: 1, - DueDate: time1, + Title: "Test Card 1", + Description: "

Card Description bold

\n" + + "

Website

\n", + BucketID: 1, + DueDate: time1, Labels: []*models.Label{ { Title: "Label 1", @@ -481,6 +489,6 @@ func TestCreateOrganizationMap(t *testing.T) { }, } if diff, equal := messagediff.PrettyDiff(organizationMap, expectedMap); !equal { - t.Errorf("converted trello data = %v,\nwant %v,\ndiff: %v", organizationMap, expectedMap, diff) + t.Errorf("converted organization map = %v,\nwant %v,\ndiff: %v", organizationMap, expectedMap, diff) } }