node

package
v0.1.0-beta4 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 16 Imported by: 0

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

View Source
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

View Source
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"`
	// set if node is shared
	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 New

func New() *Node

func (*Node) Count

func (n *Node) Count() uint64

func (*Node) GetOwnerProperties

func (n *Node) GetOwnerProperties() (Property, bool)

func (*Node) GetOwnerProperty

func (n *Node) GetOwnerProperty(key string) (string, bool)

func (*Node) IsAsset

func (n *Node) IsAsset() bool

IsAsset returns whether the node represents an asset.

func (*Node) IsAvailable

func (n *Node) IsAvailable() bool

IsAvailable returns true if the node is available

func (*Node) IsDir

func (n *Node) IsDir() bool

IsDir returns whether the node represents a folder.

func (*Node) IsFile

func (n *Node) IsFile() bool

IsFile returns whether the node represents a file.

func (*Node) Lock

func (n *Node) Lock()

func (*Node) ModTime

func (n *Node) ModTime() time.Time

ModTime returns the last modified time of the node.

func (*Node) RLock

func (n *Node) RLock()

func (*Node) RUnlock

func (n *Node) RUnlock()

func (*Node) SetOwnerProperties

func (n *Node) SetOwnerProperties(prop Property)

func (*Node) Size

func (n *Node) Size() uint64

Size returns the size of the node.

func (*Node) Unlock

func (n *Node) Unlock()

type NodeKind

type NodeKind string
const (
	KindFile   NodeKind = "FILE"
	KindFolder NodeKind = "FOLDER"
	KindAsset  NodeKind = "ASSET"
)

type NodeStatus

type NodeStatus string
const (
	StatusAvailable NodeStatus = "AVAILABLE"
	StatusTrash     NodeStatus = "TRASH"
	StatusPurged    NodeStatus = "PURGED"
)

type Nodes

type Nodes map[string]*Node

Nodes is a slice of nodes

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 NewTree

func NewTree(c client, cacheFile string, chunkSize int, syncInterval time.Duration) (*Tree, error)

NewTree returns the root node (the head of the tree).

func (*Tree) Close

func (nt *Tree) Close() error

Close finalizes the NodeTree

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) FindById

func (nt *Tree) FindById(id string) (*Node, error)

FindById returns the node identified by the Id.

func (*Tree) FindNode

func (nt *Tree) FindNode(path string) (*Node, error)

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) Lock

func (nt *Tree) Lock()

func (*Tree) MkDirAll

func (nt *Tree) MkDirAll(path string) (*Node, error)

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) Overwrite

func (nt *Tree) Overwrite(n *Node, labels []string, properties Property, r io.Reader) error

Overwrite writes contents of r as name inside the current node.

func (*Tree) Patch

func (nt *Tree) Patch(n *Node, labels []string, properties Property) error

Patch updates metadata for the provided node.

func (*Tree) RLock

func (nt *Tree) RLock()

func (*Tree) RUnlock

func (nt *Tree) RUnlock()

func (*Tree) RemoveNode

func (nt *Tree) RemoveNode(n *Node) error

RemoveNode removes this node from the server and from the NodeTree.

func (*Tree) Sync

func (nt *Tree) Sync() error

Sync syncs the tree with the server.

func (*Tree) Unlock

func (nt *Tree) Unlock()

func (*Tree) Upload

func (nt *Tree) Upload(parent *Node, name string, labels []string, properties Property, r io.Reader) (*Node, error)

Upload writes contents of r as name inside the current node.

Jump to

Keyboard shortcuts

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