| 1 |
package proton |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"io" |
| 6 |
|
| 7 |
"github.com/go-resty/resty/v2" |
| 8 |
) |
| 9 |
|
| 10 |
func (c *Client) GetBlock(ctx context.Context, bareURL, token string) (io.ReadCloser, error) { |
| 11 |
res, err := c.doRes(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 12 |
return r.SetHeader("pm-storage-token", token).SetDoNotParseResponse(true).Get(bareURL) |
| 13 |
}) |
| 14 |
if err != nil { |
| 15 |
return nil, err |
| 16 |
} |
| 17 |
|
| 18 |
return res.RawBody(), nil |
| 19 |
} |
| 20 |
|
| 21 |
func (c *Client) RequestBlockUpload(ctx context.Context, req BlockUploadReq) ([]BlockUploadLink, error) { |
| 22 |
var res struct { |
| 23 |
UploadLinks []BlockUploadLink |
| 24 |
} |
| 25 |
|
| 26 |
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 27 |
return r.SetResult(&res).SetBody(req).Post("/drive/blocks") |
| 28 |
}); err != nil { |
| 29 |
return nil, err |
| 30 |
} |
| 31 |
|
| 32 |
return res.UploadLinks, nil |
| 33 |
} |
| 34 |
|
| 35 |
func (c *Client) UploadBlock(ctx context.Context, bareURL, token string, block io.Reader) error { |
| 36 |
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 37 |
return r. |
| 38 |
SetHeader("pm-storage-token", token). |
| 39 |
SetMultipartField("Block", "blob", "application/octet-stream", block). |
| 40 |
Post(bareURL) |
| 41 |
}) |
| 42 |
} |