-
Notifications
You must be signed in to change notification settings - Fork 18
/
link.go
49 lines (38 loc) · 1.17 KB
/
link.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
43
44
45
46
47
48
49
package proton
import (
"context"
"github.com/go-resty/resty/v2"
)
func (c *Client) GetLink(ctx context.Context, shareID, linkID string) (Link, error) {
var res struct {
Link Link
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/drive/shares/" + shareID + "/links/" + linkID)
}); err != nil {
return Link{}, err
}
return res.Link, nil
}
func (c *Client) CreateFile(ctx context.Context, shareID string, req CreateFileReq) (CreateFileRes, error) {
var res struct {
File CreateFileRes
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).SetBody(req).Post("/drive/shares/" + shareID + "/files")
}); err != nil {
return CreateFileRes{}, err
}
return res.File, nil
}
func (c *Client) CreateFolder(ctx context.Context, shareID string, req CreateFolderReq) (CreateFolderRes, error) {
var res struct {
Folder CreateFolderRes
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).SetBody(req).Post("/drive/shares/" + shareID + "/folders")
}); err != nil {
return CreateFolderRes{}, err
}
return res.Folder, nil
}