diff --git a/pkg/modules/migration/vikunja-file/vikunja.go b/pkg/modules/migration/vikunja-file/vikunja.go index 3df306e2d..5ec400f18 100644 --- a/pkg/modules/migration/vikunja-file/vikunja.go +++ b/pkg/modules/migration/vikunja-file/vikunja.go @@ -26,6 +26,7 @@ import ( "encoding/json" "fmt" "io" + "strconv" "strings" ) @@ -44,11 +45,15 @@ func (v *VikunjaFileMigrator) Migrate(user *user.User, file io.ReaderAt, size in var dataFile *zip.File var filterFile *zip.File - storedFiles := make(map[string]*zip.File) + storedFiles := make(map[int64]*zip.File) for _, f := range r.File { if strings.HasPrefix(f.Name, "files/") { fname := strings.ReplaceAll(f.Name, "files/", "") - storedFiles[fname] = f + id, err := strconv.ParseInt(fname, 10, 64) + if err != nil { + return fmt.Errorf("could not convert file id: %s", err) + } + storedFiles[id] = f continue } if f.Name == "data.json" { @@ -89,13 +94,24 @@ func (v *VikunjaFileMigrator) Migrate(user *user.User, file io.ReaderAt, size in for _, comment := range t.Comments { comment.ID = 0 } + for _, attachment := range t.Attachments { + af, err := storedFiles[attachment.File.ID].Open() + if err != nil { + return fmt.Errorf("could not open attachment %d for reading: %s", attachment.ID, err) + } + var buf bytes.Buffer + if _, err := buf.ReadFrom(af); err != nil { + return fmt.Errorf("could not read attachment %d: %s", attachment.ID, err) + } + + attachment.ID = 0 + attachment.File.ID = 0 + attachment.File.FileContent = buf.Bytes() + } } } } - // Import files - // TODO - err = migration.InsertFromStructure(namespaces, user) if err != nil { return fmt.Errorf("could not insert data: %s", err)