Documentation
¶
Overview ¶
Package node represents the Amazon Cloud Drive nodes documented at https://developer.amazon.com/public/apis/experience/cloud-drive/content/nodes It also provides the Tree struct which allows you to refer to the entire filesystem as a file tree as defined by the Amazon documentation.
Index ¶
- Constants
- Variables
- type ContentProperties
- type Node
- func (n *Node) Count() uint64
- func (n *Node) GetOwnerProperties() (Property, bool)
- func (n *Node) GetOwnerProperty(key string) (string, bool)
- func (n *Node) IsAsset() bool
- func (n *Node) IsAvailable() bool
- func (n *Node) IsDir() bool
- func (n *Node) IsFile() bool
- func (n *Node) Lock()
- func (n *Node) ModTime() time.Time
- func (n *Node) RLock()
- func (n *Node) RUnlock()
- func (n *Node) SetOwnerProperties(prop Property)
- func (n *Node) Size() uint64
- func (n *Node) Unlock()
- type NodeKind
- type NodeStatus
- type Nodes
- type Property
- type Tree
- func (nt *Tree) Close() error
- func (nt *Tree) CreateFolder(n *Node, name string, labels []string, properties Property) (*Node, error)
- func (nt *Tree) Download(n *Node) (io.ReadCloser, error)
- func (nt *Tree) FindById(id string) (*Node, error)
- func (nt *Tree) FindNode(path string) (*Node, error)
- func (nt *Tree) Lock()
- func (nt *Tree) MkDirAll(path string) (*Node, error)
- func (nt *Tree) Overwrite(n *Node, labels []string, properties Property, r io.Reader) error
- func (nt *Tree) Patch(n *Node, labels []string, properties Property) error
- func (nt *Tree) RLock()
- func (nt *Tree) RUnlock()
- func (nt *Tree) RemoveNode(n *Node) error
- func (nt *Tree) Sync() error
- func (nt *Tree) Unlock()
- func (nt *Tree) Upload(parent *Node, name string, labels []string, properties Property, r io.Reader) (*Node, error)
Constants ¶
const ( // NodePropertyKeysMaxCount is the maximum allowed node property keys NodePropertyKeysMaxCount = 10 // NodePropertyKeyMaxSize is the maximum size of a node property key NodePropertyKeyMaxSize = 50 // NodePropertyKeyCheckRegex is the matching pattern for node property keys NodePropertyKeyCheckRegex = "^[a-zA-Z0-9_]*$" // NodePropertyValueMaxSize is the maximum size of a node property key's value NodePropertyValueMaxSize = 500 )
Variables ¶
var ( // Mocked is a valid tree (mock). The Ids are the fully-qualified path of // the file or folder to make testing easier. // / // |-- README.md // |-- pictures // |-- | // | -- logo.png Mocked = &Tree{ Node: rootNode, nodeIdMap: map[string]*Node{ "/": rootNode, "/README.md": rootNode.Nodes["readme.md"], "/pictures": rootNode.Nodes["pictures"], "/pictures/logo.png": rootNode.Nodes["pictures"].Nodes["logo.png"], }, } )
Functions ¶
This section is empty.
Types ¶
type ContentProperties ¶
type ContentProperties struct {
// content version of the file (number)
Version uint64 `json:"version,omitempty"`
// md5 of a file content in HEX representation. (string)
Extension string `json:"extension,omitempty"`
// byte size (number, positive integer)
Size uint64 `json:"size,omitempty"`
// Media Type defined as per RFC 2046 (string)
MD5 string `json:"md5,omitempty"`
// file extension (not including the '.') (string)
ContentType string `json:"contentType,omitempty"`
// date extracted from media types (images and videos) (ISO8601 date with timezone offset)
ContentDate time.Time `json:"contentDate,omitempty"`
}
ContentProperties hold the properties of the node.
type Node ¶
type Node struct {
// Coming from Amazon
// etag of node
ETagResponse string `json:"eTagResponse,omitempty"`
// unique identifier of a file
Id string `json:"id,omitempty"`
// user friendly name of a file
Name string `json:"name,omitempty"`
// literal string "FILE", "FOLDER", "ASSET"
Kind NodeKind `json:"kind,omitempty"`
// metadata version of the file
Version uint64 `json:"version,omitempty"`
// Last modified date (ISO8601 date with timezone offset)
ModifiedDate time.Time `json:"modifiedDate,omitempty"`
// First uploaded date (ISO8601 date with timezone offset)
CreatedDate time.Time `json:"createdDate,omitempty"`
// List of Strings that are labeled to the file. Each label Max 256 characters. Max 10 labels.
Labels []string `json:"labels,omitempty"`
// short description of the file. Max 500 characters.
Description string `json:"description,omitempty"`
// Friendly name of Application Id which created the file
CreatedBy string `json:"createdBy,omitempty"`
// List of parent folder Ids
Parents []string `json:"Parents,omitempty"`
// either "AVAILABLE", "TRASH", "PURGED"
Status NodeStatus `json:"status,omitempty"`
// Extra properties which client wants to add to a node. Properties will be grouped together by the owner application Id
// which created them. By default, all properties will be restricted to its owner and no one else can read/write/delete
// them. As of now, only 10 properties can be stored by each owner. This is how properties would look inside a Node:
// {"owner_app_id1" : {"key":"value", "key2","value2"}, "owner_app_id2" : {"foo":"bar"}, "owner_app_id3": { "key":"value", "key":"value", ...} }
Properties map[string]*nodeProperty `json:"properties,omitempty"`
// indicates whether the file is restricted to that app only or accessible to all the applications
Restricted bool `json:"restricted,omitempty"`
// indicates whether the folder is a root folder or not
IsRoot bool `json:"isRoot,omitempty"`
IsShared bool `json:"isShared,omitempty"`
// Files Only
// Pre authenticated link enables viewing the file content for limited times only; has to be specifically requested
TempLink string `json:"tempLink,omitempty"`
ContentProperties ContentProperties `json:"contentProperties,omitempty"`
// Internal - exported in order to support gob encode/decode
Nodes Nodes `json:"nodes,omitempty"`
// contains filtered or unexported fields
}
Node represents a digital asset on the Amazon Cloud Drive, including files and folders, in a parent-child relationship. A node contains only metadata (e.g. folder) or it contains metadata and content (e.g. file). https://developer.amazon.com/docs/amazon-drive/ad-restful-api-nodes.html
func (*Node) GetOwnerProperties ¶
func (*Node) IsAvailable ¶
IsAvailable returns true if the node is available
func (*Node) SetOwnerProperties ¶
type NodeStatus ¶
type NodeStatus string
const ( StatusAvailable NodeStatus = "AVAILABLE" StatusTrash NodeStatus = "TRASH" StatusPurged NodeStatus = "PURGED" )
type Property ¶
type Property interface {
Clone() Property
Get(key string) (string, bool)
GetAll() map[string]string
Has(key string) bool
Remove(key string)
RemoveAll(keys []string)
Set(key, value string) error
SetAll(props map[string]string) []error
Size() int
GobEncode() ([]byte, error)
GobDecode(data []byte) error
MarshalJSON() ([]byte, error)
UnmarshalJSON(data []byte) error
}
Property implements the Node Properties field per the API. https://developer.amazon.com/docs/amazon-drive/ad-restful-api-nodes.html#properties-1
func NewProperty ¶
func NewProperty() Property
type Tree ¶
type Tree struct {
// Exported in order to support gob encode/decode
*Node
LastUpdated time.Time
Checkpoint string
// contains filtered or unexported fields
}
Tree represents a node tree.
func (*Tree) CreateFolder ¶
func (nt *Tree) CreateFolder(n *Node, name string, labels []string, properties Property) (*Node, error)
CreateFolder creates the named folder under the node
func (*Tree) Download ¶
func (nt *Tree) Download(n *Node) (io.ReadCloser, error)
Download downloads the node and returns the body as io.ReadCloser or an error. The caller is responsible for closing the reader.
func (*Tree) FindNode ¶
FindNode finds a node for a particular path. TODO(kalbasit): This does not perform well, this should be cached in a map path->node and calculated on load (fresh, cache, refresh).
func (*Tree) MkDirAll ¶
MkdirAll creates a directory named path, along with any necessary parents, and returns the directory node and nil, or else returns an error. If path is already a directory, MkDirAll does nothing and returns the directory node and nil.
func (*Tree) RemoveNode ¶
RemoveNode removes this node from the server and from the NodeTree.