drive

package module
v0.0.0-...-61ce1f6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: MIT Imports: 20 Imported by: 1

README

proton-drive

A library for interacting with the Proton Drive API.

This code was born out of (mild) frustration about the Proton Drive backend for rclone. Due to how the API works, listing directory contents takes quite a lot of time. This, combined, with a lot of files makes sync operations painfully slow.

To remedy this issue, this library takes a more unconventional approach: During initialization, the metadata of EVERY file or directory is fetched and stored in a virtual file tree, that is kept up-to-date using Protons event system.

While this means that directory listings are pretty much instant and don't require any calls to the API, it also means that the startup time grows with the amount of files you have stored, and that the consuming app MUST be run as a daemon.

Thanks

Documentation

Index

Constants

View Source
const (
	BlockSize     = 4 * 1024 * 1024
	ISO8601Layout = "2006-01-02T15:04:05-0700"
)

Variables

View Source
var (
	ErrUsernamePasswordMissing = errors.New("username/password missing")
	ErrTwoFactorTokenMissing   = errors.New("2fa token missing")
	ErrMailboxPasswordMissing  = errors.New("mailbox password missing")
)
View Source
var (
	ErrInvalidLink     = errors.New("invalid link")
	ErrInvalidLinkType = errors.New("invalid link type, expected file")
	ErrAlreadyExists   = errors.New("file or folder already exists")
)
View Source
var (
	ErrMainVolumeNotFound             = errors.New("main volume not found")
	ErrShareAddressNotFound           = errors.New("share address not found")
	ErrLinkSignatureEmailNotFound     = errors.New("signature email not found")
	ErrLinkNameSignatureEmailNotFound = errors.New("name signature email not found")
)
View Source
var (
	ErrOutOfRange              = errors.New("out of range read")
	ErrBlockAddressNotFound    = errors.New("block signature address not found")
	ErrBlockVerificationFailed = errors.New("block verification failed")
	ErrInvalidSeekOperation    = errors.New("invalid seek operation")
)
View Source
var (
	ErrKeyringUnlockFailed = errors.New("failed to unlock keyring")
)
View Source
var (
	ErrUnexpectedBlockUploadLinks = errors.New("unexpected number of block upload links")
)

Functions

This section is empty.

Types

type Address

type Address struct {
	// contains filtered or unexported fields
}

func (*Address) Email

func (self *Address) Email() string

func (*Address) ID

func (self *Address) ID() string

func (*Address) Keyring

func (self *Address) Keyring() *crypto.KeyRing

type Application

type Application struct {
	// contains filtered or unexported fields
}

func NewApplication

func NewApplication(version string) *Application

func (*Application) Client

func (self *Application) Client() *proton.Client

func (*Application) LoginWithCredentials

func (self *Application) LoginWithCredentials(ctx context.Context, credentials Credentials) error

func (*Application) LoginWithTokens

func (self *Application) LoginWithTokens(tokens *Tokens)

func (*Application) Manager

func (self *Application) Manager() *proton.Manager

func (*Application) OnTokensExpired

func (self *Application) OnTokensExpired(handler TokensExpiredHandler)

func (*Application) OnTokensUpdated

func (self *Application) OnTokensUpdated(handler TokensUpdatedHandler)

func (*Application) Tokens

func (self *Application) Tokens() *Tokens

type Attributes

type Attributes struct {
	Size       int64
	Hash       string
	MIMEType   string
	BlockSizes []int64
	ModifyTime time.Time
}

type Credentials

type Credentials struct {
	Username        string
	Password        string
	TwoFA           string
	MailboxPassword string
}

type EventLoop

type EventLoop struct {
	// contains filtered or unexported fields
}

func (*EventLoop) Init

func (self *EventLoop) Init(ctx context.Context) error

func (*EventLoop) TriggerUpdate

func (self *EventLoop) TriggerUpdate()

type FileReader

type FileReader struct {
	// contains filtered or unexported fields
}

func (*FileReader) Close

func (self *FileReader) Close() error

func (*FileReader) Read

func (self *FileReader) Read(buffer []byte) (int, error)

func (*FileReader) Seek

func (self *FileReader) Seek(offset int64, whence int) (int64, error)

func (*FileReader) Size

func (self *FileReader) Size() int64

type FileSystem

type FileSystem struct {
	// contains filtered or unexported fields
}

func (*FileSystem) CreateDir

func (self *FileSystem) CreateDir(ctx context.Context, parent *Link, name string) error

func (*FileSystem) Delete

func (self *FileSystem) Delete(ctx context.Context, link *Link) error

func (*FileSystem) Download

func (self *FileSystem) Download(ctx context.Context, link *Link) (*FileReader, error)

func (*FileSystem) Move

func (self *FileSystem) Move(ctx context.Context, link *Link, parent *Link, name string) error

func (*FileSystem) Upload

