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"
|
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/get"
|
2020-05-30 01:41:47 +02:00
|
|
|
)
|
|
|
|
|
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()
|
|
|
|
|
2022-10-04 12:27:40 +02:00
|
|
|
conf, err := InitConfig(ctx)
|
2020-05-30 01:41:47 +02:00
|
|
|
|
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
|
|
|
|
2022-10-04 12:27:40 +02:00
|
|
|
if 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() {
|
2023-02-09 13:14:56 +01:00
|
|
|
log.Infof("config: enabled read-only mode")
|
2020-05-30 01:41:47 +02:00
|
|
|
}
|
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
w := get.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
|
|
|
|
}
|