aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api/storage.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/storage.go
parent9aca9e6deb243b87cc75325be593a3b0c2f0a113 (diff)
downloadgo-tangerine-71fdaa42386173da7bfa13f1728c394aeeb4eb01.tar.gz
go-tangerine-71fdaa42386173da7bfa13f1728c394aeeb4eb01.tar.zst
go-tangerine-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/storage.go')
-rw-r--r--swarm/api/storage.go40
1 files changed, 37 insertions, 3 deletions
diff --git a/swarm/api/storage.go b/swarm/api/storage.go
index 31b484675..7e94a9653 100644
--- a/swarm/api/storage.go
+++ b/swarm/api/storage.go
@@ -16,6 +16,8 @@
package api
+import "path"
+
type Response struct {
MimeType string
Status int
@@ -25,6 +27,8 @@ type Response struct {
}
// implements a service
+//
+// DEPRECATED: Use the HTTP API instead
type Storage struct {
api *Api
}
@@ -35,8 +39,14 @@ func NewStorage(api *Api) *Storage {
// Put uploads the content to the swarm with a simple manifest speficying
// its content type
+//
+// DEPRECATED: Use the HTTP API instead
func (self *Storage) Put(content, contentType string) (string, error) {
- return self.api.Put(content, contentType)
+ key, err := self.api.Put(content, contentType)
+ if err != nil {
+ return "", err
+ }
+ return key.String(), err
}
// Get retrieves the content from bzzpath and reads the response in full
@@ -45,8 +55,18 @@ func (self *Storage) Put(content, contentType string) (string, error) {
// NOTE: if error is non-nil, sResponse may still have partial content
// the actual size of which is given in len(resp.Content), while the expected
// size is resp.Size
+//
+// DEPRECATED: Use the HTTP API instead
func (self *Storage) Get(bzzpath string) (*Response, error) {
- reader, mimeType, status, err := self.api.Get(bzzpath, true)
+ uri, err := Parse(path.Join("bzz:/", bzzpath))
+ if err != nil {
+ return nil, err
+ }
+ key, err := self.api.Resolve(uri)
+ if err != nil {
+ return nil, err
+ }
+ reader, mimeType, status, err := self.api.Get(key, uri.Path)
if err != nil {
return nil, err
}
@@ -65,6 +85,20 @@ func (self *Storage) Get(bzzpath string) (*Response, error) {
// Modify(rootHash, path, contentHash, contentType) takes th e manifest trie rooted in rootHash,
// and merge on to it. creating an entry w conentType (mime)
+//
+// DEPRECATED: Use the HTTP API instead
func (self *Storage) Modify(rootHash, path, contentHash, contentType string) (newRootHash string, err error) {
- return self.api.Modify(rootHash+"/"+path, contentHash, contentType, true)
+ uri, err := Parse("bzz:/" + rootHash)
+ if err != nil {
+ return "", err
+ }
+ key, err := self.api.Resolve(uri)
+ if err != nil {
+ return "", err
+ }
+ key, err = self.api.Modify(key, path, contentHash, contentType)
+ if err != nil {
+ return "", err
+ }
+ return key.String(), nil
}