PiwigoDirectoryUploader/internal/app/app.go

112 lines
2.9 KiB
Go
Raw Normal View History

2019-02-23 21:57:54 +01:00
package app
import (
"errors"
2019-02-24 23:11:52 +01:00
"flag"
2019-02-23 21:57:54 +01:00
"github.com/sirupsen/logrus"
"haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/localFileStructure"
"haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo/authentication"
"os"
2019-02-23 21:57:54 +01:00
)
2019-02-24 23:11:52 +01:00
var (
imagesRootPath = flag.String("imagesRootPath", "", "This is the images root path that should be mirrored to piwigo.")
piwigoUrl = flag.String("piwigoUrl", "", "The root url 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.")
2019-02-24 23:11:52 +01:00
)
func Run() {
context, err := configureContext()
if err != nil {
os.Exit(1)
}
loginToPiwigoAndConfigureContext(context)
//ScanLocalDirectories(context)
//GetAllCategoriesFromServer()
//FindMissingAlbums()
//CreateMissingAlbums()
//FindMissingImages()
//UploadImages()
2019-02-24 21:38:28 +01:00
_ = authentication.Logout(context.Piwigo)
2019-02-23 21:57:54 +01:00
}
func ScanLocalDirectories(context *AppContext) {
2019-02-24 21:38:28 +01:00
fileNodes, err := localFileStructure.ScanLocalFileStructure(context.LocalRootPath)
if err != nil {
panic(err)
}
for _, node := range fileNodes {
logrus.Debugln("found path entry:", node.Key)
}
2019-02-23 21:57:54 +01:00
}
2019-02-23 22:02:12 +01:00
func GetAllCategoriesFromServer() {
2019-02-23 21:57:54 +01:00
// get all categories from server and flatten structure to match directory names
// 2018/2018 album blah
logrus.Warnln("Loading all categories from the server (NotImplemented)")
}
2019-02-23 22:02:12 +01:00
func FindMissingAlbums() {
2019-02-23 21:57:54 +01:00
logrus.Warnln("Looking up missing albums (NotImplemented)")
}
2019-02-23 22:02:12 +01:00
func CreateMissingAlbums() {
2019-02-23 21:57:54 +01:00
logrus.Warnln("Creating missing albums (NotImplemented)")
}
2019-02-23 22:02:12 +01:00
func FindMissingImages() {
2019-02-23 21:57:54 +01:00
logrus.Warnln("Finding missing images (NotImplemented)")
}
2019-02-23 22:02:12 +01:00
func UploadImages() {
2019-02-23 21:57:54 +01:00
logrus.Warnln("Uploading missing images (NotImplemented)")
2019-02-23 22:02:12 +01:00
}
func configureContext() (*AppContext, error) {
2019-02-24 01:17:10 +01:00
logrus.Infoln("Preparing application context and configuration")
if *piwigoUrl == "" {
return nil, errors.New("missing piwigo url!")
}
if *piwigoUser == "" {
return nil, errors.New("missing piwigo user!")
}
if *piwigoPassword == "" {
return nil, errors.New("missing piwigo password!")
}
2019-02-24 01:17:10 +01:00
context := new(AppContext)
2019-02-24 23:11:52 +01:00
context.LocalRootPath = *imagesRootPath
2019-02-24 01:17:10 +01:00
context.Piwigo = new(authentication.PiwigoContext)
2019-02-24 23:11:52 +01:00
context.Piwigo.Url = *piwigoUrl
context.Piwigo.Username = *piwigoUser
context.Piwigo.Password = *piwigoPassword
2019-02-24 01:17:10 +01:00
return context, nil
2019-02-24 01:17:10 +01:00
}
func loginToPiwigoAndConfigureContext(context *AppContext) {
logrus.Infoln("Logging in to piwigo and getting chunk size configuration for uploads")
2019-02-24 21:38:28 +01:00
err := authentication.Login(context.Piwigo)
if err != nil {
panic(err)
}
initializeUploadChunkSize(context)
}
func initializeUploadChunkSize(context *AppContext) {
2019-02-24 21:38:28 +01:00
userStatus, err := authentication.GetStatus(context.Piwigo)
if err != nil {
panic(err)
}
context.ChunkSizeBytes = userStatus.Result.UploadFormChunkSize * 1024
logrus.Debugln(context.ChunkSizeBytes)
}