Skip to content

Commit

Permalink
feat: Add drive volume events
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshoulahan committed Feb 16, 2023
1 parent 4056d48 commit 3e1eb7e
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 21 deletions.
57 changes: 57 additions & 0 deletions event_drive.go
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
}
30 changes: 30 additions & 0 deletions event_drive_types.go
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
)
26 changes: 7 additions & 19 deletions link_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@ const (
)

type RevisionMetadata struct {
ID string // Encrypted Revision ID
CreateTime int64 // Unix timestamp of the revision creation time
Size int64 // Size of the revision in bytes
State RevisionState // State of revision
ID string // Encrypted Revision ID
ClientUID string // Client UID
CreateTime int64 // Unix timestamp of the revision creation time
Size int64 // Size of the revision in bytes
ManifestSignature string // Signature of the revision manifest, signed with user's address key of the share.
SignatureEmail string // Email of the user that signed the revision.
State RevisionState // State of revision
}

// Revisions are only for files, they represent “versions” of files.
Expand All @@ -167,18 +170,3 @@ const (
RevisionStateObsolete
RevisionStateDeleted
)

type LinkEvent struct {
EventID string // Encrypted ID of the Event
CreateTime int64 // Time stamp of the creation time of the Event
EventType LinkEventType // Type of event
}

type LinkEventType int

const (
DeleteLinkEvent LinkEventType = iota
CreateLinkEvent
UpdateContentsLinkEvent
UpdateMetadataLinkEvent
)
14 changes: 14 additions & 0 deletions volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ func (c *Client) ListVolumes(ctx context.Context) ([]Volume, error) {

return res.Volumes, nil
}

func (c *Client) GetVolume(ctx context.Context, volumeID string) (Volume, error) {
var res struct {
Volume Volume
}

if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/drive/volumes/" + volumeID)
}); err != nil {
return Volume{}, err
}

return res.Volume, nil
}
4 changes: 2 additions & 2 deletions volume_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ type VolumeShare struct {
type VolumeState int

const (
ActiveVolumeState VolumeState = 1
LockedVolumeState VolumeState = 3
VolumeStateActive VolumeState = 1
VolumeStateLocked VolumeState = 3
)

0 comments on commit 3e1eb7e

Please sign in to comment.