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