2019-02-25 23:36:18 +01:00
|
|
|
package app
|
|
|
|
|
2019-02-25 23:51:18 +01:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"github.com/sirupsen/logrus"
|
2019-02-26 00:02:22 +01:00
|
|
|
"haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/localFileStructure"
|
|
|
|
"haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo/category"
|
2019-02-27 23:26:18 +01:00
|
|
|
"haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo/picture"
|
2019-02-25 23:51:18 +01:00
|
|
|
)
|
2019-02-25 23:36:18 +01:00
|
|
|
|
2019-02-27 22:13:23 +01:00
|
|
|
func synchronizeImages(context *appContext, fileSystem map[string]*localFileStructure.FilesystemNode, existingCategories map[string]*category.PiwigoCategory) error {
|
2019-02-27 00:09:41 +01:00
|
|
|
|
2019-02-27 22:11:47 +01:00
|
|
|
imageFiles, err := localFileStructure.GetImageList(fileSystem)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-02-27 00:09:41 +01:00
|
|
|
|
2019-02-27 23:26:18 +01:00
|
|
|
missingFiles, err := findMissingImages(context, imageFiles)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-02-27 00:09:41 +01:00
|
|
|
uploadImages(missingFiles)
|
|
|
|
|
2019-02-26 00:02:22 +01:00
|
|
|
return errors.New("synchronizeImages: NOT IMPLEMENTED")
|
2019-02-25 23:36:18 +01:00
|
|
|
}
|
|
|
|
|
2019-02-27 23:26:18 +01:00
|
|
|
func findMissingImages(context *appContext, imageFiles []*localFileStructure.ImageNode) ([]*localFileStructure.ImageNode, error) {
|
|
|
|
|
|
|
|
logrus.Debugln("Preparing lookuplist for missing files...")
|
|
|
|
|
|
|
|
files := make([]string, 0, len(imageFiles))
|
|
|
|
md5map := make(map[string]*localFileStructure.ImageNode, len(imageFiles))
|
|
|
|
for _, file := range imageFiles {
|
|
|
|
md5map[file.Md5Sum] = file
|
|
|
|
files = append(files, file.Md5Sum)
|
|
|
|
}
|
|
|
|
|
|
|
|
misingSums, err := picture.ImageUploadRequired(context.Piwigo, files)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
missingFiles := make([]*localFileStructure.ImageNode, 0, len(misingSums))
|
|
|
|
for _, sum := range misingSums {
|
|
|
|
file := md5map[sum]
|
|
|
|
logrus.Infof("Found missing file %s", file.Path)
|
|
|
|
missingFiles = append(missingFiles, file)
|
|
|
|
}
|
2019-02-27 00:09:41 +01:00
|
|
|
|
2019-02-27 23:26:18 +01:00
|
|
|
logrus.Infof("Found %d missing files", len(missingFiles))
|
2019-02-27 00:09:41 +01:00
|
|
|
|
2019-02-27 23:26:18 +01:00
|
|
|
return missingFiles, nil
|
2019-02-25 23:36:18 +01:00
|
|
|
}
|
|
|
|
|
2019-02-27 23:26:18 +01:00
|
|
|
func uploadImages(missingFiles []*localFileStructure.ImageNode) {
|
2019-02-25 23:36:18 +01:00
|
|
|
logrus.Warnln("Uploading missing images (NotImplemented)")
|
|
|
|
}
|