Backend: Improve logging and enforcement of file size limit
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
0aaf0d6c24
commit
36919b69a0
2 changed files with 34 additions and 12 deletions
|
@ -121,18 +121,21 @@ func ImportWorker(jobs <-chan ImportJob) {
|
|||
|
||||
done := make(map[string]bool)
|
||||
ind := imp.index
|
||||
sizeLimit := ind.conf.OriginalsLimit()
|
||||
|
||||
if related.Main != nil {
|
||||
f := related.Main
|
||||
|
||||
// Enforce file size limit for originals.
|
||||
if ind.conf.OriginalsLimit() > 0 && related.Main.FileSize() > ind.conf.OriginalsLimit() {
|
||||
log.Warnf("import: %s exceeds file size limit (%d / %d MB)", filepath.Base(related.Main.FileName()), related.Main.FileSize()/(1024*1024), ind.conf.OriginalsLimit()/(1024*1024))
|
||||
if sizeLimit > 0 && f.FileSize() > sizeLimit {
|
||||
log.Warnf("import: %s exceeds file size limit (%d / %d MB)", txt.Quote(f.BaseName()), f.FileSize()/(1024*1024), sizeLimit/(1024*1024))
|
||||
continue
|
||||
}
|
||||
|
||||
res := ind.MediaFile(related.Main, indexOpt, originalName)
|
||||
res := ind.MediaFile(f, indexOpt, originalName)
|
||||
|
||||
log.Infof("import: %s main %s file %s", res, related.Main.FileType(), txt.Quote(related.Main.RelName(ind.originalsPath())))
|
||||
done[related.Main.FileName()] = true
|
||||
log.Infof("import: %s main %s file %s", res, f.FileType(), txt.Quote(f.RelName(ind.originalsPath())))
|
||||
done[f.FileName()] = true
|
||||
|
||||
if res.Success() {
|
||||
if err := entity.AddPhotoToAlbums(res.PhotoUID, opt.Albums); err != nil {
|
||||
|
@ -154,9 +157,16 @@ func ImportWorker(jobs <-chan ImportJob) {
|
|||
continue
|
||||
}
|
||||
|
||||
res := ind.MediaFile(f, indexOpt, "")
|
||||
done[f.FileName()] = true
|
||||
|
||||
// Enforce file size limit for originals.
|
||||
if sizeLimit > 0 && f.FileSize() > sizeLimit {
|
||||
log.Warnf("import: %s exceeds file size limit (%d / %d MB)", txt.Quote(f.BaseName()), f.FileSize()/(1024*1024), sizeLimit/(1024*1024))
|
||||
continue
|
||||
}
|
||||
|
||||
res := ind.MediaFile(f, indexOpt, "")
|
||||
|
||||
log.Infof("import: %s related %s file %s", res, f.FileType(), txt.Quote(f.RelName(ind.originalsPath())))
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package photoprism
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/query"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
|
@ -18,15 +17,16 @@ func IndexMain(related *RelatedFiles, ind *Index, opt IndexOptions) (result Inde
|
|||
return result
|
||||
}
|
||||
|
||||
f := related.Main
|
||||
sizeLimit := ind.conf.OriginalsLimit()
|
||||
|
||||
// Enforce file size limit for originals.
|
||||
if ind.conf.OriginalsLimit() > 0 && related.Main.FileSize() > ind.conf.OriginalsLimit() {
|
||||
result.Err = fmt.Errorf("index: %s exceeds file size limit for originals [%d / %d MB]", filepath.Base(related.Main.FileName()), related.Main.FileSize()/(1024*1024), ind.conf.OriginalsLimit()/(1024*1024))
|
||||
if sizeLimit > 0 && f.FileSize() > sizeLimit {
|
||||
result.Err = fmt.Errorf("index: %s exceeds file size limit (%d / %d MB)", txt.Quote(f.BaseName()), f.FileSize()/(1024*1024), sizeLimit/(1024*1024))
|
||||
result.Status = IndexFailed
|
||||
return result
|
||||
}
|
||||
|
||||
f := related.Main
|
||||
|
||||
if opt.Convert && !f.HasJpeg() {
|
||||
if jpegFile, err := ind.convert.ToJpeg(f); err != nil {
|
||||
result.Err = fmt.Errorf("index: creating jpeg failed (%s)", err.Error())
|
||||
|
@ -72,6 +72,7 @@ func IndexMain(related *RelatedFiles, ind *Index, opt IndexOptions) (result Inde
|
|||
// IndexMain indexes a group of related files and returns the result.
|
||||
func IndexRelated(related RelatedFiles, ind *Index, opt IndexOptions) (result IndexResult) {
|
||||
done := make(map[string]bool)
|
||||
sizeLimit := ind.conf.OriginalsLimit()
|
||||
|
||||
result = IndexMain(&related, ind, opt)
|
||||
|
||||
|
@ -86,13 +87,24 @@ func IndexRelated(related RelatedFiles, ind *Index, opt IndexOptions) (result In
|
|||
done[related.Main.FileName()] = true
|
||||
|
||||
for _, f := range related.Files {
|
||||
if f == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if done[f.FileName()] {
|
||||
continue
|
||||
}
|
||||
|
||||
res := ind.MediaFile(f, opt, "")
|
||||
done[f.FileName()] = true
|
||||
|
||||
// Enforce file size limit for originals.
|
||||
if sizeLimit > 0 && f.FileSize() > sizeLimit {
|
||||
log.Warnf("index: %s exceeds file size limit (%d / %d MB)", txt.Quote(f.BaseName()), f.FileSize()/(1024*1024), sizeLimit/(1024*1024))
|
||||
continue
|
||||
}
|
||||
|
||||
res := ind.MediaFile(f, opt, "")
|
||||
|
||||
if res.Indexed() && f.IsJpeg() {
|
||||
if err := f.ResampleDefault(ind.thumbPath(), false); err != nil {
|
||||
log.Errorf("index: could not create default thumbnails (%s)", err.Error())
|
||||
|
|
Loading…
Reference in a new issue