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