added interfaces to the piwigo context to make testing easier
This commit is contained in:
parent
390a60418f
commit
8e3c736bf9
@ -37,7 +37,7 @@ func Run() {
|
||||
logErrorAndExit(err, 4)
|
||||
}
|
||||
|
||||
err = synchronizeCategories(context, filesystemNodes, categories)
|
||||
err = synchronizeCategories(context.piwigo, filesystemNodes, categories)
|
||||
if err != nil {
|
||||
logErrorAndExit(err, 5)
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ func getAllCategoriesFromServer(context *appContext) (map[string]*piwigo.PiwigoC
|
||||
return categories, err
|
||||
}
|
||||
|
||||
func synchronizeCategories(context *appContext, filesystemNodes map[string]*localFileStructure.FilesystemNode, existingCategories map[string]*piwigo.PiwigoCategory) error {
|
||||
func synchronizeCategories(piwigoApi piwigo.PiwigoCategoryApi, filesystemNodes map[string]*localFileStructure.FilesystemNode, existingCategories map[string]*piwigo.PiwigoCategory) error {
|
||||
logrus.Infoln("Synchronizing categories...")
|
||||
|
||||
missingCategories := findMissingCategories(filesystemNodes, existingCategories)
|
||||
@ -26,7 +26,7 @@ func synchronizeCategories(context *appContext, filesystemNodes map[string]*loca
|
||||
return nil
|
||||
}
|
||||
|
||||
return createMissingCategories(context, missingCategories, existingCategories)
|
||||
return createMissingCategories(piwigoApi, missingCategories, existingCategories)
|
||||
}
|
||||
|
||||
func findMissingCategories(fileSystem map[string]*localFileStructure.FilesystemNode, existingCategories map[string]*piwigo.PiwigoCategory) []string {
|
||||
@ -50,7 +50,7 @@ func findMissingCategories(fileSystem map[string]*localFileStructure.FilesystemN
|
||||
return missingCategories
|
||||
}
|
||||
|
||||
func createMissingCategories(context *appContext, missingCategories []string, existingCategories map[string]*piwigo.PiwigoCategory) error {
|
||||
func createMissingCategories(piwigoApi piwigo.PiwigoCategoryApi, missingCategories []string, existingCategories map[string]*piwigo.PiwigoCategory) error {
|
||||
// we sort them to make sure the categories gets created
|
||||
// in the right order and we have the parent available while creating the children
|
||||
sort.Strings(missingCategories)
|
||||
@ -66,7 +66,7 @@ func createMissingCategories(context *appContext, missingCategories []string, ex
|
||||
}
|
||||
|
||||
// create category on piwigo
|
||||
id, err := context.piwigo.CreateCategory(parentId, name)
|
||||
id, err := piwigoApi.CreateCategory(parentId, name)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Could not create category on piwigo: %s", err))
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func synchronizeLocalImageMetadata(metadataStorage ImageMetadataProvider, fileSy
|
||||
}
|
||||
|
||||
// This method agregates the check for files with missing piwigoids and if changed files need to be uploaded again.
|
||||
func synchronizePiwigoMetadata(piwigoCtx *piwigo.PiwigoContext, metadataStorage ImageMetadataProvider) error {
|
||||
func synchronizePiwigoMetadata(piwigoCtx piwigo.PiwigoImageApi, metadataStorage ImageMetadataProvider) error {
|
||||
// TODO: 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")
|
||||
err := updatePiwigoIdIfAlreadyUploaded(metadataStorage, piwigoCtx)
|
||||
@ -78,7 +78,7 @@ func synchronizePiwigoMetadata(piwigoCtx *piwigo.PiwigoContext, metadataStorage
|
||||
}
|
||||
|
||||
// Check all images with upload required if they are really changed and need to be uploaded to the server.
|
||||
func checkPiwigoForChangedImages(provider ImageMetadataProvider, piwigoCtx *piwigo.PiwigoContext) error {
|
||||
func checkPiwigoForChangedImages(provider ImageMetadataProvider, piwigoCtx piwigo.PiwigoImageApi) error {
|
||||
logrus.Infof("Checking pending files if they really differ from the version in piwigo...")
|
||||
|
||||
images, err := provider.ImageMetadataToUpload()
|
||||
@ -116,7 +116,7 @@ func checkPiwigoForChangedImages(provider ImageMetadataProvider, piwigoCtx *piwi
|
||||
|
||||
// This function calls piwigo and checks if the given md5sum is already present.
|
||||
// Only files without a piwigo id are used to query the server.
|
||||
func updatePiwigoIdIfAlreadyUploaded(provider ImageMetadataProvider, piwigoCtx *piwigo.PiwigoContext) error {
|
||||
func updatePiwigoIdIfAlreadyUploaded(provider ImageMetadataProvider, piwigoCtx piwigo.PiwigoImageApi) error {
|
||||
logrus.Infof("checking for pending files that are already on piwigo and updating piwigoids...")
|
||||
images, err := provider.ImageMetadataToUpload()
|
||||
if err != nil {
|
||||
|
@ -13,6 +13,24 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type PiwigoApi interface {
|
||||
Initialize(baseUrl string, username string, password string, chunkSizeInKB int) error
|
||||
Login() error
|
||||
Logout() error
|
||||
GetStatus() (*getStatusResponse, error)
|
||||
}
|
||||
|
||||
type PiwigoCategoryApi interface {
|
||||
GetAllCategories() (map[string]*PiwigoCategory, error)
|
||||
CreateCategory(parentId int, name string) (int, error)
|
||||
}
|
||||
|
||||
type PiwigoImageApi interface {
|
||||
ImageCheckFile(piwigoId int, md5sum string) (int, error)
|
||||
ImagesExistOnPiwigo(md5sums []string) (map[string]int, error)
|
||||
UploadImage(filePath string, md5sum string, category int) (int, error)
|
||||
}
|
||||
|
||||
type PiwigoContext struct {
|
||||
url string
|
||||
username string
|
||||
|
Loading…
Reference in New Issue
Block a user