Add copying list backgrounds
This commit is contained in:
parent
ccebb888a1
commit
2089fd3da3
|
@ -17,6 +17,7 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/files"
|
||||
"code.vikunja.io/web"
|
||||
)
|
||||
|
||||
|
@ -191,6 +192,39 @@ func (ld *ListDuplicate) Create(a web.Auth) (err error) {
|
|||
}
|
||||
|
||||
// Background files + unsplash info
|
||||
if ld.List.BackgroundFileID != 0 {
|
||||
f := &files.File{ID: ld.List.BackgroundFileID}
|
||||
if err := f.LoadFileMetaByID(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := f.LoadFileByID(); err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.File.Close()
|
||||
|
||||
file, err := files.Create(f.File, f.Name, f.Size, a)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Get unsplash info if applicable
|
||||
up, err := GetUnsplashPhotoByFileID(ld.List.BackgroundFileID)
|
||||
if err != nil && files.IsErrFileIsNotUnsplashFile(err) {
|
||||
return err
|
||||
}
|
||||
if up != nil {
|
||||
up.ID = 0
|
||||
up.FileID = file.ID
|
||||
if err := up.Save(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
ld.List.BackgroundFileID = file.ID
|
||||
if err := CreateOrUpdateList(ld.List); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Rights / Shares
|
||||
// Generate new link shares if any are available
|
||||
|
|
Loading…
Reference in New Issue