Faces: Add Marker and File UID to API error logs #1438 #2201

The file query functions have been refactored and now return pointers.
This commit is contained in:
Michael Mayer 2022-04-05 13:54:50 +02:00
parent 7b508d6ad5
commit 4afd3f2ca9
4 changed files with 41 additions and 30 deletions

2
go.mod
View file

@ -55,7 +55,7 @@ require (
github.com/urfave/cli v1.22.5
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f // indirect
gonum.org/v1/gonum v0.11.0
google.golang.org/protobuf v1.28.0 // indirect

4
go.sum
View file

@ -398,8 +398,8 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd h1:zYlwaUHTmxuf6H7hwO2dgwqozQmH7zf4x+/qql4oVWc=
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b h1:vI32FkLJNAWtGD4BwkThwEy6XS7ZLLMHkSkYfF8M0W0=
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

View file

@ -53,18 +53,16 @@ func findFileMarker(c *gin.Context) (file *entity.File, marker *entity.Marker, e
return nil, nil, fmt.Errorf("bad request")
} else if marker, err = query.MarkerByUID(uid); err != nil {
AbortEntityNotFound(c)
return nil, nil, err
return nil, nil, fmt.Errorf("uid %s %s", uid, err)
} else if marker.FileUID == "" {
AbortEntityNotFound(c)
return nil, marker, fmt.Errorf("marker file missing")
}
// Find file.
if f, err := query.FileByUID(marker.FileUID); err != nil {
if file, err = query.FileByUID(marker.FileUID); err != nil {
AbortEntityNotFound(c)
return nil, marker, err
} else {
file = &f
return file, marker, fmt.Errorf("file %s %s", marker.FileUID, err)
}
return file, marker, nil
@ -96,7 +94,7 @@ func UpdateMarker(router *gin.RouterGroup) {
file, marker, err := findFileMarker(c)
if err != nil {
log.Debugf("marker: %s (find)", err)
log.Debugf("faces: %s (find marker to update)", err)
return
}
@ -104,18 +102,18 @@ func UpdateMarker(router *gin.RouterGroup) {
f, err := form.NewMarker(*marker)
if err != nil {
log.Errorf("marker: %s (new form)", err)
log.Errorf("faces: %s (create marker update form)", err)
AbortSaveFailed(c)
return
} else if err := c.BindJSON(&f); err != nil {
log.Errorf("marker: %s (update form)", err)
log.Errorf("faces: %s (set updated marker values)", err)
AbortBadRequest(c)
return
}
// Update marker from form values.
if changed, err := marker.SaveForm(f); err != nil {
log.Errorf("marker: %s", err)
log.Errorf("faces: %s (update marker)", err)
AbortSaveFailed(c)
return
} else if changed {
@ -180,12 +178,12 @@ func ClearMarkerSubject(router *gin.RouterGroup) {
file, marker, err := findFileMarker(c)
if err != nil {
log.Debugf("api: %s (clear marker subject)", err)
log.Debugf("faces: %s (find marker to clear subject)", err)
return
}
if err := marker.ClearSubject(entity.SrcManual); err != nil {
log.Errorf("faces: %s (clear subject)", err)
log.Errorf("faces: %s (clear marker subject)", err)
AbortSaveFailed(c)
return
} else if err := query.UpdateSubjectCovers(); err != nil {

View file

@ -57,39 +57,52 @@ func FilesByUID(u []string, limit int, offset int) (files entity.Files, err erro
}
// FileByPhotoUID finds a file for the given photo UID.
func FileByPhotoUID(u string) (file entity.File, err error) {
if err := Db().Where("photo_uid = ? AND file_primary = 1", u).Preload("Photo").First(&file).Error; err != nil {
return file, err
func FileByPhotoUID(photoUID string) (*entity.File, error) {
f := entity.File{}
if photoUID == "" {
return &f, fmt.Errorf("photo uid required")
}
return file, nil
err := Db().Where("photo_uid = ? AND file_primary = 1", photoUID).Preload("Photo").First(&f).Error
return &f, err
}
// VideoByPhotoUID finds a video for the given photo UID.
func VideoByPhotoUID(u string) (file entity.File, err error) {
if err := Db().Where("photo_uid = ? AND file_video = 1", u).Preload("Photo").First(&file).Error; err != nil {
return file, err
func VideoByPhotoUID(photoUID string) (*entity.File, error) {
f := entity.File{}
if photoUID == "" {
return &f, fmt.Errorf("photo uid required")
}
return file, nil
err := Db().Where("photo_uid = ? AND file_video = 1", photoUID).Preload("Photo").First(&f).Error
return &f, err
}
// FileByUID finds a file entity for the given UID.
func FileByUID(uid string) (file entity.File, err error) {
if err := Db().Where("file_uid = ?", uid).Preload("Photo").First(&file).Error; err != nil {
return file, err
func FileByUID(fileUID string) (*entity.File, error) {
f := entity.File{}
if fileUID == "" {
return &f, fmt.Errorf("file uid required")
}
return file, nil
err := Db().Where("file_uid = ?", fileUID).Preload("Photo").First(&f).Error
return &f, err
}
// FileByHash finds a file with a given hash string.
func FileByHash(fileHash string) (file entity.File, err error) {
if err := Db().Where("file_hash = ?", fileHash).Preload("Photo").First(&file).Error; err != nil {
return file, err
func FileByHash(fileHash string) (*entity.File, error) {
f := entity.File{}
if fileHash == "" {
return &f, fmt.Errorf("file hash required")
}
return file, nil
err := Db().Where("file_hash = ?", fileHash).Preload("Photo").First(&f).Error
return &f, err
}
// RenameFile renames an indexed file.