Skip to content

Commit

Permalink
add size field
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Apr 14, 2019
1 parent 7709565 commit 1409f9b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
11 changes: 6 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ var MainnetAddress = common.HexToAddress("0x1234") //TODO

type API interface {
// Add puts new data and temporarily pins.
Add(context.Context, io.Reader) (AddResponse, error)
Add(context.Context, io.ReadCloser) (AddResponse, error)
// Status returns the status of a CID.
Status(ctx context.Context, ci cid.Cid) (StatusResponse, error)
}

type AddResponse struct {
CID string `json:"cid"`
Expiration time.Time `json:"expiration"` // Unix timestamp.
Expiration time.Time `json:"expiration"`
Size int64 `json:"size"` // File size in bytes.
}

type StatusResponse struct {
Expiration time.Time `json:"expiration,omitempty"` // Unix timestamp.
Expiration time.Time `json:"expiration,omitempty"`
Size int64 `json:"size"` // File size in bytes.
}

func NewClient(url string) API {
Expand All @@ -45,7 +46,7 @@ type client struct {
url string
}

func (c *client) Add(ctx context.Context, r io.Reader) (AddResponse, error) {
func (c *client) Add(ctx context.Context, r io.ReadCloser) (AddResponse, error) {
req, err := http.NewRequest("PUT", c.url+"add", r)
if err != nil {
return AddResponse{}, err
Expand Down
6 changes: 5 additions & 1 deletion cmd/gofs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"text/tabwriter"
"time"

"github.com/alecthomas/units"

cid "github.com/ipfs/go-cid"

"github.com/gochain-io/gofs"
Expand Down Expand Up @@ -282,6 +284,7 @@ func Add(ctx context.Context, apiURL, path string) error {
}
fmt.Println("File uploaded and pinned.")
fmt.Println("Pinned until:", ar.Expiration)
fmt.Println("File size:", units.Base2Bytes(ar.Size))
return nil
}

Expand All @@ -297,6 +300,7 @@ func Cost(ctx context.Context, rpcURL string, contract common.Address, size, dur
}

func costStr(size uint64, dur uint64, cost *big.Int) string {
//TODO github.com/alecthomas/units
return fmt.Sprintf("%d GBs for %s: %s GO", size, time.Duration(dur)*time.Hour, web3.WeiAsBase(cost))
}

Expand Down Expand Up @@ -339,12 +343,12 @@ func Status(ctx context.Context, apiURL, ci string) error {
fmt.Println("Never been pinned.")
return nil
}
fmt.Println("File size:", units.Base2Bytes(st.Size))
if until := time.Until(st.Expiration); until > 0 {
fmt.Printf("Expires in %s at %s.\n", until, st.Expiration)
} else {
fmt.Printf("Expired %s ago at %s.\n", -until, st.Expiration)
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/gochain-io/gofs
go 1.12

require (
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf
github.com/aristanetworks/goarista v0.0.0-20190319235110-489128639c40 // indirect
github.com/gochain-io/gochain/v3 v3.1.14
github.com/gochain-io/web3 v0.0.36
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ github.com/OneOfOne/xxhash v1.2.4/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/allegro/bigcache v1.1.0/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/allegro/bigcache v1.2.0 h1:qDaE0QoF29wKBb3+pXFrJFy1ihe5OT9OiXhg1t85SxM=
Expand Down

0 comments on commit 1409f9b

Please sign in to comment.