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 {
|
||||
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.
|
||||
@@ -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
volume.go
14
volume.go
@@ -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
|
||||
}
|
||||
|
||||
@@ -23,6 +23,6 @@ type VolumeShare struct {
|
||||
type VolumeState int
|
||||
|
||||
const (
|
||||
ActiveVolumeState VolumeState = 1
|
||||
LockedVolumeState VolumeState = 3
|
||||
VolumeStateActive VolumeState = 1
|
||||
VolumeStateLocked VolumeState = 3
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user