diff --git a/internal/view/buck_obj.go b/internal/view/buck_obj.go index fea0315..8a0fa11 100644 --- a/internal/view/buck_obj.go +++ b/internal/view/buck_obj.go @@ -13,35 +13,46 @@ import ( "github.com/rs/zerolog/log" ) -type BObj struct { +type S3FileViewer struct { + name, path string ResourceViewer } -func NewS3FileViewer(resource string) ResourceViewer { - var obj BObj - obj.ResourceViewer = NewBrowser(resource) +func NewS3FileViewer(path, resource string) *S3FileViewer { + var obj S3FileViewer + obj.name = resource + obj.path = path + if obj.path == "s3://" { + obj.path = obj.path + obj.name + } + obj.ResourceViewer = NewBrowser("OBJ") obj.AddBindKeysFn(obj.bindKeys) //s3.GetTable().SetEnterFn(s3.describeInstace) return &obj } -func (obj *BObj) bindKeys(aa ui.KeyActions) { + +func (obj *S3FileViewer) Name() string { + return obj.name +} + +func (obj *S3FileViewer) bindKeys(aa ui.KeyActions) { aa.Add(ui.KeyActions{ ui.KeyShiftN: ui.NewKeyAction("Sort Name", obj.GetTable().SortColCmd("Name", true), true), ui.KeyShiftM: ui.NewKeyAction("Sort Modification-Time", obj.GetTable().SortColCmd("Last-Modified", true), true), ui.KeyShiftS: ui.NewKeyAction("Sort Size", obj.GetTable().SortColCmd("Size", true), true), ui.KeyShiftC: ui.NewKeyAction("Sort Storage-Class", obj.GetTable().SortColCmd("Storage-Class", true), true), - tcell.KeyEscape: ui.NewKeyAction("Back", obj.App().PrevCmd, true), - tcell.KeyEnter: ui.NewKeyAction("View", obj.enterCmd, true), + tcell.KeyEscape: ui.NewKeyAction("Back", obj.App().PrevCmd, false), + tcell.KeyEnter: ui.NewKeyAction("View", obj.enterCmd, false), tcell.KeyCtrlD: ui.NewKeyAction("Download Object", obj.downloadCmd, true), tcell.KeyCtrlP: ui.NewKeyAction("Pre-Signed URL", obj.preSignedUrlCmd, true), }) } -func (obj *BObj) enterCmd(evt *tcell.EventKey) *tcell.EventKey { +func (obj *S3FileViewer) enterCmd(evt *tcell.EventKey) *tcell.EventKey { objName := obj.GetTable().GetSelectedItem() fileType := obj.GetTable().GetSecondColumn() if fileType == "Folder" { - o := NewS3FileViewer("OBJ") + o := NewS3FileViewer(obj.path+"/"+objName, objName) ctx := obj.App().GetContext() bn := ctx.Value(internal.BucketName) fn := fmt.Sprintf("%v%v/", ctx.Value(internal.FolderName), objName) @@ -54,12 +65,13 @@ func (obj *BObj) enterCmd(evt *tcell.EventKey) *tcell.EventKey { obj.App().Flash().Info(fmt.Sprintf("Bucket Name: %v", bn)) // println(bName) obj.App().inject(o) + o.GetTable().SetTitle(o.path) } - return nil + return evt } -func (obj *BObj) downloadCmd(evt *tcell.EventKey) *tcell.EventKey { +func (obj *S3FileViewer) downloadCmd(evt *tcell.EventKey) *tcell.EventKey { objName := obj.GetTable().GetSelectedItem() fileType := obj.GetTable().GetSecondColumn() @@ -73,7 +85,7 @@ func (obj *BObj) downloadCmd(evt *tcell.EventKey) *tcell.EventKey { return nil } -func (obj *BObj) preSignedUrlCmd(evt *tcell.EventKey) *tcell.EventKey { +func (obj *S3FileViewer) preSignedUrlCmd(evt *tcell.EventKey) *tcell.EventKey { objNmae := obj.GetTable().GetSelectedItem() fileType := obj.GetTable().GetSecondColumn() diff --git a/internal/view/s3.go b/internal/view/s3.go index 7f6155c..232292b 100644 --- a/internal/view/s3.go +++ b/internal/view/s3.go @@ -46,13 +46,14 @@ func (s3 *S3) describeBucket(evt *tcell.EventKey) *tcell.EventKey { func (s3 *S3) enterCmd(evt *tcell.EventKey) *tcell.EventKey { bName := s3.GetTable().GetSelectedItem() if bName != "" { - o := NewS3FileViewer("OBJ") + o := NewS3FileViewer("s3://", bName) ctx := context.WithValue(s3.App().GetContext(), internal.BucketName, bName) s3.App().SetContext(ctx) ctx = context.WithValue(s3.App().GetContext(), internal.FolderName, "") s3.App().SetContext(ctx) s3.App().Flash().Info("Bucket Name: " + bName) s3.App().inject(o) + o.GetTable().SetTitle(o.path) } return nil