diff --git a/internal/entity/photo.go b/internal/entity/photo.go index 6e7468fee..0800c3da9 100644 --- a/internal/entity/photo.go +++ b/internal/entity/photo.go @@ -85,6 +85,22 @@ type Photo struct { DeletedAt *time.Time `sql:"index" yaml:"DeletedAt,omitempty"` } +// NewPhoto creates a photo entity. +func NewPhoto() Photo { + return Photo{ + PhotoType: TypeImage, + PhotoCountry: UnknownCountry.ID, + Camera: &UnknownCamera, + CameraID: UnknownCamera.ID, + Lens: &UnknownLens, + LensID: UnknownLens.ID, + Location: &UnknownLocation, + LocationID: UnknownLocation.ID, + Place: &UnknownPlace, + PlaceID: UnknownPlace.ID, + } +} + // SavePhotoForm saves a model in the database using form data. func SavePhotoForm(model Photo, form form.Photo, geoApi string) error { locChanged := model.PhotoLat != form.PhotoLat || model.PhotoLng != form.PhotoLng || model.PhotoCountry != form.PhotoCountry diff --git a/internal/photoprism/import_worker.go b/internal/photoprism/import_worker.go index 5e2bbe891..1ba4b9fb6 100644 --- a/internal/photoprism/import_worker.go +++ b/internal/photoprism/import_worker.go @@ -131,14 +131,16 @@ func ImportWorker(jobs <-chan ImportJob) { res := ind.MediaFile(related.Main, indexOpt, originalName) + log.Infof("import: %s main %s file %s", res, related.Main.FileType(), txt.Quote(related.Main.RelativeName(ind.originalsPath()))) + done[related.Main.FileName()] = true + if res.Success() { if err := entity.AddPhotoToAlbums(res.PhotoUID, opt.Albums); err != nil { log.Warn(err) } + } else { + continue } - - log.Infof("import: %s main %s file %s", res, related.Main.FileType(), txt.Quote(related.Main.RelativeName(ind.originalsPath()))) - done[related.Main.FileName()] = true } else { log.Warnf("import: no main file for %s (conversion to jpeg failed?)", fs.RelativeName(destinationMainFilename, imp.originalsPath())) } diff --git a/internal/photoprism/index_mediafile.go b/internal/photoprism/index_mediafile.go index f7af3597e..2c8c9cc68 100644 --- a/internal/photoprism/index_mediafile.go +++ b/internal/photoprism/index_mediafile.go @@ -63,7 +63,7 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) ( file, primaryFile := entity.File{}, entity.File{} - photo := entity.Photo{PhotoType: entity.TypeImage, PhotoCountry: entity.UnknownCountry.ID} + photo := entity.NewPhoto() metaData := meta.Data{} description := entity.Details{} labels := classify.Labels{} diff --git a/internal/photoprism/index_worker.go b/internal/photoprism/index_worker.go index 321de5da5..b2ba24742 100644 --- a/internal/photoprism/index_worker.go +++ b/internal/photoprism/index_worker.go @@ -72,6 +72,10 @@ func IndexWorker(jobs <-chan IndexJob) { log.Infof("index: %s main %s file %s", res, f.FileType(), txt.Quote(f.RelativeName(ind.originalsPath()))) + if !res.Success() { + continue + } + for _, f := range related.Files { if done[f.FileName()] { continue diff --git a/internal/query/photo_search.go b/internal/query/photo_search.go index 0191b8069..d33b223f8 100644 --- a/internal/query/photo_search.go +++ b/internal/query/photo_search.go @@ -37,8 +37,17 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error Joins("JOIN files ON photos.id = files.photo_id AND files.file_missing = 0 AND files.deleted_at IS NULL"). Joins("JOIN cameras ON photos.camera_id = cameras.id"). Joins("JOIN lenses ON photos.lens_id = lenses.id"). - Joins("JOIN places ON photos.place_id = places.id"). - Where("files.file_type = 'jpg' OR files.file_video = 1") + Joins("JOIN places ON photos.place_id = places.id") + + if !f.Hidden { + s = s.Where("files.file_type = 'jpg' OR files.file_video = 1") + + if f.Error { + s = s.Where("files.file_error <> ''") + } else { + s = s.Where("files.file_error = ''") + } + } // Shortcut for known photo ids. if f.ID != "" { @@ -148,12 +157,6 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error } // Filter by additional flags and metadata. - if f.Error { - s = s.Where("files.file_error <> ''") - } else { - s = s.Where("files.file_error = ''") - } - if f.Camera > 0 { s = s.Where("photos.camera_id = ?", f.Camera) }