Add file upload
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
kolaente 2020-06-11 18:19:59 +02:00
parent db237883a8
commit ad8ff0d871
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 16 additions and 0 deletions

View File

@ -17,9 +17,11 @@
package upload
import (
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/background"
"code.vikunja.io/web"
"strconv"
)
type Provider struct {
@ -45,5 +47,19 @@ func (p *Provider) Search(search string, page int64) (result []*background.Image
// @Failure 500 {object} models.Message "Internal error"
// @Router /lists/{id}/backgrounds/upload [put]
func (p *Provider) Set(image *background.Image, list *models.List, auth web.Auth) (err error) {
// Remove the old background if one exists
if list.BackgroundFileID != 0 {
file := files.File{ID: list.BackgroundFileID}
if err := file.Delete(); err != nil {
return err
}
}
file := &files.File{}
file.ID, err = strconv.ParseInt(image.ID, 10, 64)
if err != nil {
return
}
return models.SetListBackground(list.ID, file)
}