mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
Api.Upload supports default index file
This commit is contained in:
parent
600e6fa584
commit
bca8ec1bde
2 changed files with 13 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue