Skip to content

Commit

Permalink
Merge pull request #432 from bittorrent/fix/from-empty
Browse files Browse the repository at this point in the history
fix: judge if from option is empty
  • Loading branch information
Shawn-Huang-Tron authored May 28, 2024
2 parents 764e3b0 + 6043244 commit 53c8d0c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/commands/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/base64"
"errors"
"io"
"strings"

shell "github.com/bittorrent/go-btfs-api"
cmds "github.com/bittorrent/go-btfs-cmds"
Expand Down Expand Up @@ -128,18 +129,24 @@ var decryptCmd = &cmds.Command{
var readClose io.ReadCloser
cid := r.Arguments[0]
from, ok := r.Options[fromOption].(string)
if ok {
if ok && strings.TrimSpace(from) != "" {
peerID, err := peer.Decode(from)
if err != nil {
return err
}
b, err := remote.P2PCallStrings(r.Context, n, api, peerID, "/decryption", cid)
if err != nil && strings.Contains(err.Error(), "unsupported path namespace") {
return errors.New("cid not found")
}
if err != nil {
return err
}
readClose = io.NopCloser(bytes.NewReader(b))
} else {
readClose, err = shell.NewLocalShell().Cat(cid)
if err != nil && strings.Contains(err.Error(), "unsupported path namespace") {
return errors.New("cid not found")
}
if err != nil {
return err
}
Expand Down

0 comments on commit 53c8d0c

Please sign in to comment.