Skip to content

Commit

Permalink
feat: Add open command to gateways
Browse files Browse the repository at this point in the history
Added open command under gateways which accepts a CID and opens a signed
url in the browser
  • Loading branch information
stevedylandev committed Oct 11, 2024
1 parent 16a8ed8 commit 25b3619
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"path/filepath"
"strings"
"time"

"github.com/skratchdot/open-golang/open"
)

func findGatewayDomain() ([]byte, error) {
Expand Down Expand Up @@ -156,3 +158,15 @@ func GetSignedURL(cid string, expires int) (GetSignedURLResponse, error) {

return response, nil
}

func OpenCID(cid string) error {
data, err := GetSignedURL(cid, 30)
if err != nil {
fmt.Errorf("Problem creating URL %d", err)
}
err = open.Run(data.Data)
if err != nil {
fmt.Errorf("Problem opening URL %d", err)
}
return nil
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sahilm/fuzzy v0.1.1 // indirect
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=
github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/schollz/progressbar/v3 v3.13.1 h1:o8rySDYiQ59Mwzy2FELeHY5ZARXZTVJC7iHD6PEFUiE=
github.com/schollz/progressbar/v3 v3.13.1/go.mod h1:xvrbki8kfT1fzWzBT/UZd9L6GA+jdL7HAgq2RFnO6fQ=
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA=
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,20 @@ func main() {
return err
},
},
{
Name: "open",
Aliases: []string{"o"},
Usage: "Open a file in the browser",
ArgsUsage: "[CID of the file]",
Action: func(ctx *cli.Context) error {
cid := ctx.Args().First()
if cid == "" {
return errors.New("No CID provided")
}
err := OpenCID(cid)
return err
},
},
{
Name: "sign",
Aliases: []string{"s"},
Expand Down

0 comments on commit 25b3619

Please sign in to comment.