mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Backend: Add FileError col to files table #202
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
@@ -30,11 +30,17 @@ func GetThumbnail(router *gin.RouterGroup, conf *config.Config) {
|
||||
return
|
||||
}
|
||||
|
||||
q := query.New(conf.OriginalsPath(), conf.Db())
|
||||
db := conf.Db()
|
||||
q := query.New(conf.OriginalsPath(), db)
|
||||
f, err := q.FindFileByHash(fileHash)
|
||||
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"error": err.Error()})
|
||||
c.Data(http.StatusNotFound, "image/svg+xml", photoIconSvg)
|
||||
return
|
||||
}
|
||||
|
||||
if f.FileError != "" {
|
||||
c.Data(http.StatusBadRequest, "image/svg+xml", brokenIconSvg)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -46,7 +52,7 @@ func GetThumbnail(router *gin.RouterGroup, conf *config.Config) {
|
||||
|
||||
// Set missing flag so that the file doesn't show up in search results anymore
|
||||
f.FileMissing = true
|
||||
conf.Db().Save(&f)
|
||||
db.Save(&f)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -66,8 +72,10 @@ func GetThumbnail(router *gin.RouterGroup, conf *config.Config) {
|
||||
|
||||
c.File(thumbnail)
|
||||
} else {
|
||||
log.Errorf("could not create thumbnail: %s", err)
|
||||
c.Data(http.StatusBadRequest, "image/svg+xml", photoIconSvg)
|
||||
f.FileError = err.Error()
|
||||
db.Save(&f)
|
||||
|
||||
c.Data(http.StatusBadRequest, "image/svg+xml", brokenIconSvg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -19,6 +19,12 @@ var albumIconSvg = []byte(`<svg xmlns="http://www.w3.org/2000/svg" width="24" he
|
||||
var labelIconSvg = []byte(`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||
<path d="M0 0h24v24H0z" fill="none"/><path d="M17.63 5.84C17.27 5.33 16.67 5 16 5L5 5.01C3.9 5.01 3 5.9 3 7v10c0 1.1.9 1.99 2 1.99L16 19c.67 0 1.27-.33 1.63-.84L22 12l-4.37-6.16z"/></svg>`)
|
||||
|
||||
var brokenIconSvg = []byte(`
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||
<path fill="none" d="M0 0h24v24H0zm0 0h24v24H0zm21 19c0 1.1-.9 2-2 2H5c-1.1 0-2-.9-2-2V5c0-1.1.9-2 2-2h14c1.1 0 2 .9 2 2"/>
|
||||
<path fill="none" d="M0 0h24v24H0z"/>
|
||||
<path d="M21 5v6.59l-3-3.01-4 4.01-4-4-4 4-3-3.01V5c0-1.1.9-2 2-2h14c1.1 0 2 .9 2 2zm-3 6.42l3 3.01V19c0 1.1-.9 2-2 2H5c-1.1 0-2-.9-2-2v-6.58l3 2.99 4-4 4 4 4-3.99z"/></svg>`)
|
||||
|
||||
// GET /api/v1/svg/*
|
||||
func GetSvg(router *gin.RouterGroup) {
|
||||
router.GET("/svg/photo", func(c *gin.Context) {
|
||||
@@ -32,4 +38,8 @@ func GetSvg(router *gin.RouterGroup) {
|
||||
router.GET("/svg/album", func(c *gin.Context) {
|
||||
c.Data(http.StatusOK, "image/svg+xml", albumIconSvg)
|
||||
})
|
||||
|
||||
router.GET("/svg/broken", func(c *gin.Context) {
|
||||
c.Data(http.StatusOK, "image/svg+xml", brokenIconSvg)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ type File struct {
|
||||
FileLuminance string `gorm:"type:binary(9);"`
|
||||
FileChroma uint
|
||||
FileNotes string `gorm:"type:text"`
|
||||
FileError string `gorm:"type:varbinary(512)"`
|
||||
CreatedAt time.Time
|
||||
CreatedIn int64
|
||||
UpdatedAt time.Time
|
||||
|
||||
@@ -14,6 +14,7 @@ type PhotoSearch struct {
|
||||
Hash string `form:"hash"`
|
||||
Duplicate bool `form:"duplicate"`
|
||||
Archived bool `form:"archived"`
|
||||
Error bool `form:"error"`
|
||||
Lat float64 `form:"lat"`
|
||||
Lng float64 `form:"lng"`
|
||||
Dist uint `form:"dist"`
|
||||
|
||||
@@ -192,6 +192,10 @@ func (s *Repo) Photos(f form.PhotoSearch) (results []PhotoResult, err error) {
|
||||
q = q.Where("photos.deleted_at IS NULL")
|
||||
}
|
||||
|
||||
if f.Error {
|
||||
q = q.Where("files.file_error <> ''")
|
||||
}
|
||||
|
||||
if f.Album != "" {
|
||||
q = q.Joins("JOIN photos_albums ON photos_albums.photo_uuid = photos.photo_uuid").Where("photos_albums.album_uuid = ?", f.Album)
|
||||
}
|
||||
@@ -355,7 +359,7 @@ func (s *Repo) FindPhotoByUUID(photoUUID string) (photo entity.Photo, err error)
|
||||
func (s *Repo) PreloadPhotoByUUID(photoUUID string) (photo entity.Photo, err error) {
|
||||
if err := s.db.Where("photo_uuid = ?", photoUUID).
|
||||
Preload("Labels", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("photos_labels.label_uncertainty ASC, photos_labels.label_id")
|
||||
return db.Order("photos_labels.label_uncertainty ASC, photos_labels.label_id DESC")
|
||||
}).
|
||||
Preload("Labels.Label").
|
||||
Preload("Camera").
|
||||
|
||||
Reference in New Issue
Block a user