Only try to download attachments from todoist when there is a url
continuous-integration/drone/push Build is passing Details

Credit: freaktechnik
This commit is contained in:
kolaente 2020-08-16 23:26:19 +02:00
parent d192c36c39
commit 301bebf8d3
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 27 additions and 23 deletions

View File

@ -316,6 +316,7 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
} }
// Task Notes -> Task Descriptions // Task Notes -> Task Descriptions
// FIXME: Should be comments
for _, n := range sync.Notes { for _, n := range sync.Notes {
if tasks[n.ItemID].Description != "" { if tasks[n.ItemID].Description != "" {
tasks[n.ItemID].Description += "\n" tasks[n.ItemID].Description += "\n"
@ -326,31 +327,34 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
continue continue
} }
// Download the attachment and put it in the file // Only add the attachment if there's something to download
resp, err := http.Get(n.FileAttachment.FileURL) if len(n.FileAttachment.FileURL) > 0 {
if err != nil { // Download the attachment and put it in the file
return nil, err resp, err := http.Get(n.FileAttachment.FileURL)
} if err != nil {
defer resp.Body.Close() return nil, err
buf := &bytes.Buffer{} }
_, err = buf.ReadFrom(resp.Body) defer resp.Body.Close()
if err != nil { buf := &bytes.Buffer{}
return nil, err _, err = buf.ReadFrom(resp.Body)
} if err != nil {
return nil, err
}
tasks[n.ItemID].Attachments = append(tasks[n.ItemID].Attachments, &models.TaskAttachment{ tasks[n.ItemID].Attachments = append(tasks[n.ItemID].Attachments, &models.TaskAttachment{
File: &files.File{ File: &files.File{
Name: n.FileAttachment.FileName, Name: n.FileAttachment.FileName,
Mime: n.FileAttachment.FileType, Mime: n.FileAttachment.FileType,
Size: uint64(n.FileAttachment.FileSize), Size: uint64(n.FileAttachment.FileSize),
Created: n.Posted,
// We directly pass the file contents here to have a way to link the attachment to the file later.
// Because we don't have an ID for our task at this point of the migration, we cannot just throw all
// attachments in a slice and do the work of downloading and properly storing them later.
FileContent: buf.Bytes(),
},
Created: n.Posted, Created: n.Posted,
// We directly pass the file contents here to have a way to link the attachment to the file later. })
// Because we don't have an ID for our task at this point of the migration, we cannot just throw all }
// attachments in a slice and do the work of downloading and properly storing them later.
FileContent: buf.Bytes(),
},
Created: n.Posted,
})
} }
// Project Notes -> List Descriptions // Project Notes -> List Descriptions