| @@ -186,9 +186,6 @@ func (svc *UserSpaceService) Test(req cliapi.UserSpaceTest) (*cliapi.UserSpaceTe | |||||
| } | } | ||||
| func (svc *UserSpaceService) DownloadPackage(packageID clitypes.PackageID, userspaceID clitypes.UserSpaceID, rootPath string) error { | func (svc *UserSpaceService) DownloadPackage(packageID clitypes.PackageID, userspaceID clitypes.UserSpaceID, rootPath string) error { | ||||
| coorCli := stgglb.CoordinatorRPCPool.Get() | |||||
| defer coorCli.Release() | |||||
| destStg := svc.UserSpaceMeta.Get(userspaceID) | destStg := svc.UserSpaceMeta.Get(userspaceID) | ||||
| if destStg == nil { | if destStg == nil { | ||||
| return fmt.Errorf("userspace not found: %d", userspaceID) | return fmt.Errorf("userspace not found: %d", userspaceID) | ||||
| @@ -169,7 +169,7 @@ func Test_Storage(t *testing.T) { | |||||
| }) | }) | ||||
| So(err, ShouldBeNil) | So(err, ShouldBeNil) | ||||
| _, err = cli.UserSpaceDownloadPackage(UserSpaceDownloadPackageReq{ | |||||
| _, err = cli.UserSpace().DownloadPackage(UserSpaceDownloadPackageReq{ | |||||
| PackageID: createResp.Package.PackageID, | PackageID: createResp.Package.PackageID, | ||||
| UserSpaceID: 1, | UserSpaceID: 1, | ||||
| }) | }) | ||||
| @@ -8,6 +8,14 @@ import ( | |||||
| cortypes "gitlink.org.cn/cloudream/jcs-pub/coordinator/types" | cortypes "gitlink.org.cn/cloudream/jcs-pub/coordinator/types" | ||||
| ) | ) | ||||
| type UserSpaceService struct { | |||||
| *Client | |||||
| } | |||||
| func (c *Client) UserSpace() *UserSpaceService { | |||||
| return &UserSpaceService{c} | |||||
| } | |||||
| const UserSpaceDownloadPackagePath = "/userSpace/downloadPackage" | const UserSpaceDownloadPackagePath = "/userSpace/downloadPackage" | ||||
| type UserSpaceDownloadPackageReq struct { | type UserSpaceDownloadPackageReq struct { | ||||
| @@ -26,7 +34,7 @@ func (r *UserSpaceDownloadPackageResp) ParseResponse(resp *http.Response) error | |||||
| return sdks.ParseCodeDataJSONResponse(resp, r) | return sdks.ParseCodeDataJSONResponse(resp, r) | ||||
| } | } | ||||
| func (c *Client) UserSpaceDownloadPackage(req UserSpaceDownloadPackageReq) (*UserSpaceDownloadPackageResp, error) { | |||||
| func (c *UserSpaceService) DownloadPackage(req UserSpaceDownloadPackageReq) (*UserSpaceDownloadPackageResp, error) { | |||||
| return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceDownloadPackageResp{}) | return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceDownloadPackageResp{}) | ||||
| } | } | ||||
| @@ -52,7 +60,7 @@ func (r *UserSpaceCreatePackageResp) ParseResponse(resp *http.Response) error { | |||||
| return sdks.ParseCodeDataJSONResponse(resp, r) | return sdks.ParseCodeDataJSONResponse(resp, r) | ||||
| } | } | ||||
| func (c *Client) UserSpaceCreatePackage(req UserSpaceCreatePackageReq) (*UserSpaceCreatePackageResp, error) { | |||||
| func (c *UserSpaceService) CreatePackage(req UserSpaceCreatePackageReq) (*UserSpaceCreatePackageResp, error) { | |||||
| return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceCreatePackageResp{}) | return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceCreatePackageResp{}) | ||||
| } | } | ||||
| @@ -74,11 +82,11 @@ func (r *UserSpaceGetResp) ParseResponse(resp *http.Response) error { | |||||
| return sdks.ParseCodeDataJSONResponse(resp, r) | return sdks.ParseCodeDataJSONResponse(resp, r) | ||||
| } | } | ||||
| func (c *Client) UserSpaceGet(req UserSpaceGet) (*UserSpaceGetResp, error) { | |||||
| func (c *UserSpaceService) Get(req UserSpaceGet) (*UserSpaceGetResp, error) { | |||||
| return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceGetResp{}) | return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceGetResp{}) | ||||
| } | } | ||||
| const UserSpaceGetByNamePath = "/userspace/getByName" | |||||
| const UserSpaceGetByNamePath = "/userSpace/getByName" | |||||
| type UserSpaceGetByName struct { | type UserSpaceGetByName struct { | ||||
| Name string `form:"name" url:"name" binding:"required"` | Name string `form:"name" url:"name" binding:"required"` | ||||
| @@ -89,18 +97,18 @@ func (r *UserSpaceGetByName) MakeParam() *sdks.RequestParam { | |||||
| } | } | ||||
| type UserSpaceGetByNameResp struct { | type UserSpaceGetByNameResp struct { | ||||
| clitypes.UserSpace | |||||
| UserSpace clitypes.UserSpace `json:"userSpace"` | |||||
| } | } | ||||
| func (r *UserSpaceGetByNameResp) ParseResponse(resp *http.Response) error { | func (r *UserSpaceGetByNameResp) ParseResponse(resp *http.Response) error { | ||||
| return sdks.ParseCodeDataJSONResponse(resp, r) | return sdks.ParseCodeDataJSONResponse(resp, r) | ||||
| } | } | ||||
| func (c *Client) UserSpaceGetByName(req UserSpaceGetByName) (*UserSpaceGetByNameResp, error) { | |||||
| func (c *UserSpaceService) GetByName(req UserSpaceGetByName) (*UserSpaceGetByNameResp, error) { | |||||
| return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceGetByNameResp{}) | return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceGetByNameResp{}) | ||||
| } | } | ||||
| const UserSpaceGetAllPath = "/userspace/getAll" | |||||
| const UserSpaceGetAllPath = "/userSpace/getAll" | |||||
| type UserSpaceGetAll struct{} | type UserSpaceGetAll struct{} | ||||
| @@ -116,7 +124,7 @@ func (r *UserSpaceGetAllResp) ParseResponse(resp *http.Response) error { | |||||
| return sdks.ParseCodeDataJSONResponse(resp, r) | return sdks.ParseCodeDataJSONResponse(resp, r) | ||||
| } | } | ||||
| func (c *Client) UserSpaceGetAll() (*UserSpaceGetAllResp, error) { | |||||
| func (c *UserSpaceService) GetAll() (*UserSpaceGetAllResp, error) { | |||||
| req := UserSpaceGetAll{} | req := UserSpaceGetAll{} | ||||
| return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceGetAllResp{}) | return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceGetAllResp{}) | ||||
| } | } | ||||
| @@ -145,7 +153,7 @@ func (r *UserSpaceCreateResp) ParseResponse(resp *http.Response) error { | |||||
| return sdks.ParseCodeDataJSONResponse(resp, r) | return sdks.ParseCodeDataJSONResponse(resp, r) | ||||
| } | } | ||||
| func (c *Client) UserSpaceCreate(req UserSpaceCreate) (*UserSpaceCreateResp, error) { | |||||
| func (c *UserSpaceService) Create(req UserSpaceCreate) (*UserSpaceCreateResp, error) { | |||||
| return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceCreateResp{}) | return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceCreateResp{}) | ||||
| } | } | ||||
| @@ -164,14 +172,14 @@ func (r *UserSpaceUpdate) MakeParam() *sdks.RequestParam { | |||||
| } | } | ||||
| type UserSpaceUpdateResp struct { | type UserSpaceUpdateResp struct { | ||||
| clitypes.UserSpace | |||||
| UserSpace clitypes.UserSpace `json:"userSpace"` | |||||
| } | } | ||||
| func (r *UserSpaceUpdateResp) ParseResponse(resp *http.Response) error { | func (r *UserSpaceUpdateResp) ParseResponse(resp *http.Response) error { | ||||
| return sdks.ParseCodeDataJSONResponse(resp, r) | return sdks.ParseCodeDataJSONResponse(resp, r) | ||||
| } | } | ||||
| func (c *Client) UserSpaceUpdate(req UserSpaceUpdate) (*UserSpaceUpdateResp, error) { | |||||
| func (c *UserSpaceService) Update(req UserSpaceUpdate) (*UserSpaceUpdateResp, error) { | |||||
| return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceUpdateResp{}) | return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceUpdateResp{}) | ||||
| } | } | ||||
| @@ -192,7 +200,7 @@ func (r *UserSpaceDeleteResp) ParseResponse(resp *http.Response) error { | |||||
| return sdks.ParseCodeDataJSONResponse(resp, r) | return sdks.ParseCodeDataJSONResponse(resp, r) | ||||
| } | } | ||||
| func (c *Client) UserSpaceDelete(req UserSpaceDelete) (*UserSpaceDeleteResp, error) { | |||||
| func (c *UserSpaceService) Delete(req UserSpaceDelete) (*UserSpaceDeleteResp, error) { | |||||
| return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceDeleteResp{}) | return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceDeleteResp{}) | ||||
| } | } | ||||
| @@ -217,6 +225,6 @@ func (r *UserSpaceTestResp) ParseResponse(resp *http.Response) error { | |||||
| return sdks.ParseCodeDataJSONResponse(resp, r) | return sdks.ParseCodeDataJSONResponse(resp, r) | ||||
| } | } | ||||
| func (c *Client) UserSpaceTest(req UserSpaceTest) (*UserSpaceTestResp, error) { | |||||
| func (c *UserSpaceService) Test(req UserSpaceTest) (*UserSpaceTestResp, error) { | |||||
| return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceTestResp{}) | return JSONAPI(&c.cfg, c.httpCli, &req, &UserSpaceTestResp{}) | ||||
| } | } | ||||
| @@ -79,7 +79,7 @@ func create(c *cobra.Command, ctx *cmd.CommandContext) { | |||||
| return | return | ||||
| } | } | ||||
| _, err = ctx.Client.UserSpaceCreate(userSpace.UserSpaceCreate) | |||||
| _, err = ctx.Client.UserSpace().Create(userSpace.UserSpaceCreate) | |||||
| if err != nil { | if err != nil { | ||||
| fmt.Printf("\033[31m保存配置失败: %v\033[0m", err) | fmt.Printf("\033[31m保存配置失败: %v\033[0m", err) | ||||
| return | return | ||||
| @@ -60,7 +60,7 @@ func delete(c *cobra.Command, ctx *cmd.CommandContext) { | |||||
| return | return | ||||
| } | } | ||||
| resp, err := ctx.Client.UserSpaceGet(cliapi.UserSpaceGet{ | |||||
| resp, err := ctx.Client.UserSpace().Get(cliapi.UserSpaceGet{ | |||||
| UserSpaceID: clitypes.UserSpaceID(id), | UserSpaceID: clitypes.UserSpaceID(id), | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -78,7 +78,7 @@ func delete(c *cobra.Command, ctx *cmd.CommandContext) { | |||||
| } | } | ||||
| name := strings.TrimSpace(nameInput) | name := strings.TrimSpace(nameInput) | ||||
| resp, err := ctx.Client.UserSpaceGetByName(cliapi.UserSpaceGetByName{ | |||||
| resp, err := ctx.Client.UserSpace().GetByName(cliapi.UserSpaceGetByName{ | |||||
| Name: name, | Name: name, | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -100,7 +100,7 @@ func delete(c *cobra.Command, ctx *cmd.CommandContext) { | |||||
| return | return | ||||
| } | } | ||||
| _, err = ctx.Client.UserSpaceDelete(cliapi.UserSpaceDelete{ | |||||
| _, err = ctx.Client.UserSpace().Delete(cliapi.UserSpaceDelete{ | |||||
| UserSpaceID: userSpace.UserSpaceID, | UserSpaceID: userSpace.UserSpaceID, | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -0,0 +1,83 @@ | |||||
| package userspace | |||||
| import ( | |||||
| "fmt" | |||||
| "strings" | |||||
| "time" | |||||
| "github.com/spf13/cobra" | |||||
| cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1" | |||||
| "gitlink.org.cn/cloudream/jcs-pub/jcsctl/cmd" | |||||
| ) | |||||
| func init() { | |||||
| var opt option | |||||
| c := &cobra.Command{ | |||||
| Use: "getp <bucket_name>/<package_name> <space_name>:<root_path>", | |||||
| Short: "download package all files to user space", | |||||
| Args: cobra.ExactArgs(2), | |||||
| RunE: func(c *cobra.Command, args []string) error { | |||||
| ctx := cmd.GetCmdCtx(c) | |||||
| return getp(c, ctx, opt, args) | |||||
| }, | |||||
| } | |||||
| // c.Flags().StringVar(&opt.Prefix, "prefix", "", "download objects with this prefix") | |||||
| // c.Flags().StringVar(&opt.NewPrefix, "new", "", "replace prefix specified by --prefix with this prefix") | |||||
| // c.Flags().BoolVar(&opt.Zip, "zip", false, "download as zip file") | |||||
| // c.Flags().StringVarP(&opt.Output, "output", "o", "", "output zip file name") | |||||
| UserSpaceCmd.AddCommand(c) | |||||
| } | |||||
| type option struct { | |||||
| // Prefix string | |||||
| // NewPrefix string | |||||
| // Zip bool | |||||
| // Output string | |||||
| } | |||||
| func getp(c *cobra.Command, ctx *cmd.CommandContext, opt option, args []string) error { | |||||
| comps := strings.Split(args[0], "/") | |||||
| if len(comps) != 2 { | |||||
| return fmt.Errorf("invalid package name: %s", args[0]) | |||||
| } | |||||
| bucketName, packageName := comps[0], comps[1] | |||||
| comps = strings.Split(args[1], ":") | |||||
| if len(comps) != 2 { | |||||
| return fmt.Errorf("invalid space name and root path: %s", args[1]) | |||||
| } | |||||
| spaceName, rootPath := comps[0], comps[1] | |||||
| getPkg, err := ctx.Client.Package().GetByFullName(cliapi.PackageGetByFullName{ | |||||
| BucketName: bucketName, | |||||
| PackageName: packageName, | |||||
| }) | |||||
| if err != nil { | |||||
| return fmt.Errorf("get package %v: %w", args[0], err) | |||||
| } | |||||
| getSpace, err := ctx.Client.UserSpace().GetByName(cliapi.UserSpaceGetByName{ | |||||
| Name: spaceName, | |||||
| }) | |||||
| if err != nil { | |||||
| return fmt.Errorf("get user space %v: %w", spaceName, err) | |||||
| } | |||||
| startTime := time.Now() | |||||
| _, err = ctx.Client.UserSpace().DownloadPackage(cliapi.UserSpaceDownloadPackageReq{ | |||||
| PackageID: getPkg.Package.PackageID, | |||||
| UserSpaceID: getSpace.UserSpace.UserSpaceID, | |||||
| RootPath: rootPath, | |||||
| }) | |||||
| if err != nil { | |||||
| return fmt.Errorf("download package %v to user space %v: %w", args[0], spaceName, err) | |||||
| } | |||||
| dt := time.Since(startTime) | |||||
| fmt.Printf("download package %v to user space %v success, time: %v\n", args[0], spaceName, dt) | |||||
| return nil | |||||
| } | |||||
| @@ -35,7 +35,7 @@ type lsOpt struct { | |||||
| func ls(c *cobra.Command, ctx *cmd.CommandContext, opt lsOpt, args []string) error { | func ls(c *cobra.Command, ctx *cmd.CommandContext, opt lsOpt, args []string) error { | ||||
| // 仅ls无参数 | // 仅ls无参数 | ||||
| if len(args) == 0 { | if len(args) == 0 { | ||||
| resp, err := ctx.Client.UserSpaceGetAll() | |||||
| resp, err := ctx.Client.UserSpace().GetAll() | |||||
| if err != nil { | if err != nil { | ||||
| return err | return err | ||||
| } | } | ||||
| @@ -58,7 +58,7 @@ func ls(c *cobra.Command, ctx *cmd.CommandContext, opt lsOpt, args []string) err | |||||
| return fmt.Errorf("ID必须是数字") | return fmt.Errorf("ID必须是数字") | ||||
| } | } | ||||
| result, err := ctx.Client.UserSpaceGet(cliapi.UserSpaceGet{ | |||||
| result, err := ctx.Client.UserSpace().Get(cliapi.UserSpaceGet{ | |||||
| UserSpaceID: clitypes.UserSpaceID(id), | UserSpaceID: clitypes.UserSpaceID(id), | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -67,7 +67,7 @@ func ls(c *cobra.Command, ctx *cmd.CommandContext, opt lsOpt, args []string) err | |||||
| userSpace = &result.UserSpace | userSpace = &result.UserSpace | ||||
| } else { | } else { | ||||
| result, err := ctx.Client.UserSpaceGetByName(cliapi.UserSpaceGetByName{ | |||||
| result, err := ctx.Client.UserSpace().GetByName(cliapi.UserSpaceGetByName{ | |||||
| Name: searchKey, | Name: searchKey, | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -7,7 +7,6 @@ import ( | |||||
| "github.com/chzyer/readline" | "github.com/chzyer/readline" | ||||
| "github.com/spf13/cobra" | "github.com/spf13/cobra" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1" | |||||
| cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1" | cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1" | ||||
| clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types" | clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types" | ||||
| cortypes "gitlink.org.cn/cloudream/jcs-pub/coordinator/types" | cortypes "gitlink.org.cn/cloudream/jcs-pub/coordinator/types" | ||||
| @@ -15,7 +14,7 @@ import ( | |||||
| ) | ) | ||||
| type UserSpaceUpdate struct { | type UserSpaceUpdate struct { | ||||
| api.UserSpaceUpdate | |||||
| cliapi.UserSpaceUpdate | |||||
| } | } | ||||
| func init() { | func init() { | ||||
| @@ -50,7 +49,7 @@ func update(c *cobra.Command, ctx *cmd.CommandContext) { | |||||
| return | return | ||||
| } | } | ||||
| resp, err := ctx.Client.UserSpaceGet(cliapi.UserSpaceGet{ | |||||
| resp, err := ctx.Client.UserSpace().Get(cliapi.UserSpaceGet{ | |||||
| UserSpaceID: clitypes.UserSpaceID(id), | UserSpaceID: clitypes.UserSpaceID(id), | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -87,7 +86,7 @@ func update(c *cobra.Command, ctx *cmd.CommandContext) { | |||||
| return | return | ||||
| } | } | ||||
| _, err = ctx.Client.UserSpaceUpdate(userSpaceUpdate.UserSpaceUpdate) | |||||
| _, err = ctx.Client.UserSpace().Update(userSpaceUpdate.UserSpaceUpdate) | |||||
| if err != nil { | if err != nil { | ||||
| fmt.Printf("\033[31m更新配置失败: %v\033[0m", err) | fmt.Printf("\033[31m更新配置失败: %v\033[0m", err) | ||||
| return | return | ||||