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.

presigned.go 5.0 kB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package api
  2. import (
  3. "net/http"
  4. clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types"
  5. )
  6. type PresignedService struct {
  7. *Client
  8. }
  9. func (c *Client) Presigned() *PresignedService {
  10. return &PresignedService{
  11. Client: c,
  12. }
  13. }
  14. const PresignedObjectListByPathPath = "/presigned/object/listByPath"
  15. type PresignedObjectListByPath struct {
  16. ObjectListByPath
  17. }
  18. func (c *PresignedService) ObjectListByPath(req PresignedObjectListByPath, expireIn int) (string, error) {
  19. return c.presign(req, PresignedObjectListByPathPath, http.MethodGet, expireIn)
  20. }
  21. const PresignedObjectDownloadByPathPath = "/presigned/object/downloadByPath"
  22. type PresignedObjectDownloadByPath struct {
  23. PackageID clitypes.PackageID `form:"packageID" url:"packageID" binding:"required"`
  24. Path string `form:"path" url:"path" binding:"required"`
  25. Offset int64 `form:"offset" url:"offset,omitempty"`
  26. Length *int64 `form:"length" url:"length,omitempty"`
  27. }
  28. func (c *PresignedService) ObjectDownloadByPath(req PresignedObjectDownloadByPath, expireIn int) (string, error) {
  29. return c.presign(req, PresignedObjectDownloadByPathPath, http.MethodGet, expireIn)
  30. }
  31. const PresignedObjectDownloadPath = "/presigned/object/download"
  32. type PresignedObjectDownload struct {
  33. ObjectID clitypes.ObjectID `form:"objectID" url:"objectID" binding:"required"`
  34. Offset int64 `form:"offset" url:"offset,omitempty"`
  35. Length *int64 `form:"length" url:"length,omitempty"`
  36. }
  37. func (c *PresignedService) ObjectDownload(req PresignedObjectDownload, expireIn int) (string, error) {
  38. return c.presign(req, PresignedObjectDownloadPath, http.MethodGet, expireIn)
  39. }
  40. const PresignedObjectUploadPath = "/presigned/object/upload"
  41. type PresignedObjectUpload struct {
  42. PackageID clitypes.PackageID `form:"packageID" binding:"required" url:"packageID"`
  43. Path string `form:"path" binding:"required" url:"path"`
  44. Affinity clitypes.UserSpaceID `form:"affinity" url:"affinity,omitempty"`
  45. CopyTo []clitypes.UserSpaceID `form:"copyTo" url:"copyTo,omitempty"`
  46. CopyToPath []string `form:"copyToPath" url:"copyToPath,omitempty"`
  47. }
  48. type PresignedObjectUploadResp struct {
  49. Object clitypes.Object `json:"object"`
  50. }
  51. func (c *PresignedService) ObjectUpload(req PresignedObjectUpload, expireIn int) (string, error) {
  52. return c.presign(req, PresignedObjectUploadPath, http.MethodPost, expireIn)
  53. }
  54. const PresignedObjectNewMultipartUploadPath = "/presigned/object/newMultipartUpload"
  55. type PresignedObjectNewMultipartUpload struct {
  56. PackageID clitypes.PackageID `form:"packageID" binding:"required" url:"packageID"`
  57. Path string `form:"path" binding:"required" url:"path"`
  58. }
  59. type PresignedObjectNewMultipartUploadResp struct {
  60. Object clitypes.Object `json:"object"`
  61. }
  62. func (c *PresignedService) ObjectNewMultipartUpload(req PresignedObjectNewMultipartUpload, expireIn int) (string, error) {
  63. return c.presign(req, PresignedObjectNewMultipartUploadPath, http.MethodPost, expireIn)
  64. }
  65. const PresignedObjectUploadPartPath = "/presigned/object/uploadPart"
  66. type PresignedObjectUploadPart struct {
  67. ObjectID clitypes.ObjectID `form:"objectID" binding:"required" url:"objectID"`
  68. Index int `form:"index" binding:"required" url:"index"`
  69. }
  70. type PresignedUploadPartResp struct{}
  71. func (c *PresignedService) ObjectUploadPart(req PresignedObjectUploadPart, expireIn int) (string, error) {
  72. return c.presign(req, PresignedObjectUploadPartPath, http.MethodPost, expireIn)
  73. }
  74. const PresignedObjectCompleteMultipartUploadPath = "/presigned/object/completeMultipartUpload"
  75. type PresignedObjectCompleteMultipartUpload struct {
  76. ObjectID clitypes.ObjectID `form:"objectID" binding:"required" url:"objectID"`
  77. Indexes []int `form:"indexes" binding:"required" url:"indexes"`
  78. }
  79. type PresignedObjectCompleteMultipartUploadResp struct {
  80. Object clitypes.Object `json:"object"`
  81. }
  82. func (c *PresignedService) ObjectCompleteMultipartUpload(req PresignedObjectCompleteMultipartUpload, expireIn int) (string, error) {
  83. return c.presign(req, PresignedObjectCompleteMultipartUploadPath, http.MethodPost, expireIn)
  84. }
  85. func (c *PresignedService) presign(req any, path string, method string, expireIn int) (string, error) {
  86. // u, err := url.Parse(c.cfg.EndPoint)
  87. // if err != nil {
  88. // return "", err
  89. // }
  90. // u = u.JoinPath(path)
  91. // us, err := query.Values(req)
  92. // if err != nil {
  93. // return "", err
  94. // }
  95. // us.Add("X-Expires", fmt.Sprintf("%v", expireIn))
  96. // u.RawQuery = us.Encode()
  97. // prod := credentials.NewStaticCredentialsProvider(c.cfg.AccessKey, c.cfg.SecretKey, "")
  98. // cred, err := prod.Retrieve(context.TODO())
  99. // if err != nil {
  100. // return "", err
  101. // }
  102. // r, err := http.NewRequest(method, u.String(), nil)
  103. // if err != nil {
  104. // return "", err
  105. // }
  106. // signer := v4.NewSigner()
  107. // signedURL, _, err := signer.PresignHTTP(context.Background(), cred, r, "", AuthService, AuthRegion, time.Now())
  108. // return signedURL, err
  109. return "", nil
  110. }

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