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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 option
  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().StringVar(&opt.Prefix, "prefix", "", "download objects with this prefix")
  22. // c.Flags().StringVar(&opt.NewPrefix, "new", "", "replace prefix specified by --prefix with this prefix")
  23. // c.Flags().BoolVar(&opt.Zip, "zip", false, "download as zip file")
  24. // c.Flags().StringVarP(&opt.Output, "output", "o", "", "output zip file name")
  25. UserSpaceCmd.AddCommand(c)
  26. }
  27. type option struct {
  28. // Prefix string
  29. // NewPrefix string
  30. // Zip bool
  31. // Output string
  32. }
  33. func getp(c *cobra.Command, ctx *cmd.CommandContext, opt option, args []string) error {
  34. comps := strings.Split(args[0], "/")
  35. if len(comps) != 2 {
  36. return fmt.Errorf("invalid package name: %s", args[0])
  37. }
  38. bucketName, packageName := comps[0], comps[1]
  39. comps = strings.Split(args[1], ":")
  40. if len(comps) != 2 {
  41. return fmt.Errorf("invalid space name and root path: %s", args[1])
  42. }
  43. spaceName, rootPath := comps[0], comps[1]
  44. getPkg, err := ctx.Client.Package().GetByFullName(cliapi.PackageGetByFullName{
  45. BucketName: bucketName,
  46. PackageName: packageName,
  47. })
  48. if err != nil {
  49. return fmt.Errorf("get package %v: %w", args[0], err)
  50. }
  51. getSpace, err := ctx.Client.UserSpace().GetByName(cliapi.UserSpaceGetByName{
  52. Name: spaceName,
  53. })
  54. if err != nil {
  55. return fmt.Errorf("get user space %v: %w", spaceName, err)
  56. }
  57. startTime := time.Now()
  58. _, err = ctx.Client.UserSpace().DownloadPackage(cliapi.UserSpaceDownloadPackageReq{
  59. PackageID: getPkg.Package.PackageID,
  60. UserSpaceID: getSpace.UserSpace.UserSpaceID,
  61. RootPath: rootPath,
  62. })
  63. if err != nil {
  64. return fmt.Errorf("download package %v to user space %v: %w", args[0], spaceName, err)
  65. }
  66. dt := time.Since(startTime)
  67. fmt.Printf("download package %v to user space %v success, time: %v\n", args[0], spaceName, dt)
  68. return nil
  69. }

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