polishing up print on restapi
License: MIT Signed-off-by: Wyatt Daviau <wdaviau@cs.stanford.edu>
This commit is contained in:
parent
9025baa12a
commit
5725e34e3d
|
@ -523,10 +523,15 @@ func (api *API) addFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
fmt.Printf("%s\n----------------\n", file.FileName())
|
||||
if file.IsDirectory() {
|
||||
continue
|
||||
}
|
||||
var n int
|
||||
for {
|
||||
n, err = file.Read(buf)
|
||||
if err == io.EOF {
|
||||
fmt.Printf("\n")
|
||||
break
|
||||
}
|
||||
fmt.Printf(string(buf[:n]))
|
||||
|
|
|
@ -9,11 +9,11 @@ import (
|
|||
"github.com/ipfs/go-ipfs-cmdkit/files"
|
||||
)
|
||||
|
||||
func parseFileArgs(paths []string) (*files.MultiFileReader, error) {
|
||||
func parseFileArgs(paths []string, recursive bool) (*files.MultiFileReader, error) {
|
||||
// logic largely drawn from go-ipfs-cmds/cli/parse.go: parseArgs
|
||||
parsedFiles := make([]files.File, len(paths), len(paths))
|
||||
for _, path := range paths {
|
||||
file, err := appendFile(path)
|
||||
file, err := appendFile(path, recursive, false) // for now no hidden support
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func parseFileArgs(paths []string) (*files.MultiFileReader, error) {
|
|||
return files.NewMultiFileReader(sliceFile, true), nil
|
||||
}
|
||||
|
||||
func appendFile(fpath string) (files.File, error) {
|
||||
func appendFile(fpath string, recursive, hidden bool) (files.File, error) {
|
||||
// logic drawn from go-ipfs-cmds/cli/parse.go: appendFile
|
||||
if fpath == "." {
|
||||
cwd, err := os.Getwd()
|
||||
|
@ -45,8 +45,10 @@ func appendFile(fpath string) (files.File, error) {
|
|||
}
|
||||
|
||||
if stat.IsDir() {
|
||||
return nil, fmt.Errorf("path: %s points to dir, adding dirs not yet supported", fpath)
|
||||
if !recursive {
|
||||
return nil, fmt.Errorf("%s is a directory, cannot add nonrecursively. Try with -r", fpath)
|
||||
}
|
||||
}
|
||||
|
||||
return files.NewSerialFile(path.Base(fpath), fpath, false, stat)
|
||||
return files.NewSerialFile(path.Base(fpath), fpath, hidden, stat)
|
||||
}
|
||||
|
|
|
@ -192,6 +192,12 @@ This is useful in the case several ipfs peers want to ingest the file and combin
|
|||
to host but no single peer's repo has the capacity for the entire file. No stdin reading yet either, that
|
||||
is also TODO
|
||||
`,
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "recursive, r",
|
||||
Usage: "add directory paths recursively, default false",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
paths := make([]string, c.NArg(), c.NArg())
|
||||
for i, path := range c.Args() {
|
||||
|
@ -199,7 +205,7 @@ is also TODO
|
|||
}
|
||||
// Unclear if multiFileR is ready for streaming, but hypothesis is yes.
|
||||
// Files are all opened but not read until they are sent.
|
||||
multiFileR, err := parseFileArgs(paths)
|
||||
multiFileR, err := parseFileArgs(paths, c.Bool("recursive"))
|
||||
checkErr("serializing all files", err)
|
||||
cerr := globalClient.AddMultiFile(multiFileR)
|
||||
if cerr != nil {
|
||||
|
|
Loading…
Reference in New Issue
Block a user