package api import ( "io" "net/http" "gitlink.org.cn/cloudream/common/sdks" jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" ) type PubShardsService struct { *Client } func (c *Client) PubShards() *PubShardsService { return &PubShardsService{ Client: c, } } const PubShardsCreatePath = "/pubShards/create" type PubShardsCreate struct { Name string `json:"name"` Storage jcstypes.StorageType `json:"storage"` Credential jcstypes.StorageCredential `json:"credential"` ShardStore jcstypes.ShardStoreUserConfig `json:"shardStore"` Features []jcstypes.StorageFeature `json:"features"` WorkingDir string `json:"workingDir"` Password string `json:"password"` MasterHub jcstypes.HubID `json:"masterHub"` } func (r *PubShardsCreate) MakeParam() *sdks.RequestParam { return sdks.MakeJSONParam(http.MethodPost, PubShardsCreatePath, r) } type PubShardsCreateResp struct { PubShards jcstypes.PubShards `json:"pubShards"` } func (r *PubShardsCreateResp) ParseResponse(resp *http.Response) error { return sdks.ParseCodeDataJSONResponse(resp, r) } func (c *PubShardsService) Create(req PubShardsCreate) (*PubShardsCreateResp, error) { return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsCreateResp{}) } const PubShardsJoinPath = "/pubShards/join" type PubShardsJoin struct { Name string `json:"name"` PubShardsID jcstypes.PubShardsID `json:"pubShardID"` Password string `json:"password"` } func (r *PubShardsJoin) MakeParam() *sdks.RequestParam { return sdks.MakeJSONParam(http.MethodPost, PubShardsJoinPath, r) } type PubShardsJoinResp struct { PubShards jcstypes.PubShards `json:"pubShards"` UserSpace jcstypes.UserSpace `json:"userSpace"` } func (r *PubShardsJoinResp) ParseResponse(resp *http.Response) error { return sdks.ParseCodeDataJSONResponse(resp, r) } func (c *PubShardsService) Join(req PubShardsJoin) (*PubShardsJoinResp, error) { return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsJoinResp{}) } const PubShardsListPath = "/pubShards/list" type PubShardsList struct{} func (r *PubShardsList) MakeParam() *sdks.RequestParam { return sdks.MakeQueryParam(http.MethodGet, PubShardsListPath, r) } type PubShardsListResp struct { PubShards []jcstypes.PubShards `json:"pubShards"` UserSpaces []jcstypes.UserSpace `json:"userSpaces"` } func (r *PubShardsListResp) ParseResponse(resp *http.Response) error { return sdks.ParseCodeDataJSONResponse(resp, r) } func (c *PubShardsService) List(req PubShardsList) (*PubShardsListResp, error) { return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsListResp{}) } const PubShardsGetPath = "/pubShards/get" type PubShardsGet struct { Name string `form:"name" url:"name"` } func (r *PubShardsGet) MakeParam() *sdks.RequestParam { return sdks.MakeQueryParam(http.MethodGet, PubShardsGetPath, r) } type PubShardsGetResp struct { PubShards jcstypes.PubShards `json:"pubShards"` UserSpace jcstypes.UserSpace `json:"userSpace"` } func (r *PubShardsGetResp) ParseResponse(resp *http.Response) error { return sdks.ParseCodeDataJSONResponse(resp, r) } func (c *PubShardsService) Get(req PubShardsGet) (*PubShardsGetResp, error) { return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsGetResp{}) } const PubShardsExportPackagePath = "/pubShards/exportPackage" type PubShardsExportPackage struct { PackageID jcstypes.PackageID `form:"packageID" url:"packageID" binding:"required"` AvailablePubShards []jcstypes.PubShardsID `form:"availablePubShards" url:"availablePubShards"` } func (r *PubShardsExportPackage) MakeParam() *sdks.RequestParam { return sdks.MakeQueryParam(http.MethodGet, PubShardsExportPackagePath, r) } type PubShardsExportPackageResp struct { FileName string PackFile io.ReadCloser } func (r *PubShardsExportPackageResp) ParseResponse(resp *http.Response) error { fileName, file, err := sdks.ParseFileResponse(resp) if err != nil { return err } r.FileName = fileName r.PackFile = file return nil } func (c *PubShardsService) ExportPackage(req PubShardsExportPackage) (*PubShardsExportPackageResp, error) { return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsExportPackageResp{}) } const PubShardsImportPackagePath = "/pubShards/importPackage" type PubShardsImportPackage struct { PackageID jcstypes.PackageID `json:"packageID"` PackFile io.ReadCloser `json:"-"` } func (r *PubShardsImportPackage) MakeParam() *sdks.RequestParam { return sdks.MakeMultipartParam(http.MethodPost, PubShardsImportPackagePath, r, r.PackFile) } type PubShardsImportPackageResp struct { InvalidObjects []jcstypes.Object `json:"invalidObjects"` } func (r *PubShardsImportPackageResp) ParseResponse(resp *http.Response) error { return sdks.ParseCodeDataJSONResponse(resp, r) } func (c *PubShardsService) ImportPackage(req PubShardsImportPackage) (*PubShardsImportPackageResp, error) { return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsImportPackageResp{}) }