2019-03-12 23:44:05 +01:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type appContext struct {
|
2019-03-15 23:54:22 +01:00
|
|
|
// think again if this is a good idea to have such a context!
|
2019-03-12 23:44:05 +01:00
|
|
|
piwigo *piwigo.PiwigoContext
|
2019-03-15 23:54:22 +01:00
|
|
|
dataStore *localDataStore
|
2019-03-12 23:44:05 +01:00
|
|
|
sessionId string
|
|
|
|
localRootPath string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *appContext) UseMetadataStore(connectionString string) error {
|
|
|
|
if connectionString == "" {
|
|
|
|
return errors.New("missing connectionString to use metadata store!")
|
|
|
|
}
|
|
|
|
|
|
|
|
logrus.Infof("Using SQL Lite data store with '%s'", connectionString)
|
2019-03-15 23:54:22 +01:00
|
|
|
c.dataStore = &localDataStore{}
|
2019-03-15 00:35:49 +01:00
|
|
|
err := c.dataStore.Initialize(connectionString)
|
2019-03-12 23:44:05 +01:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *appContext) UsePiwigo(url string, user string, password string) error {
|
|
|
|
if url == "" {
|
|
|
|
return errors.New("missing piwigo url!")
|
|
|
|
}
|
|
|
|
|
|
|
|
if user == "" {
|
|
|
|
return errors.New("missing piwigo user!")
|
|
|
|
}
|
|
|
|
|
|
|
|
if password == "" {
|
|
|
|
return errors.New("missing piwigo password!")
|
|
|
|
}
|
|
|
|
|
|
|
|
c.piwigo = new(piwigo.PiwigoContext)
|
|
|
|
return c.piwigo.Initialize(*piwigoUrl, *piwigoUser, *piwigoPassword, *piwigoUploadChunkSizeInKB)
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:28:28 +01:00
|
|
|
func newAppContext() (*appContext, error) {
|
2019-03-12 23:44:05 +01:00
|
|
|
logrus.Infoln("Preparing application context and configuration")
|
|
|
|
|
|
|
|
context := new(appContext)
|
|
|
|
context.localRootPath = *imagesRootPath
|
|
|
|
|
|
|
|
if *sqliteDb != "" {
|
|
|
|
err := context.UseMetadataStore(*sqliteDb)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logrus.Warnln("No persistence configured. Skipping metadata storage. This might affect performance on large collections!")
|
|
|
|
}
|
|
|
|
|
|
|
|
err := context.UsePiwigo(*piwigoUrl, *piwigoUser, *piwigoPassword)
|
|
|
|
|
|
|
|
return context, err
|
|
|
|
}
|