2023-03-24 19:35:29 +01:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ConnectCommand configures the command name, flags, and action.
|
|
|
|
var ConnectCommand = cli.Command{
|
|
|
|
Name: "connect",
|
|
|
|
Usage: "Connects your membership account",
|
|
|
|
ArgsUsage: "[activation code]",
|
|
|
|
Action: connectAction,
|
|
|
|
}
|
|
|
|
|
|
|
|
// connectAction connects your membership account.
|
|
|
|
func connectAction(ctx *cli.Context) error {
|
|
|
|
return CallWithDependencies(ctx, func(conf *config.Config) error {
|
|
|
|
token := ctx.Args().First()
|
|
|
|
|
|
|
|
// Fail if no code was provided.
|
|
|
|
if token == "" {
|
|
|
|
return cli.ShowSubcommandHelp(ctx)
|
|
|
|
}
|
|
|
|
|
2023-10-13 12:43:20 +02:00
|
|
|
// Renew API keys with token.
|
|
|
|
if err := conf.RenewApiKeysWithToken(token); err != nil {
|
2023-03-24 19:35:29 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infof("successfully connected your account")
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|