From bca8ec1bde1a33876b3ef175311fca1e59d1d069 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Tue, 2 Jun 2015 13:41:56 +0200 Subject: [PATCH] Api.Upload supports default index file --- bzz/api_test.go | 4 ++-- bzz/js_api.go | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bzz/api_test.go b/bzz/api_test.go index 5feb327afa..93f9b54224 100644 --- a/bzz/api_test.go +++ b/bzz/api_test.go @@ -73,7 +73,7 @@ func TestApiDirUpload(t *testing.T) { t.Errorf("unexpected error: %v", err) return } - bzzhash, err := api.Upload(path.Join(testDir, "test0")) + bzzhash, err := api.Upload(path.Join(testDir, "test0"), "") if err != nil { t.Errorf("unexpected error: %v", err) return @@ -101,7 +101,7 @@ func TestApiFileUpload(t *testing.T) { t.Errorf("unexpected error: %v", err) return } - bzzhash, err := api.Upload(path.Join(testDir, "test0", "index.html")) + bzzhash, err := api.Upload(path.Join(testDir, "test0", "index.html"), "") if err != nil { t.Errorf("unexpected error: %v", err) return diff --git a/bzz/js_api.go b/bzz/js_api.go index bd572ea40d..4bea187b06 100644 --- a/bzz/js_api.go +++ b/bzz/js_api.go @@ -182,12 +182,19 @@ func (self *JSApi) download(call otto.FunctionCall) otto.Value { } func (self *JSApi) upload(call otto.FunctionCall) otto.Value { - if len(call.ArgumentList) != 1 { - fmt.Println("requires 1 arguments: bzz.put(localpath)") + var err error + var index string + if len(call.ArgumentList) == 2 { + index, err = call.Argument(1).ToString() + if err != nil { + fmt.Println(err) + return otto.UndefinedValue() + } + } else if len(call.ArgumentList) != 1 { + fmt.Println("requires 1 or 2 arguments: bzz.put(localpath[, index])") return otto.UndefinedValue() } - var err error var localpath, res string localpath, err = call.Argument(0).ToString() if err != nil { @@ -195,7 +202,7 @@ func (self *JSApi) upload(call otto.FunctionCall) otto.Value { return otto.UndefinedValue() } - res, err = self.api.Upload(localpath) + res, err = self.api.Upload(localpath, index) if err != nil { fmt.Println(err) return otto.UndefinedValue()