Add session handling for unsplash

This commit is contained in:
kolaente 2020-12-23 01:05:44 +01:00
parent 0cc2a4fbd1
commit 662593d4fd
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 6 additions and 6 deletions

View File

@ -39,8 +39,8 @@ func (u *UnsplashPhoto) TableName() string {
} }
// Save persists an unsplash photo to the db // Save persists an unsplash photo to the db
func (u *UnsplashPhoto) Save() error { func (u *UnsplashPhoto) Save(s *xorm.Session) error {
_, err := x.Insert(u) _, err := s.Insert(u)
return err return err
} }
@ -58,10 +58,10 @@ func GetUnsplashPhotoByFileID(s *xorm.Session, fileID int64) (u *UnsplashPhoto,
} }
// RemoveUnsplashPhoto removes an unsplash photo from the db // RemoveUnsplashPhoto removes an unsplash photo from the db
func RemoveUnsplashPhoto(fileID int64) (err error) { func RemoveUnsplashPhoto(s *xorm.Session, fileID int64) (err error) {
// This is intentionally "fire and forget" which is why we don't check if we have an // This is intentionally "fire and forget" which is why we don't check if we have an
// unsplash entry for that file at all. If there is one, it will be deleted. // unsplash entry for that file at all. If there is one, it will be deleted.
// We do this to keep the function simple. // We do this to keep the function simple.
_, err = x.Where("file_id = ?", fileID).Delete(&UnsplashPhoto{}) _, err = s.Where("file_id = ?", fileID).Delete(&UnsplashPhoto{})
return return
} }

View File

@ -292,7 +292,7 @@ func (p *Provider) Set(image *background.Image, list *models.List, auth web.Auth
return err return err
} }
if err := models.RemoveUnsplashPhoto(list.BackgroundFileID); err != nil { if err := models.RemoveUnsplashPhoto(s, list.BackgroundFileID); err != nil {
return err return err
} }
} }
@ -304,7 +304,7 @@ func (p *Provider) Set(image *background.Image, list *models.List, auth web.Auth
Author: photo.User.Username, Author: photo.User.Username,
AuthorName: photo.User.Name, AuthorName: photo.User.Name,
} }
err = unsplashPhoto.Save() err = unsplashPhoto.Save(s)
if err != nil { if err != nil {
return return
} }