2019-02-23 21:57:54 +01:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2019-02-24 23:11:52 +01:00
|
|
|
"flag"
|
2019-03-03 23:44:13 +01:00
|
|
|
"git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/localFileStructure"
|
2019-03-02 00:21:01 +01:00
|
|
|
"github.com/sirupsen/logrus"
|
2019-02-24 23:27:31 +01:00
|
|
|
"os"
|
2019-02-23 21:57:54 +01:00
|
|
|
)
|
|
|
|
|
2019-02-24 23:11:52 +01:00
|
|
|
var (
|
2019-03-02 00:21:01 +01:00
|
|
|
imagesRootPath = flag.String("imagesRootPath", "", "This is the images root path that should be mirrored to piwigo.")
|
2019-03-12 23:44:05 +01:00
|
|
|
sqliteDb = flag.String("sqliteDb", "", "The connection string to the sql lite database file.")
|
2019-03-02 00:21:01 +01:00
|
|
|
piwigoUrl = flag.String("piwigoUrl", "", "The root url without tailing slash to your piwigo installation.")
|
|
|
|
piwigoUser = flag.String("piwigoUser", "", "The username to use during sync.")
|
|
|
|
piwigoPassword = flag.String("piwigoPassword", "", "This is password to the given username.")
|
|
|
|
piwigoUploadChunkSizeInKB = flag.Int("piwigoUploadChunkSizeInKB", 512, "The chunksize used to upload an image to piwigo.")
|
2019-02-24 23:11:52 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func Run() {
|
2019-03-12 23:44:05 +01:00
|
|
|
context, err := createAppContext()
|
2019-02-24 23:27:31 +01:00
|
|
|
if err != nil {
|
2019-02-25 23:51:18 +01:00
|
|
|
logErrorAndExit(err, 1)
|
2019-02-24 23:27:31 +01:00
|
|
|
}
|
2019-02-24 00:33:18 +01:00
|
|
|
|
2019-03-20 00:14:10 +01:00
|
|
|
err = context.piwigo.Login()
|
2019-02-24 23:32:05 +01:00
|
|
|
if err != nil {
|
2019-02-25 23:51:18 +01:00
|
|
|
logErrorAndExit(err, 2)
|
2019-02-24 23:32:05 +01:00
|
|
|
}
|
2019-02-25 00:02:59 +01:00
|
|
|
|
2019-03-12 23:44:05 +01:00
|
|
|
filesystemNodes, err := localFileStructure.ScanLocalFileStructure(context.localRootPath)
|
2019-02-24 21:38:28 +01:00
|
|
|
if err != nil {
|
2019-02-25 23:51:18 +01:00
|
|
|
logErrorAndExit(err, 3)
|
2019-02-24 00:33:18 +01:00
|
|
|
}
|
2019-02-25 00:02:59 +01:00
|
|
|
|
2019-02-25 23:36:18 +01:00
|
|
|
categories, err := getAllCategoriesFromServer(context)
|
2019-02-25 00:02:59 +01:00
|
|
|
if err != nil {
|
2019-02-25 23:51:18 +01:00
|
|
|
logErrorAndExit(err, 4)
|
2019-02-25 00:02:59 +01:00
|
|
|
}
|
|
|
|
|
2019-03-20 21:41:41 +01:00
|
|
|
err = synchronizeCategories(context.piwigo, filesystemNodes, categories)
|
2019-02-25 23:36:18 +01:00
|
|
|
if err != nil {
|
2019-02-25 23:51:18 +01:00
|
|
|
logErrorAndExit(err, 5)
|
2019-02-25 23:11:09 +01:00
|
|
|
}
|
2019-02-23 21:57:54 +01:00
|
|
|
|
2019-03-17 23:05:17 +01:00
|
|
|
err = synchronizeLocalImageMetadata(context.dataStore, filesystemNodes, localFileStructure.CalculateFileCheckSums)
|
2019-02-25 23:36:18 +01:00
|
|
|
if err != nil {
|
2019-02-25 23:51:18 +01:00
|
|
|
logErrorAndExit(err, 6)
|
2019-02-25 23:36:18 +01:00
|
|
|
}
|
2019-02-23 21:57:54 +01:00
|
|
|
|
2019-03-17 23:57:28 +01:00
|
|
|
err = synchronizePiwigoMetadata(context.piwigo, context.dataStore)
|
2019-03-17 23:05:17 +01:00
|
|
|
if err != nil {
|
|
|
|
logErrorAndExit(err, 7)
|
|
|
|
}
|
|
|
|
|
2019-03-19 23:08:28 +01:00
|
|
|
//err = synchronizeImages(context.piwigo, context.dataStore, categories)
|
|
|
|
//if err != nil {
|
|
|
|
// logErrorAndExit(err, 8)
|
|
|
|
//}
|
2019-03-17 23:57:28 +01:00
|
|
|
|
2019-03-20 00:14:10 +01:00
|
|
|
_ = context.piwigo.Logout()
|
2019-02-24 00:33:18 +01:00
|
|
|
}
|
2019-02-25 23:51:18 +01:00
|
|
|
|
|
|
|
func logErrorAndExit(err error, exitCode int) {
|
|
|
|
logrus.Errorln(err)
|
|
|
|
os.Exit(exitCode)
|
|
|
|
}
|