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.

newloadp.go 2.4 kB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package repl
  2. /*
  3. import (
  4. "fmt"
  5. "os"
  6. "path/filepath"
  7. "strconv"
  8. "strings"
  9. "github.com/jedib0t/go-pretty/v6/table"
  10. "github.com/spf13/cobra"
  11. cdssdk "gitlink.org.cn/cloudream/jcs-pub/client/types"
  12. )
  13. func init() {
  14. cmd := &cobra.Command{
  15. Use: "newloadp localPath bucketID packageName userSpaceID...",
  16. Short: "Create a new package then upload an load files to it at the same time",
  17. Args: cobra.MinimumNArgs(4),
  18. Run: func(cmd *cobra.Command, args []string) {
  19. cmdCtx := GetCmdCtx(cmd)
  20. localPath := args[0]
  21. bktID, err := strconv.ParseInt(args[1], 10, 64)
  22. if err != nil {
  23. fmt.Println(err)
  24. return
  25. }
  26. packageName := args[2]
  27. spaceIDs := make([]cdssdk.UserSpaceID, 0)
  28. rootPathes := make([]string, 0)
  29. for _, dst := range args[3:] {
  30. comps := strings.Split(dst, ":")
  31. if len(comps) != 2 {
  32. fmt.Println("invalid storage destination: ", dst)
  33. return
  34. }
  35. sID, err := strconv.ParseInt(comps[0], 10, 64)
  36. if err != nil {
  37. fmt.Println(err)
  38. return
  39. }
  40. spaceIDs = append(spaceIDs, cdssdk.UserSpaceID(sID))
  41. rootPathes = append(rootPathes, comps[1])
  42. }
  43. newloadp(cmdCtx, localPath, cdssdk.BucketID(bktID), packageName, spaceIDs, rootPathes)
  44. },
  45. }
  46. RootCmd.AddCommand(cmd)
  47. }
  48. func newloadp(cmdCtx *CommandContext, path string, bucketID cdssdk.BucketID, packageName string, spaceIDs []cdssdk.UserSpaceID, rootPathes []string) {
  49. up, err := cmdCtx.Cmdline.Svc.Uploader.BeginCreateLoad(bucketID, packageName, spaceIDs, rootPathes)
  50. if err != nil {
  51. fmt.Println(err)
  52. return
  53. }
  54. defer up.Abort()
  55. var fileCount int
  56. var totalSize int64
  57. err = filepath.WalkDir(path, func(fname string, fi os.DirEntry, err error) error {
  58. if err != nil {
  59. return nil
  60. }
  61. if fi.IsDir() {
  62. return nil
  63. }
  64. fileCount++
  65. info, err := fi.Info()
  66. if err != nil {
  67. return err
  68. }
  69. totalSize += info.Size()
  70. file, err := os.Open(fname)
  71. if err != nil {
  72. return err
  73. }
  74. defer file.Close()
  75. return up.Upload(fname, info.Size(), file)
  76. })
  77. if err != nil {
  78. fmt.Println(err.Error())
  79. return
  80. }
  81. ret, err := up.Commit()
  82. if err != nil {
  83. fmt.Printf("committing package: %v\n", err)
  84. return
  85. }
  86. wr := table.NewWriter()
  87. wr.AppendHeader(table.Row{"ID", "Name", "FileCount", "TotalSize"})
  88. wr.AppendRow(table.Row{ret.Package.PackageID, ret.Package.Name, fileCount, totalSize})
  89. fmt.Println(wr.Render())
  90. }
  91. */

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