diff --git a/internal/api/import.go b/internal/api/import.go index 51f85b8a1..459ad83bd 100644 --- a/internal/api/import.go +++ b/internal/api/import.go @@ -47,19 +47,21 @@ func StartImport(router *gin.RouterGroup, conf *config.Config) { start := time.Now() path := conf.ImportPath() - if subPath = c.Param("path"); subPath != "" { + if subPath = c.Param("path"); subPath != "" && subPath != "/" { subPath = strings.Replace(subPath, ".", "", -1) log.Debugf("import sub path: %s", subPath) path = path + subPath } + path = filepath.Clean(path) + event.Info(fmt.Sprintf("importing photos from \"%s\"", filepath.Base(path))) initImport(conf) imp.Start(path) - if subPath != "" && util.DirectoryIsEmpty(path) { + if subPath != "" && path != conf.ImportPath() && util.DirectoryIsEmpty(path) { if err := os.Remove(path); err != nil { log.Errorf("import: could not deleted empty directory \"%s\": %s", path, err) } else { diff --git a/internal/config/filenames.go b/internal/config/filenames.go index 149836fe5..19210a545 100644 --- a/internal/config/filenames.go +++ b/internal/config/filenames.go @@ -114,17 +114,17 @@ func (c *Config) LogFilename() string { // OriginalsPath returns the originals. func (c *Config) OriginalsPath() string { - return c.config.OriginalsPath + return filepath.Clean(c.config.OriginalsPath) } // ImportPath returns the import directory. func (c *Config) ImportPath() string { - return c.config.ImportPath + return filepath.Clean(c.config.ImportPath) } // ExportPath returns the export directory. func (c *Config) ExportPath() string { - return c.config.ExportPath + return filepath.Clean(c.config.ExportPath) } // SipsBin returns the sips binary file name. diff --git a/internal/photoprism/import.go b/internal/photoprism/import.go index d4ed5db0b..80bf3c6ac 100644 --- a/internal/photoprism/import.go +++ b/internal/photoprism/import.go @@ -102,6 +102,7 @@ func (imp *Import) Start(importPath string) { if filename != importPath { directories = append(directories, filename) } + return nil } @@ -114,13 +115,13 @@ func (imp *Import) Start(importPath string) { return nil } - mediaFile, err := NewMediaFile(filename) + mf, err := NewMediaFile(filename) - if err != nil || !mediaFile.IsPhoto() { + if err != nil || !mf.IsPhoto() { return nil } - related, err := mediaFile.RelatedFiles() + related, err := mf.RelatedFiles() if err != nil { event.Error(fmt.Sprintf("import: %s", err.Error())) @@ -128,10 +129,19 @@ func (imp *Import) Start(importPath string) { return nil } + var files MediaFiles + for _, f := range related.files { + if done[f.Filename()] { continue } + + files = append(files, f) done[f.Filename()] = true } + done[mf.Filename()] = true + + related.files = files + jobs <- ImportJob{ related: related, opt: options, diff --git a/internal/photoprism/index.go b/internal/photoprism/index.go index eb3b8b279..0caacae69 100644 --- a/internal/photoprism/index.go +++ b/internal/photoprism/index.go @@ -103,13 +103,13 @@ func (ind *Index) Start(options IndexOptions) map[string]bool { return nil } - mediaFile, err := NewMediaFile(filename) + mf, err := NewMediaFile(filename) - if err != nil || !mediaFile.IsPhoto() { + if err != nil || !mf.IsPhoto() { return nil } - related, err := mediaFile.RelatedFiles() + related, err := mf.RelatedFiles() if err != nil { log.Warnf("index: %s", err.Error()) @@ -117,10 +117,19 @@ func (ind *Index) Start(options IndexOptions) map[string]bool { return nil } + var files MediaFiles + for _, f := range related.files { + if done[f.Filename()] { continue } + + files = append(files, f) done[f.Filename()] = true } + done[mf.Filename()] = true + + related.files = files + jobs <- IndexJob{ related: related, opt: options,