Add support for importing task attachments
This commit is contained in:
parent
1773fdf73d
commit
0e35f0f5fb
|
@ -26,6 +26,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -44,11 +45,15 @@ func (v *VikunjaFileMigrator) Migrate(user *user.User, file io.ReaderAt, size in
|
||||||
|
|
||||||
var dataFile *zip.File
|
var dataFile *zip.File
|
||||||
var filterFile *zip.File
|
var filterFile *zip.File
|
||||||
storedFiles := make(map[string]*zip.File)
|
storedFiles := make(map[int64]*zip.File)
|
||||||
for _, f := range r.File {
|
for _, f := range r.File {
|
||||||
if strings.HasPrefix(f.Name, "files/") {
|
if strings.HasPrefix(f.Name, "files/") {
|
||||||
fname := strings.ReplaceAll(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
|
continue
|
||||||
}
|
}
|
||||||
if f.Name == "data.json" {
|
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 {
|
for _, comment := range t.Comments {
|
||||||
comment.ID = 0
|
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)
|
err = migration.InsertFromStructure(namespaces, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not insert data: %s", err)
|
return fmt.Errorf("could not insert data: %s", err)
|
||||||
|
|
Loading…
Reference in New Issue