2018-09-24 07:53:16 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-05-13 16:01:50 +00:00
|
|
|
"time"
|
|
|
|
|
2021-09-22 17:33:41 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
2019-05-06 21:18:10 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2020-04-05 20:26:53 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/service"
|
2020-05-03 16:00:50 +00:00
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
2018-09-24 07:53:16 +00:00
|
|
|
)
|
|
|
|
|
2021-09-05 10:32:08 +00:00
|
|
|
// ResampleCommand registers the resample cli command.
|
2020-05-03 14:15:54 +00:00
|
|
|
var ResampleCommand = cli.Command{
|
2020-05-03 16:00:50 +00:00
|
|
|
Name: "resample",
|
2020-05-03 14:15:54 +00:00
|
|
|
Aliases: []string{"thumbs"},
|
2021-09-05 11:48:53 +00:00
|
|
|
Usage: "Pre-caches thumbnail images for improved performance",
|
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
|
|
|
},
|
|
|
|
},
|
2020-05-03 14:15:54 +00:00
|
|
|
Action: resampleAction,
|
2018-09-24 07:53:16 +00:00
|
|
|
}
|
|
|
|
|
2021-09-05 10:32:08 +00:00
|
|
|
// resampleAction pre-caches default thumbnails.
|
2020-05-03 14:15:54 +00:00
|
|
|
func resampleAction(ctx *cli.Context) error {
|
2019-05-14 14:04:17 +00:00
|
|
|
start := time.Now()
|
|
|
|
|
2019-05-06 21:18:10 +00:00
|
|
|
conf := config.NewConfig(ctx)
|
2020-04-05 20:26:53 +00:00
|
|
|
service.SetConfig(conf)
|
2018-09-24 07:53:16 +00:00
|
|
|
|
2020-10-08 06:52:03 +00:00
|
|
|
if err := conf.Init(); err != nil {
|
2019-01-15 13:00:42 +00:00
|
|
|
return err
|
2018-09-24 07:53:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 15:04:13 +00:00
|
|
|
log.Infof("creating thumbnails in %s", txt.Quote(conf.ThumbPath()))
|
2018-09-24 07:53:16 +00:00
|
|
|
|
2020-04-05 20:26:53 +00:00
|
|
|
rs := service.Resample()
|
2020-01-08 21:29:40 +00:00
|
|
|
|
2020-01-31 16:29:55 +00:00
|
|
|
if err := rs.Start(ctx.Bool("force")); err != nil {
|
2019-05-13 16:01:50 +00:00
|
|
|
log.Error(err)
|
|
|
|
return err
|
2018-09-24 07:53:16 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 14:04:17 +00:00
|
|
|
elapsed := time.Since(start)
|
|
|
|
|
|
|
|
log.Infof("thumbnails created in %s", elapsed)
|
2018-09-24 07:53:16 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|