diff --git a/block.go b/block.go index 74e89a6..b2d6596 100644 --- a/block.go +++ b/block.go @@ -2,7 +2,9 @@ package proton import ( "context" + "fmt" "io" + "net/http" "github.com/go-resty/resty/v2" ) @@ -33,10 +35,40 @@ func (c *Client) RequestBlockUpload(ctx context.Context, req BlockUploadReq) ([] } func (c *Client) UploadBlock(ctx context.Context, bareURL, token string, block io.Reader) 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) - }) + // Storage servers require only pm-storage-token, not API auth headers. + // Use a plain resty request instead of going through c.do() which adds + // x-pm-uid and Authorization headers. + req := resty.New().R().SetContext(ctx) + req.SetHeader("pm-storage-token", token) + req.SetMultipartField("Block", "blob", "application/octet-stream", block) + + resp, err := req.Post(bareURL) + if err != nil { + return err + } + + if resp.StatusCode() != http.StatusOK { + return fmt.Errorf("%v POST %s: %s", resp.StatusCode(), bareURL, resp.String()) + } + + return nil } + +func (c *Client) GetUploadVerification(ctx context.Context, volumeID, linkID, revisionID string) (UploadVerification, error) { + var res struct { + VerificationCode string + ContentKeyPacket string + } + + route := fmt.Sprintf("/drive/v2/volumes/%s/links/%s/revisions/%s/verification", volumeID, linkID, revisionID) + if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) { + return r.SetResult(&res).Get(route) + }); err != nil { + return UploadVerification{}, err + } + + return UploadVerification{ + VerificationCode: res.VerificationCode, + ContentKeyPacket: res.ContentKeyPacket, + }, nil +} \ No newline at end of file diff --git a/block_types.go b/block_types.go index ad41611..0eb5288 100644 --- a/block_types.go +++ b/block_types.go @@ -19,6 +19,7 @@ type BlockUploadReq struct { ShareID string LinkID string RevisionID string + VolumeID string BlockList []BlockUploadInfo } @@ -28,6 +29,16 @@ type BlockUploadInfo struct { Size int64 EncSignature string Hash string + Verifier *BlockVerifier `json:"Verifier,omitempty"` +} + +type BlockVerifier struct { + Token string +} + +type UploadVerification struct { + VerificationCode string + ContentKeyPacket string } type BlockUploadLink struct {