func (self *FileSystem) Upload(ctx context.Context, parent *Link, name string) (*FileWriter, error)

type FileWriter

type FileWriter struct {
	// contains filtered or unexported fields
}

func (*FileWriter) Close

func (self *FileWriter) Close() error

func (*FileWriter) Hash

func (self *FileWriter) Hash() string

func (*FileWriter) ModTime

func (self *FileWriter) ModTime() time.Time

func (*FileWriter) SetModTime

func (self *FileWriter) SetModTime(modTime time.Time)

func (*FileWriter) Size

func (self *FileWriter) Size() int64

func (*FileWriter) Write

func (self *FileWriter) Write(buffer []byte) (int, error)

type InitHandler

type InitHandler func(ctx context.Context) error
type Link struct {
	// contains filtered or unexported fields
}

func (*Link) BlockSizes

func (self *Link) BlockSizes() []int64

func (*Link) Children

func (self *Link) Children() mapset.Set[*Link]

func (*Link) ContentHash

func (self *Link) ContentHash() string

func (*Link) CreationTime

func (self *Link) CreationTime() time.Time

func (*Link) Hash

func (self *Link) Hash() string

func (*Link) HashKey

func (self *Link) HashKey() []byte

func (*Link) ID

func (self *Link) ID() string

func (*Link) IsDir

func (self *Link) IsDir() bool

func (*Link) IsFile

func (self *Link) IsFile() bool

func (*Link) IsRoot

func (self *Link) IsRoot() bool

func (*Link) Keyring

func (self *Link) Keyring() *crypto.KeyRing

func (*Link) MIMEType

func (self *Link) MIMEType() string

func (*Link) ModificationTime

func (self *Link) ModificationTime() time.Time

func (*Link) Name

func (self *Link) Name() string

func (*Link) NameSignatureEmail

func (self *Link) NameSignatureEmail() *Address

func (*Link) NodePassphrase

func (self *Link) NodePassphrase() string

func (*Link) NodePassphraseSignature

func (self *Link) NodePassphraseSignature() string

func (*Link) Parent

func (self *Link) Parent() *Link

func (*Link) Path

func (self *Link) Path() string

func (*Link) RevisionID

func (self *Link) RevisionID() string

func (*Link) SessionKey

func (self *Link) SessionKey() *crypto.SessionKey

func (*Link) Share

func (self *Link) Share() *Share

func (*Link) SignatureAddress

func (self *Link) SignatureAddress() *Address

func (*Link) Size

func (self *Link) Size() int64
type Links struct {
	// contains filtered or unexported fields
}

func (*Links) Init

func (self *Links) Init(ctx context.Context) error

func (*Links) LinkFromID

func (self *Links) LinkFromID(linkID string) *Link

func (*Links) LinkFromPath

func (self *Links) LinkFromPath(path string) *Link

func (*Links) OnEvent

func (self *Links) OnEvent(event proton.LinkEvent) error

func (*Links) Root

func (self *Links) Root() *Link

func (*Links) Share

func (self *Links) Share() *Share

func (*Links) Volume

func (self *Links) Volume() *Volume

type Session

type Session struct {
	// contains filtered or unexported fields
}

func NewSession

func NewSession(application *Application) *Session

func (*Session) Client

func (self *Session) Client() *proton.Client

func (*Session) Events

func (self *Session) Events() *EventLoop

func (*Session) FileSystem

func (self *Session) FileSystem() *FileSystem

func (*Session) Init

func (self *Session) Init(ctx context.Context) error
func (self *Session) Links() *Links

func (*Session) Tokens

func (self *Session) Tokens() *Tokens

func (*Session) User

func (self *Session) User() *User

type Share

type Share struct {
	// contains filtered or unexported fields
}

func (*Share) Address

func (self *Share) Address() *Address

func (*Share) ID

func (self *Share) ID() string

func (*Share) Keyring

func (self *Share) Keyring() *crypto.KeyRing

func (*Share) LinkID

func (self *Share) LinkID() string

type Tokens

type Tokens struct {
	UID           string
	AccessToken   string
	RefreshToken  string
	SaltedKeyPass string
}

type TokensExpiredHandler

type TokensExpiredHandler func()

type TokensUpdatedHandler

type TokensUpdatedHandler func(*Tokens)

type User

type User struct {
	// contains filtered or unexported fields
}

func (*User) AddressFromEmail

func (self *User) AddressFromEmail(email string) *Address

func (*User) AddressFromID

func (self *User) AddressFromID(id string) *Address

func (*User) Addresses

func (self *User) Addresses() []*Address

func (*User) Init

func (self *User) Init(ctx context.Context) error

func (*User) Keyring

func (self *User) Keyring() *crypto.KeyRing

type Volume

type Volume struct {
	// contains filtered or unexported fields
}

func (*Volume) ID

func (self *Volume) ID() string

func (*Volume) ShareID

func (self *Volume) ShareID() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL