started synchronization of piwigo ids and upload required
This commit is contained in:
parent
20eeba2615
commit
5166b0c6b8
@ -48,11 +48,16 @@ func Run() {
|
||||
logErrorAndExit(err, 6)
|
||||
}
|
||||
|
||||
err = synchronizeImages(context.piwigo, context.dataStore, categories)
|
||||
err = synchronizePiwigoMetadata(context.piwigo, context.dataStore)
|
||||
if err != nil {
|
||||
logErrorAndExit(err, 7)
|
||||
}
|
||||
|
||||
err = synchronizeImages(context.piwigo, context.dataStore, categories)
|
||||
if err != nil {
|
||||
logErrorAndExit(err, 8)
|
||||
}
|
||||
|
||||
_ = piwigo.Logout(context.piwigo)
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/localFileStructure"
|
||||
"git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -18,6 +19,7 @@ func synchronizeLocalImageMetadata(metadataStorage ImageMetadataProvider, fileSy
|
||||
// - get file metadata from filesystem (date, filename, dir, modtime etc.)
|
||||
// - recalculate md5 sum if file changed referring to the stored record (reduces load after first calculation a lot)
|
||||
// - mark metadata as upload required if changed or new
|
||||
logrus.Debugf("Starting synchronizeLocalImageMetadata")
|
||||
|
||||
logrus.Info("Synchronizing local image metadata database with local available images")
|
||||
|
||||
@ -58,12 +60,32 @@ func synchronizeLocalImageMetadata(metadataStorage ImageMetadataProvider, fileSy
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("Finished synchronizeLocalImageMetadata")
|
||||
return nil
|
||||
}
|
||||
|
||||
// STEP 2 - get file states from piwigo (pwg.images.checkFiles)
|
||||
// - get upload status of md5 sum from piwigo for all marked to upload
|
||||
// - check if category has to be assigned (image possibly added to two albums -> only uploaded once but assigned multiple times)
|
||||
func synchronizePiwigoMetadata(piwigo *piwigo.PiwigoContext, metadataStorage ImageMetadataProvider) error {
|
||||
// STEP 2 - get file states from piwigo (pwg.images.checkFiles)
|
||||
// - make bulk query possible
|
||||
// - get upload status of md5 sum from piwigo for all marked to upload
|
||||
// - build method to update database with new piwigoId by md5 sum
|
||||
// - set UploadRequired to false and the returned piwigoid
|
||||
// - check if category has to be assigned (image possibly added to two albums -> only uploaded once but assigned multiple times) -> implement later
|
||||
|
||||
logrus.Debugf("Starting synchronizePiwigoMetadata")
|
||||
images, err := metadataStorage.GetImageMetadataToUpload()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Infof("Synchronizing metadata with existing Piwigo data...")
|
||||
for img := range images {
|
||||
logrus.Debug(img)
|
||||
}
|
||||
|
||||
logrus.Debugf("Finished synchronizePiwigoMetadata")
|
||||
return errors.New("N/A")
|
||||
}
|
||||
|
||||
// STEP 3: Upload missing images
|
||||
// - upload file in chunks
|
||||
|
@ -1,6 +1,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/localFileStructure"
|
||||
"testing"
|
||||
"time"
|
||||
@ -160,6 +161,25 @@ func TestSynchronizeLocalImageMetadataShouldNotProcessDirectories(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSynchronizePiwigoMetadata(t *testing.T) {
|
||||
db := NewtestStore()
|
||||
db.savedMetadata["2019/shooting1/abc.jpg"] = ImageMetaData{
|
||||
Md5Sum: "2019/shooting1/abc.jpg",
|
||||
RelativeImagePath: "2019/shooting1/abc.jpg",
|
||||
UploadRequired: false,
|
||||
LastChange: time.Date(2019, 01, 01, 00, 0, 0, 0, time.UTC),
|
||||
Filename: "abc.jpg",
|
||||
}
|
||||
|
||||
|
||||
// execute the sync metadata based on the file system results
|
||||
//err := synchronizeLocalImageMetadata( db)
|
||||
//if err != nil {
|
||||
// t.Error(err)
|
||||
//}
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
// test metadata store to store save the metadat and simulate the database
|
||||
type testStore struct {
|
||||
savedMetadata map[string]ImageMetaData
|
||||
@ -182,6 +202,10 @@ func (s *testStore) SaveImageMetadata(m ImageMetaData) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *testStore) GetImageMetadataToUpload() ([]*ImageMetaData, error) {
|
||||
return nil, errors.New("N/A")
|
||||
}
|
||||
|
||||
// to make the sync testable, we pass in a simple mock that returns the filepath as checksum
|
||||
func testChecksumCalculator(file string) (string, error) {
|
||||
return file, nil
|
||||
|
Loading…
Reference in New Issue
Block a user