mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
fixes for api.upload
This commit is contained in:
parent
0139cdade4
commit
06fdf4acb3
2 changed files with 14 additions and 4 deletions
12
bzz/api.go
12
bzz/api.go
|
|
@ -91,6 +91,8 @@ func (self *Api) Download(bzzpath, localpath string) (string, error) {
|
||||||
// TODO: localpath should point to a manifest
|
// TODO: localpath should point to a manifest
|
||||||
func (self *Api) Upload(localpath, address, domain string) (string, error) {
|
func (self *Api) Upload(localpath, address, domain string) (string, error) {
|
||||||
var files []string
|
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 {
|
err := filepath.Walk(localpath, func(path string, info os.FileInfo, err error) error {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
files = append(files, path)
|
files = append(files, path)
|
||||||
|
|
@ -124,6 +126,13 @@ func (self *Api) Upload(localpath, address, domain string) (string, error) {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
buffer.WriteString(`{"entries":[`)
|
buffer.WriteString(`{"entries":[`)
|
||||||
sc := ","
|
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 {
|
for i, path := range files {
|
||||||
if errors[i] != nil {
|
if errors[i] != nil {
|
||||||
return "", errors[i]
|
return "", errors[i]
|
||||||
|
|
@ -131,7 +140,8 @@ func (self *Api) Upload(localpath, address, domain string) (string, error) {
|
||||||
if i == cnt-1 {
|
if i == cnt-1 {
|
||||||
sc = "]}"
|
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()
|
manifest := buffer.Bytes()
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ func (self *JSApi) get(call otto.FunctionCall) otto.Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSApi) put(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])")
|
fmt.Println("requires 2 or 4 arguments: bzz.put(content, content-type[, address, domain])")
|
||||||
return otto.UndefinedValue()
|
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 {
|
func (self *JSApi) upload(call otto.FunctionCall) otto.Value {
|
||||||
if len(call.ArgumentList) != 1 || len(call.ArgumentList) != 3 {
|
if len(call.ArgumentList) != 1 && len(call.ArgumentList) != 3 {
|
||||||
fmt.Println("requires 1 or 1 arguments: bzz.put(localpath[, address, domain])")
|
fmt.Println("requires 1 or 3 arguments: bzz.put(localpath[, address, domain])")
|
||||||
return otto.UndefinedValue()
|
return otto.UndefinedValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue