mega

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiURL              = "https://g.api.mega.co.nz/cs"
	HandleLen           = 8
	FolderNodeKeyB64Len = 22
	FileNodeKeyB64Len   = 43
)

Variables

View Source
var ErrDecryptAttr = errors.New("decrypt mega attribute failed")
View Source
var ErrInvalidKeyLen = errors.New("invalid mega key")
View Source
var ErrInvalidNodeType = errors.New("invalid mega node type")

Functions

func CalcAesCTRIV

func CalcAesCTRIV(iv []byte, off uint64) []byte

func NewAesCTRStream

func NewAesCTRStream(blk cipher.Block, iv []byte, off uint64) (ctr cipher.Stream)

Types

type ApiErr

type ApiErr int
const (
	API_OK                  ApiErr = 0
	API_EINTERNAL           ApiErr = -1  // internal error
	API_EARGS               ApiErr = -2  // bad arguments
	API_EAGAIN              ApiErr = -3  // request failed retry with exponential backoff
	API_ERATELIMIT          ApiErr = -4  // too many requests slow down
	API_EFAILED             ApiErr = -5  // request failed permanently
	API_ETOOMANY            ApiErr = -6  // too many requests for this resource
	API_ERANGE              ApiErr = -7  // resource access out of rage
	API_EEXPIRED            ApiErr = -8  // resource expired
	API_ENOENT              ApiErr = -9  // resource does not exist
	API_ECIRCULAR           ApiErr = -10 // circular linkage
	API_EACCESS             ApiErr = -11 // access denied
	API_EEXIST              ApiErr = -12 // resource already exists
	API_EINCOMPLETE         ApiErr = -13 // request incomplete
	API_EKEY                ApiErr = -14 // cryptographic error
	API_ESID                ApiErr = -15 // bad session ID
	API_EBLOCKED            ApiErr = -16 // resource administratively blocked
	API_EOVERQUOTA          ApiErr = -17 // quote exceeded
	API_ETEMPUNAVAIL        ApiErr = -18 // resource temporarily not available
	API_ETOOMANYCONNECTIONS ApiErr = -19 // too many connections on this resource
	API_EWRITE              ApiErr = -20 // file could not be written to
	API_EREAD               ApiErr = -21 // file could not be read from
	API_EAPPKEY             ApiErr = -22 // invalid or missing application key
	API_ESSL                ApiErr = -23 // SSL verification failed
	API_EGOINGOVERQUOTA     ApiErr = -24 // Not enough quota
	API_EMFAREQUIRED        ApiErr = -26 // Multi-factor authentication required
)

from MEGA office sdk MError.h

func (ApiErr) Error

func (e ApiErr) Error() string

func (ApiErr) Message

func (e ApiErr) Message() string

type Attribute

type Attribute struct {
	Name string `json:"n"`
}

type Client

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

func NewClient

func NewClient(client *http.Client) *Client

func (*Client) Download

func (c *Client) Download(info *NodeInfo, opt DownloadOption) (dl *Download, err error)

func (*Client) GetPublicFileNodeInfo

func (c *Client) GetPublicFileNodeInfo(publicHandle, nodeHandle string, nodeKey string) (info *NodeInfo, err error)

func (*Client) OpenPublicFolder

func (c *Client) OpenPublicFolder(handle, key string) (fm *FM, err error)

type Download

type Download struct {
	Range struct {
		S     int64
		E     int64
		Total int64
	}
	Http struct {
		Status     string
		StatusCode int
		Header     http.Header
	}
	// contains filtered or unexported fields
}

func (*Download) Close

func (d *Download) Close() error

func (*Download) Read

func (d *Download) Read(p []byte) (n int, err error)

type DownloadOption

type DownloadOption func(*http.Request) error

func NewDownloadOption

func NewDownloadOption() DownloadOption

func (DownloadOption) HttpHeader

func (d DownloadOption) HttpHeader(k, v string) DownloadOption

func (DownloadOption) Range

func (d DownloadOption) Range(s, e int64) DownloadOption

http range

type EncryptedNode

type EncryptedNode struct {
	H  string   `json:"h"`
	P  string   `json:"p"`
	U  string   `json:"u"`
	K  string   `json:"k"`
	Ts int64    `json:"ts"`
	S  int64    `json:"s"`
	A  string   `json:"a"`
	T  NodeType `json:"t"`
}

type FM

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

func (*FM) GetFileNodeInfo

func (fm *FM) GetFileNodeInfo(n *Node) (info *NodeInfo, err error)

func (*FM) Lookup

func (fm *FM) Lookup(handle string) *Node

func (*FM) LookupPath

func (fm *FM) LookupPath(p string) *Node

func (*FM) Walk

func (fm *FM) Walk(walker func(*Node) bool)

type HttpStatusErr

type HttpStatusErr int

func (HttpStatusErr) Error

func (e HttpStatusErr) Error() string

type Node

type Node struct {
	Handle    string
	Owner     string
	Parent    string
	Children  []*Node
	Type      NodeType
	Timestamp int64
	Size      int64
	Attr      Attribute
	K         NodeKey
}

func (*Node) Walk

func (n *Node) Walk(walker func(*Node) bool) bool

type NodeInfo

type NodeInfo struct {
	Size int64
	Attr Attribute
	K    NodeKey
	URL  string
}

type NodeInfoReq

type NodeInfoReq struct {
	A   string `json:"a"`
	G   int    `json:"g"`
	SSL int    `json:"ssl"`         // use https
	P   string `json:"p,omitempty"` // public handle
	N   string `json:"n,omitempty"` // node handle
}

type NodeInfoResp

type NodeInfoResp struct {
	S   int64  `json:"s"`
	At  string `json:"at"`
	URL string `json:"g"`
}

type NodeKey

type NodeKey struct {
	Key []byte
	IV  []byte
	Mac []byte
}

type NodeType

type NodeType int32
const (
	TypeFile NodeType = iota
	TypeFolder
	TypeCloudDrive
	TypeInbox
	TypeTrashBin
)

type NodesReq

type NodesReq struct {
	A  string `json:"a"`
	C  int    `json:"c"`
	R  int    `json:"r"`  //recursive?
	CA int    `json:"ca"` //cache?
}

from official web client mega.js treefetcher_fetch

type NodesResp

type NodesResp struct {
	F  []EncryptedNode `json:"f"`
	SN string          `json:"sn"`
}

Jump to

Keyboard shortcuts

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