2018-09-24 07:53:16 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2022-10-04 10:27:40 +00:00
|
|
|
"context"
|
2019-05-13 16:01:50 +00:00
|
|
|
"time"
|
|
|
|
|
2021-09-22 17:33:41 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
2020-04-05 20:26:53 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/service"
|
2022-04-15 07:42:07 +00:00
|
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
2018-09-24 07:53:16 +00:00
|
|
|
)
|
|
|
|
|
2021-10-05 20:33:29 +00:00
|
|
|
// ThumbsCommand registers the resample cli command.
|
|
|
|
var ThumbsCommand = cli.Command{
|
2021-10-05 21:13:06 +00:00
|
|
|
Name: "thumbs",
|
2021-11-18 02:02:10 +00:00
|
|
|
Usage: "Generates thumbnails using the current settings",
|
2018-09-24 07:53:16 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
2019-05-13 16:01:50 +00:00
|
|
|
Name: "force, f",
|
2021-09-05 10:32:08 +00:00
|
|
|
Usage: "replace existing thumbnails",
|
2018-09-24 07:53:16 +00:00
|
|
|
},
|
2022-08-31 16:53:04 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "originals, o",
|
|
|
|
Usage: "originals only, skip sidecar files",
|
|
|
|
},
|
2018-09-24 07:53:16 +00:00
|
|
|
},
|
2021-10-05 20:33:29 +00:00
|
|
|
Action: thumbsAction,
|
2018-09-24 07:53:16 +00:00
|
|
|
}
|
|
|
|
|
2021-10-05 20:33:29 +00:00
|
|
|
// thumbsAction pre-renders thumbnail images.
|
|
|
|
func thumbsAction(ctx *cli.Context) error {
|
2019-05-14 14:04:17 +00:00
|
|
|
start := time.Now()
|
|
|
|
|
2022-10-04 10:27:40 +00:00
|
|
|
conf, err := InitConfig(ctx)
|
2018-09-24 07:53:16 +00:00
|
|
|
|
2022-10-04 10:27:40 +00:00
|
|
|
_, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
if err != nil {
|
2019-01-15 13:00:42 +00:00
|
|
|
return err
|
2018-09-24 07:53:16 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 07:01:17 +00:00
|
|
|
conf.RegisterDb()
|
|
|
|
defer conf.Shutdown()
|
|
|
|
|
2022-08-31 16:53:04 +00:00
|
|
|
log.Infof("creating thumbs in %s", clean.Log(conf.ThumbCachePath()))
|
2018-09-24 07:53:16 +00:00
|
|
|
|
2022-08-31 16:53:04 +00:00
|
|
|
rs := service.Thumbs()
|
2020-01-08 21:29:40 +00:00
|
|
|
|
2022-08-31 16:53:04 +00:00
|
|
|
if err := rs.Start(ctx.Bool("force"), ctx.Bool("originals")); err != nil {
|
2019-05-13 16:01:50 +00:00
|
|
|
log.Error(err)
|
|
|
|
return err
|
2018-09-24 07:53:16 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 16:53:04 +00:00
|
|
|
log.Infof("thumbs created in %s", time.Since(start))
|
2018-09-24 07:53:16 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|