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-08-12 04:54:20 +02:00
|
|
|
// MomentsCommand registers the moments cli command.
|
2020-05-30 01:41:47 +02:00
|
|
|
var MomentsCommand = cli.Command{
|
|
|
|
Name: "moments",
|
2021-08-15 14:14:27 +02:00
|
|
|
Usage: "Creates albums based on popular locations, dates, and labels",
|
2020-05-30 01:41:47 +02:00
|
|
|
Action: momentsAction,
|
|
|
|
}
|
|
|
|
|
|
|
|
// momentsAction creates albums based on popular locations, dates and labels.
|
|
|
|
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()
|
|
|
|
|
|
|
|
if conf.ReadOnly() {
|
2021-01-24 17:46:18 +01:00
|
|
|
log.Infof("moments: 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
|
|
|
}
|
|
|
|
|
|
|
|
conf.Shutdown()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|