|
- package storage
-
- import (
- "fmt"
- "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"
- )
-
- type StorageMoveObjectReq struct {
- UserID int64 `json:"userID"`
- ObjectID int64 `json:"objectID"`
- StorageID int64 `json:"storageID"`
- }
-
- func (c *Client) StorageMoveObject(req StorageMoveObjectReq) error {
- url, err := url.JoinPath(c.baseURL, "/storage/moveObject")
- if err != nil {
- return err
- }
-
- resp, err := myhttp.PostJSON(url, myhttp.RequestParam{
- Body: req,
- })
- if err != nil {
- return err
- }
-
- contType := resp.Header.Get("Content-Type")
- if strings.Contains(contType, myhttp.ContentTypeJSON) {
- var codeResp response[any]
- if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
- return fmt.Errorf("parsing response: %w", err)
- }
-
- if codeResp.Code == errorcode.OK {
- return nil
- }
-
- return codeResp.ToError()
- }
-
- return fmt.Errorf("unknow response content type: %s", contType)
- }
|