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.

getp.go 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package userspace
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. "github.com/spf13/cobra"
  7. cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
  8. "gitlink.org.cn/cloudream/jcs-pub/jcsctl/cmd"
  9. )
  10. func init() {
  11. var opt getpOpt
  12. c := &cobra.Command{
  13. Use: "getp <bucket_name>/<package_name> <space_name>:<root_path>",
  14. Short: "download package all files to user space",
  15. Args: cobra.ExactArgs(2),
  16. RunE: func(c *cobra.Command, args []string) error {
  17. ctx := cmd.GetCmdCtx(c)
  18. return getp(c, ctx, opt, args)
  19. },
  20. }
  21. c.Flags().IntVarP(&opt.Concurrency, "concurrency", "c", 5, "concurrency of download files")
  22. c.Flags().BoolVar(&opt.SaveToShards, "to-shards", false, "save downloaded files to shards")
  23. UserSpaceCmd.AddCommand(c)
  24. }
  25. type getpOpt struct {
  26. Concurrency int
  27. SaveToShards bool
  28. }
  29. func getp(c *cobra.Command, ctx *cmd.CommandContext, opt getpOpt, args []string) error {
  30. comps := strings.Split(args[0], "/")
  31. if len(comps) != 2 {
  32. return fmt.Errorf("invalid package name: %s", args[0])
  33. }
  34. bucketName, packageName := comps[0], comps[1]
  35. comps = strings.Split(args[1], ":")
  36. if len(comps) != 2 {
  37. return fmt.Errorf("invalid space name and root path: %s", args[1])
  38. }
  39. spaceName, rootPath := comps[0], comps[1]
  40. getPkg, err := ctx.Client.Package().GetByFullName(cliapi.PackageGetByFullName{
  41. BucketName: bucketName,
  42. PackageName: packageName,
  43. })
  44. if err != nil {
  45. return fmt.Errorf("get package %v: %w", args[0], err)
  46. }
  47. getSpace, err := ctx.Client.UserSpace().GetByName(cliapi.UserSpaceGetByName{
  48. Name: spaceName,
  49. })
  50. if err != nil {
  51. return fmt.Errorf("get user space %v: %w", spaceName, err)
  52. }
  53. startTime := time.Now()
  54. _, err = ctx.Client.UserSpace().DownloadPackage(cliapi.UserSpaceDownloadPackage{
  55. PackageID: getPkg.Package.PackageID,
  56. UserSpaceID: getSpace.UserSpace.UserSpaceID,
  57. RootPath: rootPath,
  58. Concurrency: opt.Concurrency,
  59. SaveToShards: opt.SaveToShards,
  60. })
  61. if err != nil {
  62. return fmt.Errorf("download package %v to user space %v: %w", args[0], spaceName, err)
  63. }
  64. dt := time.Since(startTime)
  65. fmt.Printf("download package %v to user space %v success, time: %v\n", args[0], spaceName, dt)
  66. return nil
  67. }

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