You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ls_object.go 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package ls
  2. import (
  3. "fmt"
  4. "github.com/jedib0t/go-pretty/v6/table"
  5. cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
  6. jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
  7. "gitlink.org.cn/cloudream/jcs-pub/jcsctl/cmd"
  8. )
  9. func lsObject(ctx *cmd.CommandContext, opt option, bktName string, pkgName string, objPath string) error {
  10. var pkgID jcstypes.PackageID
  11. if opt.PackageID != 0 {
  12. pkgID = jcstypes.PackageID(opt.PackageID)
  13. } else {
  14. resp, err := ctx.Client.Package().GetByFullName(cliapi.PackageGetByFullName{
  15. BucketName: bktName,
  16. PackageName: pkgName,
  17. })
  18. if err != nil {
  19. return fmt.Errorf("get package %v: %w", pkgName, err)
  20. }
  21. pkgID = resp.Package.PackageID
  22. }
  23. var objs []jcstypes.Object
  24. var commonPrefixes []string
  25. req := cliapi.ObjectListByPath{
  26. PackageID: pkgID,
  27. Path: objPath,
  28. IsPrefix: true,
  29. }
  30. if !opt.Recursive {
  31. req.NoRecursive = true
  32. }
  33. var nextConToken string
  34. for {
  35. req.ContinuationToken = nextConToken
  36. resp, err := ctx.Client.Object().ListByPath(req)
  37. if err != nil {
  38. return fmt.Errorf("list objects: %w", err)
  39. }
  40. objs = append(objs, resp.Objects...)
  41. commonPrefixes = append(commonPrefixes, resp.CommonPrefixes...)
  42. if !resp.IsTruncated {
  43. break
  44. }
  45. nextConToken = resp.NextContinuationToken
  46. }
  47. if opt.Long {
  48. fmt.Printf("total %d objects, %d common prefixes in package %v\n", len(objs), len(commonPrefixes), pkgName)
  49. }
  50. if len(commonPrefixes) > 0 {
  51. for _, prefix := range commonPrefixes {
  52. fmt.Printf("%s\n", prefix)
  53. }
  54. fmt.Printf("\n")
  55. }
  56. if len(objs) > 0 {
  57. if opt.Long {
  58. tb := table.NewWriter()
  59. tb.AppendHeader(table.Row{"ID", "Path", "Size", "Hash", "Redundancy", "Create Time", "Update Time"})
  60. for _, obj := range objs {
  61. tb.AppendRow(table.Row{
  62. obj.ObjectID,
  63. obj.Path,
  64. obj.Size,
  65. obj.FileHash,
  66. obj.Redundancy.GetRedundancyType(),
  67. obj.CreateTime,
  68. obj.UpdateTime,
  69. })
  70. }
  71. fmt.Println(tb.Render())
  72. } else {
  73. for _, obj := range objs {
  74. fmt.Printf("%s\n", obj.Path)
  75. }
  76. }
  77. }
  78. return nil
  79. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。