aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api/filesystem.go
diff options
context:
space:
mode:
authorLewis Marshall <lewis@lmars.net>2017-04-07 06:22:22 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-04-07 06:22:22 +0800
commit71fdaa42386173da7bfa13f1728c394aeeb4eb01 (patch)
tree364a169f650982d3b2880c95e40e2c91cb27c86e /swarm/api/filesystem.go
parent9aca9e6deb243b87cc75325be593a3b0c2f0a113 (diff)
downloaddexon-71fdaa42386173da7bfa13f1728c394aeeb4eb01.tar.gz
dexon-71fdaa42386173da7bfa13f1728c394aeeb4eb01.tar.zst
dexon-71fdaa42386173da7bfa13f1728c394aeeb4eb01.zip
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).
Diffstat (limited to 'swarm/api/filesystem.go')
-rw-r--r--swarm/api/filesystem.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/swarm/api/filesystem.go b/swarm/api/filesystem.go
index c2583e265..e7deaa32f 100644
--- a/swarm/api/filesystem.go
+++ b/swarm/api/filesystem.go
@@ -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 += "/"