Add export task attachment stub
This commit is contained in:
parent
a3e779e088
commit
1804e4cca0
@ -57,6 +57,10 @@ func ExportUserData(u *user.User) (err error) {
|
||||
return err
|
||||
}
|
||||
// Task attachment files
|
||||
err = exportTaskAttachments(s, u, dumpWriter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Saved filters
|
||||
// Subscription Status
|
||||
// Background files
|
||||
@ -125,3 +129,7 @@ func exportListsAndTasks(s *xorm.Session, u *user.User, wr *zip.Writer) (err err
|
||||
|
||||
return dump.WriteBytesToZip("data.json", data, wr)
|
||||
}
|
||||
|
||||
func exportTaskAttachments(s *xorm.Session, u *user.User, wr *zip.Writer) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
@ -81,21 +81,12 @@ func Dump(filename string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("error saving file: %s", err)
|
||||
}
|
||||
for fid, file := range allFiles {
|
||||
header := &zip.FileHeader{
|
||||
Name: "files/" + strconv.FormatInt(fid, 10),
|
||||
Method: compressionUsed,
|
||||
}
|
||||
w, err := dumpWriter.CreateHeader(header)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = io.Copy(w, file)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing file %d: %s", fid, err)
|
||||
}
|
||||
_ = file.Close()
|
||||
|
||||
err = WriteFilesToZip(allFiles, dumpWriter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("Dumped files")
|
||||
|
||||
log.Info("Done creating dump")
|
||||
@ -145,3 +136,25 @@ func WriteBytesToZip(filename string, data []byte, writer *zip.Writer) (err erro
|
||||
_, err = w.Write(data)
|
||||
return
|
||||
}
|
||||
|
||||
// WriteFilesToZip writes a bunch of files from the db to a zip file. It exprects a map with the file id
|
||||
// as key and its content as io.ReadCloser.
|
||||
func WriteFilesToZip(files map[int64]io.ReadCloser, wr *zip.Writer) (err error) {
|
||||
for fid, file := range files {
|
||||
header := &zip.FileHeader{
|
||||
Name: "files/" + strconv.FormatInt(fid, 10),
|
||||
Method: compressionUsed,
|
||||
}
|
||||
w, err := wr.CreateHeader(header)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = io.Copy(w, file)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing file %d: %s", fid, err)
|
||||
}
|
||||
_ = file.Close()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user