| @@ -7,6 +7,7 @@ import ( | |||
| "strings" | |||
| "gitlink.org.cn/cloudream/common/consts/errorcode" | |||
| "gitlink.org.cn/cloudream/common/models" | |||
| myhttp "gitlink.org.cn/cloudream/common/utils/http" | |||
| "gitlink.org.cn/cloudream/common/utils/serder" | |||
| ) | |||
| @@ -48,19 +49,13 @@ func (c *Client) ObjectDownload(req ObjectDownloadReq) (io.ReadCloser, error) { | |||
| } | |||
| type ObjectUploadReq struct { | |||
| UserID int64 `json:"userID"` | |||
| BucketID int64 `json:"bucketID"` | |||
| FileSize int64 `json:"fileSize"` | |||
| ObjectName string `json:"objectName"` | |||
| Redundancy MyRedundancyInfo `json:"redundancy"` | |||
| File io.Reader `json:"-"` | |||
| UserID int64 `json:"userID"` | |||
| BucketID int64 `json:"bucketID"` | |||
| FileSize int64 `json:"fileSize"` | |||
| ObjectName string `json:"objectName"` | |||
| Redundancy models.TypedRedundancyInfo `json:"redundancy"` | |||
| File io.Reader `json:"-"` | |||
| } | |||
| type MyRedundancyInfo struct { | |||
| Type string `json:"type"` | |||
| Info any `json:"config"` | |||
| } | |||
| type ObjectUploadResp struct { | |||
| ObjectID int64 `json:"objectID,string"` | |||
| } | |||
| @@ -24,7 +24,7 @@ func Test_Object(t *testing.T) { | |||
| BucketID: 1, | |||
| FileSize: 4096, | |||
| ObjectName: uuid.NewString(), | |||
| Redundancy: MyRedundancyInfo{ | |||
| Redundancy: models.TypedRedundancyInfo{ | |||
| Type: models.RedundancyRep, | |||
| Info: models.NewRepRedundancyInfo(1), | |||
| }, | |||
| @@ -65,7 +65,7 @@ func Test_Storage(t *testing.T) { | |||
| BucketID: 1, | |||
| FileSize: 4096, | |||
| ObjectName: uuid.NewString(), | |||
| Redundancy: MyRedundancyInfo{ | |||
| Redundancy: models.TypedRedundancyInfo{ | |||
| Type: models.RedundancyRep, | |||
| Info: models.NewRepRedundancyInfo(1), | |||
| }, | |||
| @@ -1,5 +1,7 @@ | |||
| package models | |||
| import "gitlink.org.cn/cloudream/common/utils/serder" | |||
| /// TODO 将分散在各处的公共结构体定义集中到这里来 | |||
| const ( | |||
| @@ -11,7 +13,7 @@ const ( | |||
| // 注:如果在mq中的消息结构体使用了此类型,记得使用RegisterTypeSet注册相关的类型。 | |||
| type RedundancyInfo interface{} | |||
| type RedundancyInfoConst interface { | |||
| RepRedundancyInfo | ECRedundancyInfo | RedundancyInfo | |||
| RedundancyInfo | RepRedundancyInfo | ECRedundancyInfo | |||
| } | |||
| type RepRedundancyInfo struct { | |||
| RepCount int `json:"repCount"` | |||
| @@ -24,4 +26,43 @@ func NewRepRedundancyInfo(repCount int) RepRedundancyInfo { | |||
| } | |||
| type ECRedundancyInfo struct { | |||
| ECName string `json:"ecName"` | |||
| } | |||
| func NewECRedundancyInfo(ecName string) ECRedundancyInfo { | |||
| return ECRedundancyInfo{ | |||
| ECName: ecName, | |||
| } | |||
| } | |||
| type TypedRedundancyInfo struct { | |||
| Type string `json:"type"` | |||
| Info RedundancyInfo `json:"info"` | |||
| } | |||
| func NewTypedRedundancyInfo[T RedundancyInfoConst](typ string, info T) TypedRedundancyInfo { | |||
| return TypedRedundancyInfo{ | |||
| Type: typ, | |||
| Info: info, | |||
| } | |||
| } | |||
| func NewTypedRepRedundancyInfo(repCount int) TypedRedundancyInfo { | |||
| return TypedRedundancyInfo{ | |||
| Type: RedundancyRep, | |||
| Info: RepRedundancyInfo{ | |||
| RepCount: repCount, | |||
| }, | |||
| } | |||
| } | |||
| func (i *TypedRedundancyInfo) ToRepInfo() (RepRedundancyInfo, error) { | |||
| var info RepRedundancyInfo | |||
| err := serder.AnyToAny(i.Info, &info) | |||
| return info, err | |||
| } | |||
| func (i *TypedRedundancyInfo) ToECInfo() (ECRedundancyInfo, error) { | |||
| var info ECRedundancyInfo | |||
| err := serder.AnyToAny(i.Info, &info) | |||
| return info, err | |||
| } | |||