Skip to content

Commit

Permalink
feat(ipfs_http): support PUT on IPFS over http
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Sep 24, 2020
1 parent eb06cdd commit b257edd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions qipfs/qipfs_http/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"strings"

logging "github.com/ipfs/go-log"
coreiface "github.com/ipfs/interface-go-ipfs-core"
Expand Down Expand Up @@ -93,8 +94,13 @@ func (fst *Filestore) Fetch(ctx context.Context, source cafs.Source, key string)
return fst.getKey(ctx, key)
}

func (fst *Filestore) Put(ctx context.Context, file qfs.File) (key string, err error) {
return "", fmt.Errorf("ipfs_http cannot put")
func (fst *Filestore) Put(ctx context.Context, file qfs.File) (string, error) {
resolvedPath, err := fst.capi.Unixfs().Add(ctx, wrapFile{file})
if err != nil {
return "", fmt.Errorf("putting file in IPFS via HTTP: %q", err)
}

return pathFromHash(resolvedPath.String()), nil
}

func (fst *Filestore) Delete(ctx context.Context, key string) error {
Expand Down Expand Up @@ -129,6 +135,9 @@ func (fst *Filestore) NewAdder(pin, wrap bool) (cafs.Adder, error) {
}

func pathFromHash(hash string) string {
if strings.HasPrefix(hash, fmt.Sprintf("/%s", FilestoreType)) {
return hash
}
return fmt.Sprintf("/%s/%s", FilestoreType, hash)
}

Expand Down

0 comments on commit b257edd

Please sign in to comment.