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.

pub_shards.go 5.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package api
  2. import (
  3. "io"
  4. "net/http"
  5. "gitlink.org.cn/cloudream/common/sdks"
  6. jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
  7. )
  8. type PubShardsService struct {
  9. *Client
  10. }
  11. func (c *Client) PubShards() *PubShardsService {
  12. return &PubShardsService{
  13. Client: c,
  14. }
  15. }
  16. const PubShardsCreatePath = "/pubShards/create"
  17. type PubShardsCreate struct {
  18. Name string `json:"name"`
  19. Storage jcstypes.StorageType `json:"storage"`
  20. Credential jcstypes.StorageCredential `json:"credential"`
  21. ShardStore jcstypes.ShardStoreUserConfig `json:"shardStore"`
  22. Features []jcstypes.StorageFeature `json:"features"`
  23. WorkingDir string `json:"workingDir"`
  24. Password string `json:"password"`
  25. MasterHub jcstypes.HubID `json:"masterHub"`
  26. }
  27. func (r *PubShardsCreate) MakeParam() *sdks.RequestParam {
  28. return sdks.MakeJSONParam(http.MethodPost, PubShardsCreatePath, r)
  29. }
  30. type PubShardsCreateResp struct {
  31. PubShards jcstypes.PubShards `json:"pubShards"`
  32. }
  33. func (r *PubShardsCreateResp) ParseResponse(resp *http.Response) error {
  34. return sdks.ParseCodeDataJSONResponse(resp, r)
  35. }
  36. func (c *PubShardsService) Create(req PubShardsCreate) (*PubShardsCreateResp, error) {
  37. return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsCreateResp{})
  38. }
  39. const PubShardsJoinPath = "/pubShards/join"
  40. type PubShardsJoin struct {
  41. Name string `json:"name"`
  42. PubShardsID jcstypes.PubShardsID `json:"pubShardID"`
  43. Password string `json:"password"`
  44. }
  45. func (r *PubShardsJoin) MakeParam() *sdks.RequestParam {
  46. return sdks.MakeJSONParam(http.MethodPost, PubShardsJoinPath, r)
  47. }
  48. type PubShardsJoinResp struct {
  49. PubShards jcstypes.PubShards `json:"pubShards"`
  50. UserSpace jcstypes.UserSpace `json:"userSpace"`
  51. }
  52. func (r *PubShardsJoinResp) ParseResponse(resp *http.Response) error {
  53. return sdks.ParseCodeDataJSONResponse(resp, r)
  54. }
  55. func (c *PubShardsService) Join(req PubShardsJoin) (*PubShardsJoinResp, error) {
  56. return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsJoinResp{})
  57. }
  58. const PubShardsListPath = "/pubShards/list"
  59. type PubShardsList struct{}
  60. func (r *PubShardsList) MakeParam() *sdks.RequestParam {
  61. return sdks.MakeQueryParam(http.MethodGet, PubShardsListPath, r)
  62. }
  63. type PubShardsListResp struct {
  64. PubShards []jcstypes.PubShards `json:"pubShards"`
  65. UserSpaces []jcstypes.UserSpace `json:"userSpaces"`
  66. }
  67. func (r *PubShardsListResp) ParseResponse(resp *http.Response) error {
  68. return sdks.ParseCodeDataJSONResponse(resp, r)
  69. }
  70. func (c *PubShardsService) List(req PubShardsList) (*PubShardsListResp, error) {
  71. return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsListResp{})
  72. }
  73. const PubShardsGetPath = "/pubShards/get"
  74. type PubShardsGet struct {
  75. Name string `form:"name" url:"name"`
  76. }
  77. func (r *PubShardsGet) MakeParam() *sdks.RequestParam {
  78. return sdks.MakeQueryParam(http.MethodGet, PubShardsGetPath, r)
  79. }
  80. type PubShardsGetResp struct {
  81. PubShards jcstypes.PubShards `json:"pubShards"`
  82. UserSpace jcstypes.UserSpace `json:"userSpace"`
  83. }
  84. func (r *PubShardsGetResp) ParseResponse(resp *http.Response) error {
  85. return sdks.ParseCodeDataJSONResponse(resp, r)
  86. }
  87. func (c *PubShardsService) Get(req PubShardsGet) (*PubShardsGetResp, error) {
  88. return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsGetResp{})
  89. }
  90. const PubShardsExportPackagePath = "/pubShards/exportPackage"
  91. type PubShardsExportPackage struct {
  92. PackageID jcstypes.PackageID `form:"packageID" url:"packageID" binding:"required"`
  93. AvailablePubShards []jcstypes.PubShardsID `form:"availablePubShards" url:"availablePubShards"`
  94. }
  95. func (r *PubShardsExportPackage) MakeParam() *sdks.RequestParam {
  96. return sdks.MakeQueryParam(http.MethodGet, PubShardsExportPackagePath, r)
  97. }
  98. type PubShardsExportPackageResp struct {
  99. FileName string
  100. PackFile io.ReadCloser
  101. }
  102. func (r *PubShardsExportPackageResp) ParseResponse(resp *http.Response) error {
  103. fileName, file, err := sdks.ParseFileResponse(resp)
  104. if err != nil {
  105. return err
  106. }
  107. r.FileName = fileName
  108. r.PackFile = file
  109. return nil
  110. }
  111. func (c *PubShardsService) ExportPackage(req PubShardsExportPackage) (*PubShardsExportPackageResp, error) {
  112. return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsExportPackageResp{})
  113. }
  114. const PubShardsImportPackagePath = "/pubShards/importPackage"
  115. type PubShardsImportPackage struct {
  116. PackageID jcstypes.PackageID `json:"packageID"`
  117. PackFile io.ReadCloser `json:"-"`
  118. }
  119. func (r *PubShardsImportPackage) MakeParam() *sdks.RequestParam {
  120. return sdks.MakeMultipartParam(http.MethodPost, PubShardsImportPackagePath, r, r.PackFile)
  121. }
  122. type PubShardsImportPackageResp struct {
  123. InvalidObjects []jcstypes.Object `json:"invalidObjects"`
  124. }
  125. func (r *PubShardsImportPackageResp) ParseResponse(resp *http.Response) error {
  126. return sdks.ParseCodeDataJSONResponse(resp, r)
  127. }
  128. func (c *PubShardsService) ImportPackage(req PubShardsImportPackage) (*PubShardsImportPackageResp, error) {
  129. return JSONAPI(&c.cfg, c.httpCli, &req, &PubShardsImportPackageResp{})
  130. }

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