Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
2f5ae08768
commit
05a05773d9
10 changed files with 37 additions and 31 deletions
|
@ -28,7 +28,7 @@ func main() {
|
||||||
commands.ImportCommand,
|
commands.ImportCommand,
|
||||||
commands.CopyCommand,
|
commands.CopyCommand,
|
||||||
commands.ConvertCommand,
|
commands.ConvertCommand,
|
||||||
commands.ThumbsCommand,
|
commands.ResampleCommand,
|
||||||
commands.MigrateCommand,
|
commands.MigrateCommand,
|
||||||
commands.ConfigCommand,
|
commands.ConfigCommand,
|
||||||
commands.VersionCommand,
|
commands.VersionCommand,
|
||||||
|
|
|
@ -8,21 +8,22 @@ import (
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ThumbsCommand is used to register the thumbs cli command
|
// ResampleCommand is used to register the thumbs cli command
|
||||||
var ThumbsCommand = cli.Command{
|
var ResampleCommand = cli.Command{
|
||||||
Name: "thumbs",
|
Name: "resample",
|
||||||
Usage: "Pre-renders thumbnails to boost performance",
|
Aliases: []string{"thumbs"},
|
||||||
|
Usage: "Pre-renders thumbnails (significantly reduces memory and cpu usage)",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "force, f",
|
Name: "force, f",
|
||||||
Usage: "re-create existing thumbnails",
|
Usage: "re-create existing thumbnails",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: thumbsAction,
|
Action: resampleAction,
|
||||||
}
|
}
|
||||||
|
|
||||||
// thumbsAction pre-render the thumbnails
|
// resampleAction pre-render the thumbnails
|
||||||
func thumbsAction(ctx *cli.Context) error {
|
func resampleAction(ctx *cli.Context) error {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
conf := config.NewConfig(ctx)
|
conf := config.NewConfig(ctx)
|
|
@ -85,6 +85,8 @@ func (c *Convert) Start(path string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done[fileName] = true
|
||||||
|
|
||||||
jobs <- ConvertJob{
|
jobs <- ConvertJob{
|
||||||
image: mf,
|
image: mf,
|
||||||
convert: c,
|
convert: c,
|
||||||
|
@ -131,7 +133,7 @@ func (c *Convert) ConvertCommand(image *MediaFile, jpegName string, xmpName stri
|
||||||
// ToJpeg converts a single image file to JPEG if possible.
|
// ToJpeg converts a single image file to JPEG if possible.
|
||||||
func (c *Convert) ToJpeg(image *MediaFile) (*MediaFile, error) {
|
func (c *Convert) ToJpeg(image *MediaFile) (*MediaFile, error) {
|
||||||
if !image.Exists() {
|
if !image.Exists() {
|
||||||
return nil, fmt.Errorf("convert: can not convert to jpeg, file does not exist (%s)", image.FileName())
|
return nil, fmt.Errorf("convert: can not convert to jpeg, file does not exist (%s)", image.RelativeName(c.conf.OriginalsPath()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if image.IsJpeg() {
|
if image.IsJpeg() {
|
||||||
|
@ -149,12 +151,12 @@ func (c *Convert) ToJpeg(image *MediaFile) (*MediaFile, error) {
|
||||||
jpegName = image.AbsBase(c.conf.Settings().Library.GroupRelated) + ".jpg"
|
jpegName = image.AbsBase(c.conf.Settings().Library.GroupRelated) + ".jpg"
|
||||||
|
|
||||||
if c.conf.ReadOnly() {
|
if c.conf.ReadOnly() {
|
||||||
return nil, fmt.Errorf("convert: disabled in read only mode (%s)", image.FileName())
|
return nil, fmt.Errorf("convert: disabled in read only mode (%s)", image.RelativeName(c.conf.OriginalsPath()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName := image.RelativeName(c.conf.OriginalsPath())
|
fileName := image.RelativeName(c.conf.OriginalsPath())
|
||||||
|
|
||||||
log.Infof("convert: %s -> %s", fileName, jpegName)
|
log.Infof("convert: %s -> %s", fileName, fs.RelativeName(jpegName, c.conf.OriginalsPath()))
|
||||||
|
|
||||||
xmpName := fs.TypeXMP.Find(image.FileName(), c.conf.Settings().Library.GroupRelated)
|
xmpName := fs.TypeXMP.Find(image.FileName(), c.conf.Settings().Library.GroupRelated)
|
||||||
|
|
||||||
|
|
|
@ -99,10 +99,6 @@ func (imp *Import) Start(opt ImportOptions) {
|
||||||
return errors.New("import canceled")
|
return errors.New("import canceled")
|
||||||
}
|
}
|
||||||
|
|
||||||
if done[fileName] {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
isDir := info.IsDir()
|
isDir := info.IsDir()
|
||||||
isSymlink := info.IsSymlink()
|
isSymlink := info.IsSymlink()
|
||||||
|
|
||||||
|
@ -141,7 +137,7 @@ func (imp *Import) Start(opt ImportOptions) {
|
||||||
done[f.FileName()] = true
|
done[f.FileName()] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
done[mf.FileName()] = true
|
done[fileName] = true
|
||||||
|
|
||||||
related.Files = files
|
related.Files = files
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/photoprism/photoprism/internal/event"
|
"github.com/photoprism/photoprism/internal/event"
|
||||||
|
"github.com/photoprism/photoprism/pkg/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImportJob struct {
|
type ImportJob struct {
|
||||||
|
@ -47,23 +48,23 @@ func ImportWorker(jobs <-chan ImportJob) {
|
||||||
|
|
||||||
if related.Main.HasSameName(f) {
|
if related.Main.HasSameName(f) {
|
||||||
destinationMainFilename = destinationFilename
|
destinationMainFilename = destinationFilename
|
||||||
log.Infof("import: moving main %s file \"%s\" to \"%s\"", f.FileType(), relativeFilename, destinationFilename)
|
log.Infof("import: moving main %s file \"%s\" to \"%s\"", f.FileType(), relativeFilename, fs.RelativeName(destinationFilename, imp.originalsPath()))
|
||||||
} else {
|
} else {
|
||||||
log.Infof("import: moving related %s file \"%s\" to \"%s\"", f.FileType(), relativeFilename, destinationFilename)
|
log.Infof("import: moving related %s file \"%s\" to \"%s\"", f.FileType(), relativeFilename, fs.RelativeName(destinationFilename, imp.originalsPath()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if opt.Move {
|
if opt.Move {
|
||||||
if err := f.Move(destinationFilename); err != nil {
|
if err := f.Move(destinationFilename); err != nil {
|
||||||
log.Errorf("import: could not move file to %s (%s)", destinationMainFilename, err.Error())
|
log.Errorf("import: could not move file to %s (%s)", fs.RelativeName(destinationMainFilename, imp.originalsPath()), err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := f.Copy(destinationFilename); err != nil {
|
if err := f.Copy(destinationFilename); err != nil {
|
||||||
log.Errorf("import: could not copy file to %s (%s)", destinationMainFilename, err.Error())
|
log.Errorf("import: could not copy file to %s (%s)", fs.RelativeName(destinationMainFilename, imp.originalsPath()), err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if opt.RemoveExistingFiles {
|
} else if opt.RemoveExistingFiles {
|
||||||
if err := f.Remove(); err != nil {
|
if err := f.Remove(); err != nil {
|
||||||
log.Errorf("import: could not delete %s (%s)", f.FileName(), err.Error())
|
log.Errorf("import: could not delete %s (%s)",fs.RelativeName(f.FileName(), importPath), err.Error())
|
||||||
} else {
|
} else {
|
||||||
log.Infof("import: deleted %s (already exists)", relativeFilename)
|
log.Infof("import: deleted %s (already exists)", relativeFilename)
|
||||||
}
|
}
|
||||||
|
@ -74,7 +75,7 @@ func ImportWorker(jobs <-chan ImportJob) {
|
||||||
importedMainFile, err := NewMediaFile(destinationMainFilename)
|
importedMainFile, err := NewMediaFile(destinationMainFilename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("import: could not index \"%s\" (%s)", destinationMainFilename, err.Error())
|
log.Errorf("import: could not index \"%s\" (%s)", fs.RelativeName(destinationMainFilename, imp.originalsPath()), err.Error())
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -96,7 +97,7 @@ func ImportWorker(jobs <-chan ImportJob) {
|
||||||
related, err := importedMainFile.RelatedFiles(imp.conf.Settings().Library.GroupRelated)
|
related, err := importedMainFile.RelatedFiles(imp.conf.Settings().Library.GroupRelated)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("import: could not index \"%s\" (%s)", destinationMainFilename, err.Error())
|
log.Errorf("import: could not index \"%s\" (%s)", fs.RelativeName(destinationMainFilename, imp.originalsPath()), err.Error())
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -109,7 +110,7 @@ func ImportWorker(jobs <-chan ImportJob) {
|
||||||
log.Infof("import: %s main %s file \"%s\"", res, related.Main.FileType(), related.Main.RelativeName(ind.originalsPath()))
|
log.Infof("import: %s main %s file \"%s\"", res, related.Main.FileType(), related.Main.RelativeName(ind.originalsPath()))
|
||||||
done[related.Main.FileName()] = true
|
done[related.Main.FileName()] = true
|
||||||
} else {
|
} else {
|
||||||
log.Warnf("import: no main file for %s (conversion to jpeg failed?)", destinationMainFilename)
|
log.Warnf("import: no main file for %s (conversion to jpeg failed?)", fs.RelativeName(destinationMainFilename, imp.originalsPath()))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range related.Files {
|
for _, f := range related.Files {
|
||||||
|
|
|
@ -141,7 +141,7 @@ func (ind *Index) Start(options IndexOptions) map[string]bool {
|
||||||
done[f.FileName()] = true
|
done[f.FileName()] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
done[mf.FileName()] = true
|
done[fileName] = true
|
||||||
|
|
||||||
related.Files = files
|
related.Files = files
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package photoprism
|
package photoprism
|
||||||
|
|
||||||
|
import "github.com/photoprism/photoprism/pkg/fs"
|
||||||
|
|
||||||
type IndexJob struct {
|
type IndexJob struct {
|
||||||
FileName string
|
FileName string
|
||||||
Related RelatedFiles
|
Related RelatedFiles
|
||||||
|
@ -20,7 +22,7 @@ func IndexWorker(jobs <-chan IndexJob) {
|
||||||
|
|
||||||
log.Infof("index: %s main %s file \"%s\"", res, related.Main.FileType(), related.Main.RelativeName(ind.originalsPath()))
|
log.Infof("index: %s main %s file \"%s\"", res, related.Main.FileType(), related.Main.RelativeName(ind.originalsPath()))
|
||||||
} else {
|
} else {
|
||||||
log.Warnf("index: no main file for %s (conversion to jpeg failed?)", job.FileName)
|
log.Warnf("index: no main file for %s (conversion to jpeg failed?)", fs.RelativeName(job.FileName, ind.originalsPath()))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range related.Files {
|
for _, f := range related.Files {
|
||||||
|
|
|
@ -82,6 +82,8 @@ func (rs *Resample) Start(force bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done[fileName] = true
|
||||||
|
|
||||||
relativeName := mf.RelativeName(originalsPath)
|
relativeName := mf.RelativeName(originalsPath)
|
||||||
|
|
||||||
event.Publish("index.thumbnails", event.Data{
|
event.Publish("index.thumbnails", event.Data{
|
||||||
|
|
|
@ -112,17 +112,17 @@ func (l *IgnoreList) Dir(dir string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if l.configFile == "" {
|
if l.configFile == "" {
|
||||||
return errors.New("ignore file name not set")
|
return errors.New("empty ignore file name")
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName := filepath.Join(dir, l.configFile)
|
fileName := filepath.Join(dir, l.configFile)
|
||||||
|
|
||||||
if _, ok := l.configFiles[fileName]; ok {
|
if _, ok := l.configFiles[fileName]; ok {
|
||||||
return fmt.Errorf("%s already parsed", l.configFile)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !FileExists(fileName) {
|
if !FileExists(fileName) {
|
||||||
return fmt.Errorf("%s does not exist", l.configFile)
|
return fmt.Errorf("no %s file found", l.configFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
return l.ConfigFile(fileName)
|
return l.ConfigFile(fileName)
|
||||||
|
|
|
@ -10,8 +10,6 @@ func SkipWalk(fileName string, isDir, isSymlink bool, done map[string]bool, igno
|
||||||
isDone := done[fileName]
|
isDone := done[fileName]
|
||||||
isIgnored := ignore.Ignore(fileName)
|
isIgnored := ignore.Ignore(fileName)
|
||||||
|
|
||||||
done[fileName] = true
|
|
||||||
|
|
||||||
if isSymlink {
|
if isSymlink {
|
||||||
// Symlinks are skipped by default unless they are links to directories
|
// Symlinks are skipped by default unless they are links to directories
|
||||||
skip = true
|
skip = true
|
||||||
|
@ -39,5 +37,9 @@ func SkipWalk(fileName string, isDir, isSymlink bool, done map[string]bool, igno
|
||||||
skip = true
|
skip = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if skip {
|
||||||
|
done[fileName] = true
|
||||||
|
}
|
||||||
|
|
||||||
return skip, result
|
return skip, result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue