2018-09-24 09:53:16 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-05-13 18:01:50 +02:00
|
|
|
"time"
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2018-09-24 09:53:16 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/photoprism"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2020-02-18 23:42:51 +01:00
|
|
|
// ThumbsCommand is used to register the thumbs cli command
|
2020-01-31 17:29:55 +01:00
|
|
|
var ThumbsCommand = cli.Command{
|
|
|
|
Name: "thumbs",
|
2020-01-22 12:19:43 +01:00
|
|
|
Usage: "Pre-renders thumbnails to boost performance",
|
2018-09-24 09:53:16 +02:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
2019-05-13 18:01:50 +02:00
|
|
|
Name: "force, f",
|
2020-01-22 10:35:00 +01:00
|
|
|
Usage: "re-create existing thumbnails",
|
2018-09-24 09:53:16 +02:00
|
|
|
},
|
|
|
|
},
|
2020-01-31 17:29:55 +01:00
|
|
|
Action: thumbsAction,
|
2018-09-24 09:53:16 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 23:42:51 +01:00
|
|
|
// thumbsAction pre-render the thumbnails
|
2020-01-31 17:29:55 +01:00
|
|
|
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)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
if err := conf.CreateDirectories(); err != nil {
|
2019-01-15 14:00:42 +01:00
|
|
|
return err
|
2018-09-24 09:53:16 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 16:04:17 +02:00
|
|
|
log.Infof("creating thumbnails in \"%s\"", conf.ThumbnailsPath())
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-01-31 17:29:55 +01:00
|
|
|
rs := photoprism.NewResample(conf)
|
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
|
|
|
}
|
|
|
|
|
2019-05-14 16:04:17 +02:00
|
|
|
elapsed := time.Since(start)
|
|
|
|
|
|
|
|
log.Infof("thumbnails created in %s", elapsed)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|