Skip to content

Commit

Permalink
feat(login): support local passcode. close iyear#58
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Nov 23, 2022
1 parent bf8063f commit a909abc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/login/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const tdata = "tdata"

func Desktop(ctx context.Context, desktop string) error {
func Desktop(ctx context.Context, desktop, passcode string) error {
ns := viper.GetString(consts.FlagNamespace)

kvd, err := kv.New(kv.Options{
Expand All @@ -41,7 +41,7 @@ func Desktop(ctx context.Context, desktop string) error {
if filepath.Base(desktop) != tdata {
desktop = filepath.Join(desktop, tdata)
}
accounts, err := tdesktop.Read(desktop, nil)
accounts, err := tdesktop.Read(desktop, []byte(passcode))
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

var (
desktop string
desktop, passcode string
)

var Cmd = &cobra.Command{
Expand All @@ -18,12 +18,13 @@ var Cmd = &cobra.Command{
color.Yellow("WARN: If data exists in the namespace, data will be overwritten")

if desktop != "" {
return login.Desktop(cmd.Context(), desktop)
return login.Desktop(cmd.Context(), desktop, passcode)
}
return login.Code(cmd.Context())
},
}

func init() {
Cmd.Flags().StringVarP(&desktop, consts.FlagLoginDesktop, "d", "", "Official desktop client path, import session from it")
Cmd.Flags().StringVarP(&desktop, consts.FlagLoginDesktop, "d", "", "official desktop client path, import session from it")
Cmd.Flags().StringVarP(&passcode, consts.FlagLoginPasscode, "p", "", "passcode for desktop client, keep empty if no passcode")
}
27 changes: 14 additions & 13 deletions pkg/consts/flag.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package consts

const (
FlagProxy = "proxy"
FlagNamespace = "ns"
FlagDebug = "debug"
FlagPartSize = "size"
FlagThreads = "threads"
FlagLimit = "limit"
FlagNTP = "ntp"
FlagUpPath = "path"
FlagUpExcludes = "excludes"
FlagLoginDesktop = "desktop"
FlagDlUrl = "url"
FlagDlFile = "file"
FlagDlTemplate = "template"
FlagProxy = "proxy"
FlagNamespace = "ns"
FlagDebug = "debug"
FlagPartSize = "size"
FlagThreads = "threads"
FlagLimit = "limit"
FlagNTP = "ntp"
FlagUpPath = "path"
FlagUpExcludes = "excludes"
FlagLoginDesktop = "desktop"
FlagLoginPasscode = "passcode"
FlagDlUrl = "url"
FlagDlFile = "file"
FlagDlTemplate = "template"
)

0 comments on commit a909abc

Please sign in to comment.