photoprism/internal/commands/thumbnails.go

47 lines
973 B
Go
Raw Normal View History

package commands
import (
"time"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/photoprism"
2019-05-02 14:10:05 +02:00
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
// Pre-renders thumbnails
var ThumbnailsCommand = cli.Command{
Name: "thumbnails",
Usage: "Render thumbnails for all originals",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "Re-create existing thumbnails",
},
},
Action: thumbnailsAction,
}
func thumbnailsAction(ctx *cli.Context) error {
start := time.Now()
conf := config.NewConfig(ctx)
if err := conf.CreateDirectories(); err != nil {
return err
}
log.Infof("creating thumbnails in \"%s\"", conf.ThumbnailsPath())
if err := photoprism.CreateThumbnailsFromOriginals(conf.OriginalsPath(), conf.ThumbnailsPath(), ctx.Bool("force")); err != nil {
log.Error(err)
return err
}
elapsed := time.Since(start)
log.Infof("thumbnails created in %s", elapsed)
return nil
}