1
0

fix(list): when list background is removed, delete file from file system and DB (#1372)

Co-authored-by: testinho.testador <testinho.testador@noreply.kolaente.de>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/1372
Reviewed-by: konrad <k@knt.li>
Co-authored-by: clos <clos@noreply.kolaente.de>
Co-committed-by: clos <clos@noreply.kolaente.de>
This commit is contained in:
clos
2023-02-01 11:38:23 +00:00
committed by konrad
parent 437960b146
commit afdceb0aff
6 changed files with 112 additions and 17 deletions

View File

@ -341,6 +341,11 @@ func RemoveListBackground(c echo.Context) error {
return err
}
err = list.DeleteBackgroundFileIfExists()
if err != nil {
return err
}
list.BackgroundFileID = 0
list.BackgroundInformation = nil
list.BackgroundBlurHash = ""

View File

@ -54,11 +54,9 @@ func (p *Provider) Search(s *xorm.Session, search string, page int64) (result []
// @Router /lists/{id}/backgrounds/upload [put]
func (p *Provider) Set(s *xorm.Session, img *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
}
err = list.DeleteBackgroundFileIfExists()
if err != nil {
return err
}
file := &files.File{}