Api.Upload supports default index file

This commit is contained in:
zsfelfoldi 2015-06-02 13:41:56 +02:00
parent 600e6fa584
commit bca8ec1bde
2 changed files with 13 additions and 6 deletions

View file

@ -73,7 +73,7 @@ func TestApiDirUpload(t *testing.T) {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
return return
} }
bzzhash, err := api.Upload(path.Join(testDir, "test0")) bzzhash, err := api.Upload(path.Join(testDir, "test0"), "")
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
return return
@ -101,7 +101,7 @@ func TestApiFileUpload(t *testing.T) {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
return return
} }
bzzhash, err := api.Upload(path.Join(testDir, "test0", "index.html")) bzzhash, err := api.Upload(path.Join(testDir, "test0", "index.html"), "")
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
return return

View file

@ -182,12 +182,19 @@ func (self *JSApi) download(call otto.FunctionCall) otto.Value {
} }
func (self *JSApi) upload(call otto.FunctionCall) otto.Value { func (self *JSApi) upload(call otto.FunctionCall) otto.Value {
if len(call.ArgumentList) != 1 { var err error
fmt.Println("requires 1 arguments: bzz.put(localpath)") 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() return otto.UndefinedValue()
} }
var err error
var localpath, res string var localpath, res string
localpath, err = call.Argument(0).ToString() localpath, err = call.Argument(0).ToString()
if err != nil { if err != nil {
@ -195,7 +202,7 @@ func (self *JSApi) upload(call otto.FunctionCall) otto.Value {
return otto.UndefinedValue() return otto.UndefinedValue()
} }
res, err = self.api.Upload(localpath) res, err = self.api.Upload(localpath, index)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return otto.UndefinedValue() return otto.UndefinedValue()