-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4056d48
commit 3e1eb7e
Showing
5 changed files
with
110 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package proton | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-resty/resty/v2" | ||
) | ||
|
||
func (c *Client) GetLatestVolumeEventID(ctx context.Context, volumeID string) (string, error) { | ||
var res struct { | ||
EventID string | ||
} | ||
|
||
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) { | ||
return r.SetResult(&res).Get("/drive/volumes/" + volumeID + "/events/latest") | ||
}); err != nil { | ||
return "", err | ||
} | ||
|
||
return res.EventID, nil | ||
} | ||
|
||
func (c *Client) GetVolumeEvent(ctx context.Context, volumeID, eventID string) (VolumeEvent, error) { | ||
event, more, err := c.getVolumeEvent(ctx, volumeID, eventID) | ||
if err != nil { | ||
return VolumeEvent{}, err | ||
} | ||
|
||
for more { | ||
var next VolumeEvent | ||
|
||
next, more, err = c.getVolumeEvent(ctx, volumeID, event.EventID) | ||
if err != nil { | ||
return VolumeEvent{}, err | ||
} | ||
|
||
event.Events = append(event.Events, next.Events...) | ||
} | ||
|
||
return event, nil | ||
} | ||
|
||
func (c *Client) getVolumeEvent(ctx context.Context, volumeID, eventID string) (VolumeEvent, bool, error) { | ||
var res struct { | ||
VolumeEvent | ||
|
||
More Bool | ||
} | ||
|
||
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) { | ||
return r.SetResult(&res).Get("/drive/volumes/" + volumeID + "/events/" + eventID) | ||
}); err != nil { | ||
return VolumeEvent{}, false, err | ||
} | ||
|
||
return res.VolumeEvent, bool(res.More), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package proton | ||
|
||
type VolumeEvent struct { | ||
EventID string | ||
|
||
Events []LinkEvent | ||
|
||
Refresh Bool | ||
} | ||
|
||
type LinkEvent struct { | ||
EventID string | ||
|
||
EventType LinkEventType | ||
|
||
CreateTime int | ||
|
||
Data string | ||
|
||
Link Link | ||
} | ||
|
||
type LinkEventType int | ||
|
||
const ( | ||
LinkEventDelete LinkEventType = iota | ||
LinkEventCreate | ||
LinkEventUpdate | ||
LinkEventUpdateMetadata | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters