2018-09-24 09:53:16 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-05-14 16:04:17 +02:00
|
|
|
"time"
|
|
|
|
|
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"
|
2018-09-24 09:53:16 +02:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2020-02-18 23:42:51 +01:00
|
|
|
// ConvertCommand is used to register the convert cli command
|
2018-09-24 09:53:16 +02:00
|
|
|
var ConvertCommand = cli.Command{
|
|
|
|
Name: "convert",
|
2020-01-22 10:35:00 +01:00
|
|
|
Usage: "Converts originals in other formats to JPEG",
|
2018-09-24 09:53:16 +02:00
|
|
|
Action: convertAction,
|
|
|
|
}
|
|
|
|
|
2020-02-18 23:42:51 +01:00
|
|
|
// convertAction converts RAW files to JPEG images, if no JPEG already exists
|
2018-11-17 06:21:39 +01:00
|
|
|
func convertAction(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)
|
2019-06-30 05:38:39 +02:00
|
|
|
|
2020-06-07 14:33:07 +02:00
|
|
|
if !conf.SidecarWritable() {
|
2019-07-02 22:03:23 +02:00
|
|
|
return config.ErrReadOnly
|
|
|
|
}
|
|
|
|
|
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-06 23:18:10 +02:00
|
|
|
log.Infof("converting RAW images in %s to JPEG", conf.OriginalsPath())
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-04-05 22:26:53 +02:00
|
|
|
convert := service.Convert()
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2020-04-05 22:26:53 +02:00
|
|
|
if err := convert.Start(conf.OriginalsPath()); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2019-05-14 16:04:17 +02:00
|
|
|
elapsed := time.Since(start)
|
|
|
|
|
|
|
|
log.Infof("image conversion completed in %s", elapsed)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|