diff --git a/bzz/api.go b/bzz/api.go index 30c8e9e715..9deeba05f6 100644 --- a/bzz/api.go +++ b/bzz/api.go @@ -91,6 +91,8 @@ func (self *Api) Download(bzzpath, localpath string) (string, error) { // TODO: localpath should point to a manifest func (self *Api) Upload(localpath, address, domain string) (string, error) { var files []string + localpath = common.ExpandHomePath(localpath) + dpaLogger.Debugf("uploading '%s'", localpath) err := filepath.Walk(localpath, func(path string, info os.FileInfo, err error) error { if err == nil { files = append(files, path) @@ -124,6 +126,13 @@ func (self *Api) Upload(localpath, address, domain string) (string, error) { var buffer bytes.Buffer buffer.WriteString(`{"entries":[`) sc := "," + var pathPrefix *regexp.Regexp + var relativePath string + pathPrefix, err = regexp.Compile("^" + localpath + fmt.Sprintf("%s", os.PathSeparator)) + if err != nil { + return "", err + } + for i, path := range files { if errors[i] != nil { return "", errors[i] @@ -131,7 +140,8 @@ func (self *Api) Upload(localpath, address, domain string) (string, error) { if i == cnt-1 { sc = "]}" } - buffer.WriteString(fmt.Sprintf(`{"hash":"%064x","path":"%s","contentType":"text/plain"}%s`, hashes[i], path, sc)) + relativePath = pathPrefix.ReplaceAllString(path, "") + buffer.WriteString(fmt.Sprintf(`{"hash":"%064x","path":"%s","contentType":"text/plain"}%s`, hashes[i], relativePath, sc)) } manifest := buffer.Bytes() diff --git a/bzz/js_api.go b/bzz/js_api.go index 7406501ffc..5a53913227 100644 --- a/bzz/js_api.go +++ b/bzz/js_api.go @@ -54,7 +54,7 @@ func (self *JSApi) get(call otto.FunctionCall) otto.Value { } func (self *JSApi) put(call otto.FunctionCall) otto.Value { - if len(call.ArgumentList) != 2 || len(call.ArgumentList) != 4 { + if len(call.ArgumentList) != 2 && len(call.ArgumentList) != 4 { fmt.Println("requires 2 or 4 arguments: bzz.put(content, content-type[, address, domain])") return otto.UndefinedValue() } @@ -124,8 +124,8 @@ func (self *JSApi) download(call otto.FunctionCall) otto.Value { } func (self *JSApi) upload(call otto.FunctionCall) otto.Value { - if len(call.ArgumentList) != 1 || len(call.ArgumentList) != 3 { - fmt.Println("requires 1 or 1 arguments: bzz.put(localpath[, address, domain])") + if len(call.ArgumentList) != 1 && len(call.ArgumentList) != 3 { + fmt.Println("requires 1 or 3 arguments: bzz.put(localpath[, address, domain])") return otto.UndefinedValue() }