swarm/api: refactor and improve HTTP API (#3773)
This PR deprecates the file related RPC calls in favour of an improved HTTP API. The main aim is to expose a simple to use API which can be consumed by thin clients (e.g. curl and HTML forms) without the need for complex logic (e.g. manipulating prefix trie manifests).
This commit is contained in:
committed by
Felix Lange
parent
9aca9e6deb
commit
71fdaa4238
@ -22,6 +22,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
@ -43,6 +44,8 @@ func NewFileSystem(api *Api) *FileSystem {
|
||||
// Upload replicates a local directory as a manifest file and uploads it
|
||||
// using dpa store
|
||||
// TODO: localpath should point to a manifest
|
||||
//
|
||||
// DEPRECATED: Use the HTTP API instead
|
||||
func (self *FileSystem) Upload(lpath, index string) (string, error) {
|
||||
var list []*manifestTrieEntry
|
||||
localpath, err := filepath.Abs(filepath.Clean(lpath))
|
||||
@ -72,9 +75,7 @@ func (self *FileSystem) Upload(lpath, index string) (string, error) {
|
||||
if path[:start] != localpath {
|
||||
return fmt.Errorf("Path prefix of '%s' does not match localpath '%s'", path, localpath)
|
||||
}
|
||||
entry := &manifestTrieEntry{
|
||||
Path: filepath.ToSlash(path),
|
||||
}
|
||||
entry := newManifestTrieEntry(&ManifestEntry{Path: filepath.ToSlash(path)}, nil)
|
||||
list = append(list, entry)
|
||||
}
|
||||
return err
|
||||
@ -91,9 +92,7 @@ func (self *FileSystem) Upload(lpath, index string) (string, error) {
|
||||
if localpath[:start] != dir {
|
||||
return "", fmt.Errorf("Path prefix of '%s' does not match dir '%s'", localpath, dir)
|
||||
}
|
||||
entry := &manifestTrieEntry{
|
||||
Path: filepath.ToSlash(localpath),
|
||||
}
|
||||
entry := newManifestTrieEntry(&ManifestEntry{Path: filepath.ToSlash(localpath)}, nil)
|
||||
list = append(list, entry)
|
||||
}
|
||||
|
||||
@ -153,11 +152,10 @@ func (self *FileSystem) Upload(lpath, index string) (string, error) {
|
||||
}
|
||||
entry.Path = RegularSlashes(entry.Path[start:])
|
||||
if entry.Path == index {
|
||||
ientry := &manifestTrieEntry{
|
||||
Path: "",
|
||||
Hash: entry.Hash,
|
||||
ientry := newManifestTrieEntry(&ManifestEntry{
|
||||
ContentType: entry.ContentType,
|
||||
}
|
||||
}, nil)
|
||||
ientry.Hash = entry.Hash
|
||||
trie.addEntry(ientry, quitC)
|
||||
}
|
||||
trie.addEntry(entry, quitC)
|
||||
@ -174,6 +172,8 @@ func (self *FileSystem) Upload(lpath, index string) (string, error) {
|
||||
|
||||
// Download replicates the manifest path structure on the local filesystem
|
||||
// under localpath
|
||||
//
|
||||
// DEPRECATED: Use the HTTP API instead
|
||||
func (self *FileSystem) Download(bzzpath, localpath string) error {
|
||||
lpath, err := filepath.Abs(filepath.Clean(localpath))
|
||||
if err != nil {
|
||||
@ -185,10 +185,15 @@ func (self *FileSystem) Download(bzzpath, localpath string) error {
|
||||
}
|
||||
|
||||
//resolving host and port
|
||||
key, _, path, err := self.api.parseAndResolve(bzzpath, true)
|
||||
uri, err := Parse(path.Join("bzz:/", bzzpath))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
key, err := self.api.Resolve(uri)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path := uri.Path
|
||||
|
||||
if len(path) > 0 {
|
||||
path += "/"
|
||||
|
Reference in New Issue
Block a user