2021-02-03 20:00:11 +01:00
|
|
|
package sampleapp
|
|
|
|
|
|
|
|
import (
|
2021-02-03 23:00:31 +01:00
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
|
2021-02-03 20:00:11 +01:00
|
|
|
"github.com/kris-nova/logger"
|
|
|
|
|
|
|
|
photoprism "github.com/kris-nova/client-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SampleApplication struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func New() *SampleApplication {
|
|
|
|
app := &SampleApplication{}
|
|
|
|
return app
|
|
|
|
}
|
|
|
|
|
|
|
|
// These are the bash scripts that can be used
|
|
|
|
// to start/stop the Photoprism test application
|
|
|
|
var (
|
2021-02-03 23:00:31 +01:00
|
|
|
CreateCommand = `pcreate`
|
|
|
|
DestroyCommand = `pdestroy`
|
|
|
|
LogsCommand = `plogs`
|
2021-02-11 20:25:45 +01:00
|
|
|
StartCommand = `cd ../sample-app && bash -c "./pstart"`
|
2021-02-03 23:00:31 +01:00
|
|
|
StopCommand = `pstop`
|
2021-02-03 20:00:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func (a *SampleApplication) Start() error {
|
|
|
|
logger.Info("Starting Application...")
|
2021-02-03 23:00:31 +01:00
|
|
|
script, err := NewScriptFromPath(filepath.Join(PrintWorkingDirectory(), StartCommand))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-02-03 20:00:11 +01:00
|
|
|
return script.Interpret()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *SampleApplication) Stop() error {
|
|
|
|
logger.Info("Stopping Application...")
|
2021-02-03 23:00:31 +01:00
|
|
|
script, err := NewScriptFromPath(filepath.Join(PrintWorkingDirectory(), StopCommand))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-02-03 20:00:11 +01:00
|
|
|
return script.Interpret()
|
|
|
|
}
|
|
|
|
|
2021-02-04 02:00:31 +01:00
|
|
|
func (a *SampleApplication) Create() error {
|
|
|
|
logger.Info("Create Application...")
|
|
|
|
script, err := NewScriptFromPath(filepath.Join(PrintWorkingDirectory(), CreateCommand))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return script.Interpret()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *SampleApplication) Destroy() error {
|
|
|
|
logger.Info("Destroying Application...")
|
|
|
|
script, err := NewScriptFromPath(filepath.Join(PrintWorkingDirectory(), DestroyCommand))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return script.Interpret()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *SampleApplication) Logs() error {
|
|
|
|
logger.Info("Logging Application...")
|
|
|
|
script, err := NewScriptFromPath(filepath.Join(PrintWorkingDirectory(), LogsCommand))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return script.Interpret()
|
|
|
|
}
|
|
|
|
|
2021-02-03 20:00:11 +01:00
|
|
|
func (a *SampleApplication) GetAuth() photoprism.ClientAuthenticator {
|
|
|
|
return nil
|
|
|
|
}
|
2021-02-03 23:00:31 +01:00
|
|
|
|
|
|
|
func PrintWorkingDirectory() string {
|
|
|
|
_, filename, _, ok := runtime.Caller(1)
|
|
|
|
if !ok {
|
|
|
|
logger.Info("Unable to PWD")
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
dir, err := filepath.Abs(filepath.Dir(filename))
|
|
|
|
if err != nil {
|
|
|
|
logger.Info("Unable to PWD: %v", err)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return dir
|
|
|
|
}
|