Skip to content

Commit

Permalink
set path with entry
Browse files Browse the repository at this point in the history
  • Loading branch information
treethought committed Sep 9, 2021
1 parent 595fb7e commit f485db3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ipfs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ func (c *Client) ListFiles(path string) (entries []*api.MfsLsEntry, err error) {
return entries, nil
}

func (c *Client) StatEntry(entry *api.MfsLsEntry) (string, error) {
func (c *Client) StatFile(path string, entry *api.MfsLsEntry) (string, error) {

f, err := c.sh.FilesStat(context.Background(), fmt.Sprintf("/%s", entry.Name))
f, err := c.sh.FilesStat(context.Background(), path)
if err != nil {
return "", err
}
Expand Down
27 changes: 18 additions & 9 deletions ui/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,31 @@ type RepoTree struct {
inputHandler *cbind.Configuration
}

type TreeEntry struct {
entry *api.MfsLsEntry
path string
}

func (r *RepoTree) buildNodes(basePath string, entries ...*api.MfsLsEntry) []*cview.TreeNode {
nodes := []*cview.TreeNode{}
for _, i := range entries {
fmt.Println(i.Name)
node := cview.NewTreeNode(i.Name)
node.SetReference(i)
ref := TreeEntry{
entry: i,
path: filepath.Join(basePath, i.Name),
}
node.SetReference(ref)

if i.Type == api.TDirectory {

path := filepath.Join(basePath, i.Name)
children, err := r.app.client.ListFiles(path)
children, err := r.app.client.ListFiles(ref.path)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

childrenNodes := r.buildNodes(path, children...)
childrenNodes := r.buildNodes(ref.path, children...)
node.SetChildren(childrenNodes)
node.SetExpanded(false)
}
Expand Down Expand Up @@ -76,14 +84,15 @@ func NewRepoTree(app *App) *RepoTree {

return m
}

func (r *RepoTree) handleOpen(ev *tcell.EventKey) *tcell.EventKey {
ref := r.GetCurrentNode().GetReference()
entry, ok := ref.(*api.MfsLsEntry)
e, ok := ref.(TreeEntry)
if !ok {
return nil
}

url := fmt.Sprintf("ipfs://%s", entry.Hash)
url := fmt.Sprintf("ipfs://%s", e.entry.Hash)
openbrowser(url)
return nil

Expand All @@ -92,7 +101,7 @@ func (r *RepoTree) handleOpen(ev *tcell.EventKey) *tcell.EventKey {
func (r *RepoTree) handleSelect(ev *tcell.EventKey) *tcell.EventKey {
node := r.GetCurrentNode()
ref := node.GetReference()
entry, ok := ref.(*api.MfsLsEntry)
e, ok := ref.(TreeEntry)
if !ok {
return nil
}
Expand All @@ -101,8 +110,8 @@ func (r *RepoTree) handleSelect(ev *tcell.EventKey) *tcell.EventKey {
node.SetExpanded(true)
}

r.app.info.SetItem(entry)
r.app.dag.SetItem(entry)
r.app.info.SetItem(e.path, e.entry)
r.app.dag.SetItem(e.entry)
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions ui/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ func NewFileInfo(app *App) *FileInfo {
return m
}

func (i *FileInfo) SetItem(entry *api.MfsLsEntry) {
func (i *FileInfo) SetItem(path string, entry *api.MfsLsEntry) {
info := fmt.Sprintf("%+v", entry)

stat, err := i.app.client.StatEntry(entry)
stat, err := i.app.client.StatFile(path, entry)
if err != nil {
i.SetText(fmt.Sprintf("%s\n%v", path, err))
return
}
info = fmt.Sprintf("%s\n%s", entry.Name, stat)
Expand Down

0 comments on commit f485db3

Please sign in to comment.