| 1 |
package proton |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"fmt" |
| 6 |
"strconv" |
| 7 |
|
| 8 |
"github.com/go-resty/resty/v2" |
| 9 |
) |
| 10 |
|
| 11 |
func (c *Client) ListRevisions(ctx context.Context, shareID, linkID string) ([]RevisionMetadata, error) { |
| 12 |
var res struct { |
| 13 |
Revisions []RevisionMetadata |
| 14 |
} |
| 15 |
|
| 16 |
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 17 |
return r.SetResult(&res).Get("/drive/shares/" + shareID + "/files/" + linkID + "/revisions") |
| 18 |
}); err != nil { |
| 19 |
return nil, err |
| 20 |
} |
| 21 |
|
| 22 |
return res.Revisions, nil |
| 23 |
} |
| 24 |
|
| 25 |
func (c *Client) GetRevisionAllBlocks(ctx context.Context, shareID, linkID, revisionID string) (Revision, error) { |
| 26 |
var res struct { |
| 27 |
Revision Revision |
| 28 |
} |
| 29 |
|
| 30 |
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 31 |
return r. |
| 32 |
SetResult(&res). |
| 33 |
Get("/drive/shares/" + shareID + "/files/" + linkID + "/revisions/" + revisionID) |
| 34 |
}); err != nil { |
| 35 |
return Revision{}, err |
| 36 |
} |
| 37 |
|
| 38 |
return res.Revision, nil |
| 39 |
} |
| 40 |
|
| 41 |
func (c *Client) GetRevision(ctx context.Context, shareID, linkID, revisionID string, fromBlock, pageSize int) (Revision, error) { |
| 42 |
if fromBlock < 1 { |
| 43 |
return Revision{}, fmt.Errorf("fromBlock must be greater than 0") |
| 44 |
} else if pageSize < 1 { |
| 45 |
return Revision{}, fmt.Errorf("pageSize must be greater than 0") |
| 46 |
} |
| 47 |
|
| 48 |
var res struct { |
| 49 |
Revision Revision |
| 50 |
} |
| 51 |
|
| 52 |
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 53 |
return r. |
| 54 |
SetQueryParams(map[string]string{ |
| 55 |
"FromBlockIndex": strconv.Itoa(fromBlock), |
| 56 |
"PageSize": strconv.Itoa(pageSize), |
| 57 |
}). |
| 58 |
SetResult(&res). |
| 59 |
Get("/drive/shares/" + shareID + "/files/" + linkID + "/revisions/" + revisionID) |
| 60 |
}); err != nil { |
| 61 |
return Revision{}, err |
| 62 |
} |
| 63 |
|
| 64 |
return res.Revision, nil |
| 65 |
} |
| 66 |
|
| 67 |
func (c *Client) CommitRevision(ctx context.Context, shareID, linkID, revisionID string, req CommitRevisionReq) error { |
| 68 |
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 69 |
return r.SetBody(req).Put("/drive/shares/" + shareID + "/files/" + linkID + "/revisions/" + revisionID) |
| 70 |
}) |
| 71 |
} |
| 72 |
|
| 73 |
func (c *Client) DeleteRevision(ctx context.Context, shareID, linkID, revisionID string) error { |
| 74 |
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 75 |
return r.Delete("/drive/shares/" + shareID + "/files/" + linkID + "/revisions/" + revisionID) |
| 76 |
}) |
| 77 |
} |
| 78 |
|
| 79 |
func (c *Client) CreateRevision(ctx context.Context, shareID, linkID string) (CreateRevisionRes, error) { |
| 80 |
var res struct { |
| 81 |
Revision CreateRevisionRes |
| 82 |
} |
| 83 |
|
| 84 |
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 85 |
return r.SetResult(&res).Post("/drive/shares/" + shareID + "/files/" + linkID + "/revisions") |
| 86 |
}); err != nil { |
| 87 |
return CreateRevisionRes{}, err |
| 88 |
} |
| 89 |
|
| 90 |
return res.Revision, nil |
| 91 |
} |