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