2020-05-30 01:41:47 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2021-09-22 19:33:41 +02:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
2020-05-30 01:41:47 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
|
|
|
"github.com/photoprism/photoprism/internal/service"
|
|
|
|
)
|
|
|
|
|
2021-10-06 08:31:35 +02:00
|
|
|
// MomentsCommand registers the moments command.
|
2020-05-30 01:41:47 +02:00
|
|
|
var MomentsCommand = cli.Command{
|
|
|
|
Name: "moments",
|
2021-10-05 22:33:29 +02:00
|
|
|
Usage: "Creates albums of special moments, trips, and places",
|
2020-05-30 01:41:47 +02:00
|
|
|
Action: momentsAction,
|
|
|
|
}
|
|
|
|
|
2021-10-06 08:31:35 +02:00
|
|
|
// momentsAction creates albums of special moments, trips, and places.
|
2020-05-30 01:41:47 +02:00
|
|
|
func momentsAction(ctx *cli.Context) error {
|
|
|
|
start := time.Now()
|
|
|
|
|
|
|
|
conf := config.NewConfig(ctx)
|
|
|
|
service.SetConfig(conf)
|
|
|
|
|
2020-10-08 08:52:03 +02:00
|
|
|
_, cancel := context.WithCancel(context.Background())
|
2020-05-30 01:41:47 +02:00
|
|
|
defer cancel()
|
2020-10-08 08:52:03 +02:00
|
|
|
|
|
|
|
if err := conf.Init(); err != nil {
|
2020-05-30 01:41:47 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
conf.InitDb()
|
2022-09-28 09:01:17 +02:00
|
|
|
defer conf.Shutdown()
|
2020-05-30 01:41:47 +02:00
|
|
|
|
|
|
|
if conf.ReadOnly() {
|
2021-11-18 03:02:10 +01:00
|
|
|
log.Infof("config: read-only mode enabled")
|
2020-05-30 01:41:47 +02:00
|
|
|
}
|
|
|
|
|
2021-08-13 20:04:59 +02:00
|
|
|
w := service.Moments()
|
2020-05-30 01:41:47 +02:00
|
|
|
|
2021-08-13 20:04:59 +02:00
|
|
|
if err := w.Start(); err != nil {
|
2020-05-30 01:41:47 +02:00
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
elapsed := time.Since(start)
|
|
|
|
|
2021-10-02 15:34:41 +02:00
|
|
|
log.Infof("completed in %s", elapsed)
|
2020-05-30 01:41:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|