2018-09-24 09:53:16 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-05-13 18:01:50 +02:00
|
|
|
"time"
|
|
|
|
|
2021-09-22 19:33:41 +02:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2020-04-05 22:26:53 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/service"
|
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
|
|
|
},
|
|
|
|
},
|
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()
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
conf := config.NewConfig(ctx)
|
2020-04-05 22:26:53 +02:00
|
|
|
service.SetConfig(conf)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-10-08 08:52:03 +02:00
|
|
|
if err := conf.Init(); err != nil {
|
2019-01-15 14:00:42 +01:00
|
|
|
return err
|
2018-09-24 09:53:16 +02:00
|
|
|
}
|
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
log.Infof("creating thumbnails in %s", clean.Log(conf.ThumbPath()))
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-04-05 22:26:53 +02:00
|
|
|
rs := service.Resample()
|
2020-01-08 22:29:40 +01:00
|
|
|
|
2020-01-31 17:29:55 +01:00
|
|
|
if err := rs.Start(ctx.Bool("force")); err != nil {
|
2019-05-13 18:01:50 +02:00
|
|
|
log.Error(err)
|
|
|
|
return err
|
2018-09-24 09:53:16 +02:00
|
|
|
}
|
|
|
|
|
2021-10-02 15:34:41 +02:00
|
|
|
log.Infof("thumbnails created in %s", time.Since(start))
|
2018-09-24 09:53:16 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|