|
| 1 | +package upload |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "errors" |
| 6 | + "strings" |
| 7 | + |
| 8 | + "github.com/simulot/immich-go/adapters/folder" |
| 9 | + "github.com/simulot/immich-go/app" |
| 10 | + "github.com/simulot/immich-go/internal/filenames" |
| 11 | + "github.com/simulot/immich-go/internal/fshelper" |
| 12 | + "github.com/spf13/cobra" |
| 13 | +) |
| 14 | + |
| 15 | +func NewFromPicasaCommand(ctx context.Context, parent *cobra.Command, app *app.Application, upOptions *UploadOptions) *cobra.Command { |
| 16 | + cmd := &cobra.Command{ |
| 17 | + Use: "from-picasa [flags] <path>...", |
| 18 | + Short: "Upload photos from a Picasa folder or zip file", |
| 19 | + Args: cobra.MinimumNArgs(1), |
| 20 | + } |
| 21 | + cmd.SetContext(ctx) |
| 22 | + options := &folder.ImportFolderOptions{} |
| 23 | + options.AddFromPicasaFlags(cmd, parent) |
| 24 | + |
| 25 | + cmd.RunE = func(cmd *cobra.Command, args []string) error { //nolint:contextcheck |
| 26 | + // ready to run |
| 27 | + ctx := cmd.Context() |
| 28 | + log := app.Log() |
| 29 | + client := app.Client() |
| 30 | + options.TZ = app.GetTZ() |
| 31 | + |
| 32 | + // parse arguments |
| 33 | + fsyss, err := fshelper.ParsePath(args) |
| 34 | + if err != nil { |
| 35 | + return err |
| 36 | + } |
| 37 | + if len(fsyss) == 0 { |
| 38 | + log.Message("No file found matching the pattern: %s", strings.Join(args, ",")) |
| 39 | + return errors.New("No file found matching the pattern: " + strings.Join(args, ",")) |
| 40 | + } |
| 41 | + |
| 42 | + // create the adapter for folders |
| 43 | + options.SupportedMedia = client.Immich.SupportedMedia() |
| 44 | + upOptions.Filters = append(upOptions.Filters, options.ManageBurst.GroupFilter(), options.ManageRawJPG.GroupFilter(), options.ManageHEICJPG.GroupFilter()) |
| 45 | + |
| 46 | + options.InfoCollector = filenames.NewInfoCollector(app.GetTZ(), options.SupportedMedia) |
| 47 | + adapter, err := folder.NewLocalFiles(ctx, app.Jnl(), options, fsyss...) |
| 48 | + if err != nil { |
| 49 | + return err |
| 50 | + } |
| 51 | + |
| 52 | + return newUpload(UpModeFolder, app, upOptions).run(ctx, adapter, app, fsyss) |
| 53 | + } |
| 54 | + |
| 55 | + return cmd |
| 56 | +} |
0 commit comments