Sharing: Use single image as preview for small albums #18
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
f2955fdefc
commit
63f940b694
3 changed files with 37 additions and 2 deletions
|
@ -69,13 +69,13 @@ func SharePreview(router *gin.RouterGroup) {
|
|||
f.Hidden = false
|
||||
f.Archived = false
|
||||
f.Review = false
|
||||
f.Merged = true
|
||||
f.Primary = true
|
||||
|
||||
// Get first 12 album entries.
|
||||
f.Count = 12
|
||||
f.Order = "relevance"
|
||||
|
||||
p, _, err := query.PhotoSearch(f)
|
||||
p, count, err := query.PhotoSearch(f)
|
||||
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
|
@ -83,6 +83,34 @@ func SharePreview(router *gin.RouterGroup) {
|
|||
return
|
||||
}
|
||||
|
||||
if count == 0 {
|
||||
c.Redirect(http.StatusTemporaryRedirect, conf.SitePreview())
|
||||
return
|
||||
} else if count < 12 {
|
||||
f := p[0]
|
||||
thumbType, _ := thumb.Types["fit_720"]
|
||||
|
||||
fileName := photoprism.FileName(f.FileRoot, f.FileName)
|
||||
|
||||
if !fs.FileExists(fileName) {
|
||||
log.Errorf("share: file %s is missing (preview)", txt.Quote(f.FileName))
|
||||
c.Redirect(http.StatusTemporaryRedirect, conf.SitePreview())
|
||||
return
|
||||
}
|
||||
|
||||
thumbnail, err := thumb.FromFile(fileName, f.FileHash, conf.ThumbPath(), thumbType.Width, thumbType.Height, thumbType.Options...)
|
||||
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
c.Redirect(http.StatusTemporaryRedirect, conf.SitePreview())
|
||||
return
|
||||
}
|
||||
|
||||
c.File(thumbnail)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
width := 908
|
||||
height := 680
|
||||
x := 0
|
||||
|
@ -105,6 +133,7 @@ func SharePreview(router *gin.RouterGroup) {
|
|||
if err != nil {
|
||||
log.Error(err)
|
||||
c.Redirect(http.StatusTemporaryRedirect, conf.SitePreview())
|
||||
return
|
||||
}
|
||||
|
||||
src, err := imaging.Open(thumbnail)
|
||||
|
|
|
@ -16,6 +16,7 @@ type PhotoSearch struct {
|
|||
Original string `form:"original"`
|
||||
Title string `form:"title"`
|
||||
Hash string `form:"hash"`
|
||||
Primary bool `form:"primary"`
|
||||
Video bool `form:"video"`
|
||||
Photo bool `form:"photo"`
|
||||
Duplicate bool `form:"duplicate"`
|
||||
|
|
|
@ -49,6 +49,11 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error
|
|||
}
|
||||
}
|
||||
|
||||
// Return primary files only.
|
||||
if f.Primary {
|
||||
s = s.Where("files.file_primary = 1")
|
||||
}
|
||||
|
||||
// Shortcut for known photo ids.
|
||||
if f.ID != "" {
|
||||
s = s.Where("photos.photo_uid IN (?)", strings.Split(f.ID, ","))
|
||||
|
|
Loading…
Reference in a new issue