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.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. UserSpaceCmd.AddCommand(c)
  23. }
  24. type getpOpt struct {
  25. Concurrency int
  26. }
  27. func getp(c *cobra.Command, ctx *cmd.CommandContext, opt getpOpt, args []string) error {
  28. comps := strings.Split(args[0], "/")
  29. if len(comps) != 2 {
  30. return fmt.Errorf("invalid package name: %s", args[0])
  31. }
  32. bucketName, packageName := comps[0], comps[1]
  33. comps = strings.Split(args[1], ":")
  34. if len(comps) != 2 {
  35. return fmt.Errorf("invalid space name and root path: %s", args[1])
  36. }
  37. spaceName, rootPath := comps[0], comps[1]
  38. getPkg, err := ctx.Client.Package().GetByFullName(cliapi.PackageGetByFullName{
  39. BucketName: bucketName,
  40. PackageName: packageName,
  41. })
  42. if err != nil {
  43. return fmt.Errorf("get package %v: %w", args[0], err)
  44. }
  45. getSpace, err := ctx.Client.UserSpace().GetByName(cliapi.UserSpaceGetByName{
  46. Name: spaceName,
  47. })
  48. if err != nil {
  49. return fmt.Errorf("get user space %v: %w", spaceName, err)
  50. }
  51. startTime := time.Now()
  52. _, err = ctx.Client.UserSpace().DownloadPackage(cliapi.UserSpaceDownloadPackage{
  53. PackageID: getPkg.Package.PackageID,
  54. UserSpaceID: getSpace.UserSpace.UserSpaceID,
  55. RootPath: rootPath,
  56. Concurrency: opt.Concurrency,
  57. })
  58. if err != nil {
  59. return fmt.Errorf("download package %v to user space %v: %w", args[0], spaceName, err)
  60. }
  61. dt := time.Since(startTime)
  62. fmt.Printf("download package %v to user space %v success, time: %v\n", args[0], spaceName, dt)
  63. return nil
  64. }

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