mirror of
https://github.com/ProtonMail/go-proton-api.git
synced 2025-12-23 23:57:50 -05:00
feat: Add drive volume events
This commit is contained in:
57
event_drive.go
Normal file
57
event_drive.go
Normal file
@@ -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
event_drive_types.go
Normal file
30
event_drive_types.go
Normal file
@@ -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
|
||||||
|
)
|
||||||
@@ -145,10 +145,13 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type RevisionMetadata struct {
|
type RevisionMetadata struct {
|
||||||
ID string // Encrypted Revision ID
|
ID string // Encrypted Revision ID
|
||||||
CreateTime int64 // Unix timestamp of the revision creation time
|
ClientUID string // Client UID
|
||||||
Size int64 // Size of the revision in bytes
|
CreateTime int64 // Unix timestamp of the revision creation time
|
||||||
State RevisionState // State of revision
|
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.
|
// Revisions are only for files, they represent “versions” of files.
|
||||||
@@ -167,18 +170,3 @@ const (
|
|||||||
RevisionStateObsolete
|
RevisionStateObsolete
|
||||||
RevisionStateDeleted
|
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
volume.go
14
volume.go
@@ -19,3 +19,17 @@ func (c *Client) ListVolumes(ctx context.Context) ([]Volume, error) {
|
|||||||
|
|
||||||
return res.Volumes, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,6 @@ type VolumeShare struct {
|
|||||||
type VolumeState int
|
type VolumeState int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ActiveVolumeState VolumeState = 1
|
VolumeStateActive VolumeState = 1
|
||||||
LockedVolumeState VolumeState = 3
|
VolumeStateLocked VolumeState = 3
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user