| @@ -32,7 +32,7 @@ func Test_Package(t *testing.T) { | |||
| URL: "http://localhost:7893", | |||
| }) | |||
| _, err := cli.PackageGetWithObjectCacheInfos(PackageGetWithObjectCacheInfos{UserID: 0, PackageID: 13}) | |||
| _, err := cli.PackageGetWithObjects(PackageGetWithObjectsInfos{UserID: 0, PackageID: 13}) | |||
| So(err, ShouldBeNil) | |||
| }) | |||
| } | |||
| @@ -8,19 +8,19 @@ import ( | |||
| myhttp "gitlink.org.cn/cloudream/common/utils/http" | |||
| ) | |||
| const PackageGetWithObjectCacheInfosPath = "/package/getWithObjectCacheInfos" | |||
| const PackageGetWithObjectsPath = "/package/getWithObjects" | |||
| type PackageGetWithObjectCacheInfos struct { | |||
| type PackageGetWithObjectsInfos struct { | |||
| UserID int64 `json:"userID"` | |||
| PackageID int64 `json:"packageID"` | |||
| } | |||
| type PackageGetWithObjectCacheInfosResp struct { | |||
| Package cdssdk.Package `json:"package"` | |||
| ObjectCacheInfos []cdssdk.ObjectCacheInfo `json:"objectCacheInfos"` | |||
| type PackageGetWithObjectsResp struct { | |||
| Package cdssdk.Package `json:"package"` | |||
| Objects []cdssdk.Object `json:"objects"` | |||
| } | |||
| func (c *Client) PackageGetWithObjectCacheInfos(req PackageGetWithObjectCacheInfos) (*PackageGetWithObjectCacheInfosResp, error) { | |||
| url, err := url.JoinPath(c.baseURL, PackageGetWithObjectCacheInfosPath) | |||
| func (c *Client) PackageGetWithObjects(req PackageGetWithObjectsInfos) (*PackageGetWithObjectsResp, error) { | |||
| url, err := url.JoinPath(c.baseURL, PackageGetWithObjectsPath) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| @@ -32,7 +32,7 @@ func (c *Client) PackageGetWithObjectCacheInfos(req PackageGetWithObjectCacheInf | |||
| return nil, err | |||
| } | |||
| jsonResp, err := myhttp.ParseJSONResponse[response[PackageGetWithObjectCacheInfosResp]](resp) | |||
| jsonResp, err := myhttp.ParseJSONResponse[response[PackageGetWithObjectsResp]](resp) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| @@ -7,17 +7,17 @@ import ( | |||
| myhttp "gitlink.org.cn/cloudream/common/utils/http" | |||
| ) | |||
| var CacheMovePackagePath = "/cache/movePackage" | |||
| type CacheMovePackageReq struct { | |||
| UserID UserID `json:"userID"` | |||
| PackageID PackageID `json:"packageID"` | |||
| NodeID NodeID `json:"nodeID"` | |||
| } | |||
| type CacheMovePackageResp struct { | |||
| CacheInfos []ObjectCacheInfo `json:"cacheInfos"` | |||
| } | |||
| type CacheMovePackageResp struct{} | |||
| func (c *Client) CacheMovePackage(req CacheMovePackageReq) (*CacheMovePackageResp, error) { | |||
| url, err := url.JoinPath(c.baseURL, "/cache/movePackage") | |||
| url, err := url.JoinPath(c.baseURL, CacheMovePackagePath) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| @@ -40,36 +40,3 @@ func (c *Client) CacheMovePackage(req CacheMovePackageReq) (*CacheMovePackageRes | |||
| return nil, jsonResp.ToError() | |||
| } | |||
| type CacheGetPackageObjectCacheInfosReq struct { | |||
| UserID UserID `json:"userID"` | |||
| PackageID PackageID `json:"packageID"` | |||
| } | |||
| type CacheGetPackageObjectCacheInfosResp struct { | |||
| Infos []ObjectCacheInfo `json:"cacheInfos"` | |||
| } | |||
| func (c *Client) CacheGetPackageObjectCacheInfos(req CacheGetPackageObjectCacheInfosReq) (*CacheGetPackageObjectCacheInfosResp, error) { | |||
| url, err := url.JoinPath(c.baseURL, "/cache/getPackageObjectCacheInfos") | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| resp, err := myhttp.GetForm(url, myhttp.RequestParam{ | |||
| Query: req, | |||
| }) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| jsonResp, err := myhttp.ParseJSONResponse[response[CacheGetPackageObjectCacheInfosResp]](resp) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| if jsonResp.Code == errorcode.OK { | |||
| return &jsonResp.Data, nil | |||
| } | |||
| return nil, jsonResp.ToError() | |||
| } | |||
| @@ -91,6 +91,7 @@ type Object struct { | |||
| PackageID PackageID `db:"PackageID" json:"packageID"` | |||
| Path string `db:"Path" json:"path"` | |||
| Size int64 `db:"Size" json:"size,string"` | |||
| FileHash string `db:"FileHash" json:"fileHash"` | |||
| Redundancy Redundancy `db:"Redundancy" json:"redundancy"` | |||
| } | |||
| @@ -109,18 +110,6 @@ func (i *Object) Scan(src interface{}) error { | |||
| return nil | |||
| } | |||
| type ObjectCacheInfo struct { | |||
| Object Object `json:"object"` | |||
| FileHash string `json:"fileHash"` | |||
| } | |||
| func NewObjectCacheInfo(object Object, fileHash string) ObjectCacheInfo { | |||
| return ObjectCacheInfo{ | |||
| Object: object, | |||
| FileHash: fileHash, | |||
| } | |||
| } | |||
| type NodePackageCachingInfo struct { | |||
| NodeID NodeID `json:"nodeID"` | |||
| FileSize int64 `json:"fileSize"` | |||
| @@ -128,16 +117,14 @@ type NodePackageCachingInfo struct { | |||
| } | |||
| type PackageCachingInfo struct { | |||
| NodeInfos []NodePackageCachingInfo `json:"nodeInfos"` | |||
| PackageSize int64 `json:"packageSize"` | |||
| RedunancyType string `json:"redunancyType"` | |||
| NodeInfos []NodePackageCachingInfo `json:"nodeInfos"` | |||
| PackageSize int64 `json:"packageSize"` | |||
| } | |||
| func NewPackageCachingInfo(nodeInfos []NodePackageCachingInfo, packageSize int64, redunancyType string) PackageCachingInfo { | |||
| func NewPackageCachingInfo(nodeInfos []NodePackageCachingInfo, packageSize int64) PackageCachingInfo { | |||
| return PackageCachingInfo{ | |||
| NodeInfos: nodeInfos, | |||
| PackageSize: packageSize, | |||
| RedunancyType: redunancyType, | |||
| NodeInfos: nodeInfos, | |||
| PackageSize: packageSize, | |||
| } | |||
| } | |||
| @@ -6,6 +6,7 @@ import ( | |||
| "net/url" | |||
| "strings" | |||
| "gitlink.org.cn/cloudream/common/consts/errorcode" | |||
| myhttp "gitlink.org.cn/cloudream/common/utils/http" | |||
| "gitlink.org.cn/cloudream/common/utils/serder" | |||
| ) | |||
| @@ -45,3 +46,38 @@ func (c *Client) ObjectDownload(req ObjectDownloadReq) (io.ReadCloser, error) { | |||
| return nil, fmt.Errorf("unknow response content type: %s", contType) | |||
| } | |||
| var ObjectGetPackageObjectsPath = "/object/getPackageObjects" | |||
| type ObjectGetPackageObjectsReq struct { | |||
| UserID UserID `json:"userID"` | |||
| PackageID PackageID `json:"packageID"` | |||
| } | |||
| type ObjectGetPackageObjectsResp struct { | |||
| Objects []Object `json:"objects"` | |||
| } | |||
| func (c *Client) ObjectGetPackageObjects(req ObjectGetPackageObjectsReq) (*ObjectGetPackageObjectsResp, error) { | |||
| url, err := url.JoinPath(c.baseURL, ObjectGetPackageObjectsPath) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| resp, err := myhttp.GetForm(url, myhttp.RequestParam{ | |||
| Query: req, | |||
| }) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| jsonResp, err := myhttp.ParseJSONResponse[response[ObjectGetPackageObjectsResp]](resp) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| if jsonResp.Code == errorcode.OK { | |||
| return &jsonResp.Data, nil | |||
| } | |||
| return nil, jsonResp.ToError() | |||
| } | |||
| @@ -177,21 +177,13 @@ func Test_Cache(t *testing.T) { | |||
| }) | |||
| So(err, ShouldBeNil) | |||
| cacheMoveResp, err := cli.CacheMovePackage(CacheMovePackageReq{ | |||
| _, err = cli.CacheMovePackage(CacheMovePackageReq{ | |||
| UserID: 0, | |||
| PackageID: upResp.PackageID, | |||
| NodeID: 1, | |||
| }) | |||
| So(err, ShouldBeNil) | |||
| cacheInfoResp, err := cli.CacheGetPackageObjectCacheInfos(CacheGetPackageObjectCacheInfosReq{ | |||
| UserID: 0, | |||
| PackageID: upResp.PackageID, | |||
| }) | |||
| So(err, ShouldBeNil) | |||
| So(cacheInfoResp.Infos, ShouldResemble, cacheMoveResp.CacheInfos) | |||
| err = cli.PackageDelete(PackageDeleteReq{ | |||
| UserID: 0, | |||
| PackageID: upResp.PackageID, | |||