Dropbox

WORK IN PROGRESS, NOT RECOMMENDED FOR PRODUCTION USE

Dropbox backend for RemoteStorage.js This file exposes a get/put/delete interface which is compatible with RemoteStorage.WireClient.

When remoteStorage.backend is set to ‘dropbox’, this backend will initialize and replace remoteStorage.remote with remoteStorage.dropbox.

In order to ensure compatibility with the public folder, <BaseClient.getItemURL> gets hijacked to return the Dropbox public share URL.

To use this backend, you need to specify the Dropbox app key like so

remoteStorage.setApiKeys('dropbox', {
  appKey: 'your-app-key'
});

An app key can be obtained by registering your app at https://www.dropbox.com/developers/apps

Known issues

  • Storing files larger than 150MB is not yet supported
  • Listing and deleting folders with more than 10’000 files will cause problems
  • Content-Type is not fully supported due to limitations of the Dropbox API
  • Dropbox preserves cases but is not case-sensitive
  • getItemURL is asynchronous which means getIetmURL returns useful values after the syncCycle
Summary
DropboxWORK IN PROGRESS, NOT RECOMMENDED FOR PRODUCTION USE
Functions
getDropboxPath(path)Map a local path to a path in DropBox.
LowerCaseCacheA cache which automatically converts all keys to lower case and can propagate changes up to parent folders.
Functions
getGet a value from the cache or defaultValue, if the key is not in the cache.
propagateSetSet a value and also update the parent folders with that value.
propagateDeleteDelete a value and propagate the changes to the parent folders.
justSetSet a value without propagating.
justDeleteDelete a value without propagating.
RemoteStorage.Dropbox
Functions
connectSet the backed to ‘dropbox’ and start the authentication flow in order to obtain an API token from Dropbox.
stopWaitingForTokenStop waiting for the token and emit not-connected
_getFolderGet all items in a folder.
getCompatible with <RemoteStorage.WireClient.get>
putCompatible with RemoteStorage.WireClient
deleteCompatible with <RemoteStorage.WireClient.delete>
_shareIfNeededCalls share, if the provided path resides in a public folder.
shareGets a publicly-accessible URL for the path from Dropbox and stores it in _itemRefs.
infoFetches the user’s info from dropbox and returns a promise for it.
_requestMake a HTTP request.
fetchDeltaFetches the revision of all the files from dropbox API and puts them into _revCache.
_getMetadataGets metadata for a path (can point to either a file or a folder).
_uploadSimpleUpload a simple file (the size is no more than 150MB).
_deleteSimpleDeletes a file or a folder.

Functions

getDropboxPath(path)

var getDropboxPath = function (path)

Map a local path to a path in DropBox.

LowerCaseCache

A cache which automatically converts all keys to lower case and can propagate changes up to parent folders.

By default the set and delete methods are aliased to justSet and justDelete.

Parameters

defaultValuethe value that is returned for all keys that don’t exist in the cache
Summary
Functions
getGet a value from the cache or defaultValue, if the key is not in the cache.
propagateSetSet a value and also update the parent folders with that value.
propagateDeleteDelete a value and propagate the changes to the parent folders.
justSetSet a value without propagating.
justDeleteDelete a value without propagating.

Functions

get

get : function (key)

Get a value from the cache or defaultValue, if the key is not in the cache.

propagateSet

propagateSet : function (key,
value)

Set a value and also update the parent folders with that value.

propagateDelete

propagateDelete : function (key)

Delete a value and propagate the changes to the parent folders.

justSet

justSet : function (key,
value)

Set a value without propagating.

justDelete

justDelete : function (key,
value)

Delete a value without propagating.

RemoteStorage.Dropbox

Summary
Functions
connectSet the backed to ‘dropbox’ and start the authentication flow in order to obtain an API token from Dropbox.
stopWaitingForTokenStop waiting for the token and emit not-connected
_getFolderGet all items in a folder.
getCompatible with <RemoteStorage.WireClient.get>
putCompatible with RemoteStorage.WireClient
deleteCompatible with <RemoteStorage.WireClient.delete>
_shareIfNeededCalls share, if the provided path resides in a public folder.
shareGets a publicly-accessible URL for the path from Dropbox and stores it in _itemRefs.
infoFetches the user’s info from dropbox and returns a promise for it.
_requestMake a HTTP request.
fetchDeltaFetches the revision of all the files from dropbox API and puts them into _revCache.
_getMetadataGets metadata for a path (can point to either a file or a folder).
_uploadSimpleUpload a simple file (the size is no more than 150MB).
_deleteSimpleDeletes a file or a folder.

Functions

connect

connect: function ()

Set the backed to ‘dropbox’ and start the authentication flow in order to obtain an API token from Dropbox.

stopWaitingForToken

stopWaitingForToken: function ()

Stop waiting for the token and emit not-connected

_getFolder

_getFolder: function (path,
options)

Get all items in a folder.

Parameters

pathpath of the folder to get, with leading slash
optionsnot used

Returns

statusCodeHTTP status code
bodyarray of the items found
contentType’application/json; charset=UTF-8’
revisionrevision of the folder

get

get: function (path,
options)

Compatible with <RemoteStorage.WireClient.get>

Checks for the path in _revCache and decides based on that if file has changed.  Calls _getFolder is the path points to a folder.

Calls RemoteStorage.Dropbox.share afterwards to fill _itemRefs.

put

put: function (path,
body,
contentType,
options)

Compatible with RemoteStorage.WireClient

Checks for the path in _revCache and decides based on that if file has changed.

Calls RemoteStorage.Dropbox.share afterwards to fill _itemRefs.

delete

'delete': function (path,
options)

Compatible with <RemoteStorage.WireClient.delete>

Checks for the path in _revCache and decides based on that if file has changed.

Calls RemoteStorage.Dropbox.share afterwards to fill _itemRefs.

_shareIfNeeded

_shareIfNeeded: function (path)

Calls share, if the provided path resides in a public folder.

share

share: function (path)

Gets a publicly-accessible URL for the path from Dropbox and stores it in _itemRefs.

Returns

A promise for the URL

info

info: function ()

Fetches the user’s info from dropbox and returns a promise for it.

Returns

A promise to the user’s info

_request

_request: function (method,
url,
options)

Make a HTTP request.

Options

headersan object containing the request headers

Parameters

methodthe method to use
urlthe URL to make the request to
optionssee above

fetchDelta

fetchDelta: function ()

Fetches the revision of all the files from dropbox API and puts them into _revCache.  These values can then be used to determine if something has changed.

_getMetadata

_getMetadata: function (path,
options)

Gets metadata for a path (can point to either a file or a folder).

Options

listif path points to a folder, specifies whether to list the metadata of the folder’s children.  False by default.

Parameters

paththe path to get metadata for
optionssee above

Returns

A promise for the metadata

_uploadSimple

_uploadSimple: function (params)

Upload a simple file (the size is no more than 150MB).

Parameters

ifMatchsame as for get
pathpath of the file
bodycontents of the file to upload
contentTypemime type of the file

Returns

statusCodeHTTP status code
revisionrevision of the newly-created file, if any

_deleteSimple

_deleteSimple: function (path)

Deletes a file or a folder.  If the folder contains more than 10’000 items (recursively) then the operation may not complete successfully.  If that is the case, an Error gets thrown.

Parameters

paththe path to delete

Returns

statusCodeHTTP status code
var getDropboxPath = function (path)
Map a local path to a path in DropBox.
get : function (key)
Get a value from the cache or defaultValue, if the key is not in the cache.
propagateSet : function (key,
value)
Set a value and also update the parent folders with that value.
propagateDelete : function (key)
Delete a value and propagate the changes to the parent folders.
justSet : function (key,
value)
Set a value without propagating.
justDelete : function (key,
value)
Delete a value without propagating.
connect: function ()
Set the backed to ‘dropbox’ and start the authentication flow in order to obtain an API token from Dropbox.
stopWaitingForToken: function ()
Stop waiting for the token and emit not-connected
_getFolder: function (path,
options)
Get all items in a folder.
get: function (path,
options)
Compatible with RemoteStorage.WireClient.get
put: function (path,
body,
contentType,
options)
Compatible with RemoteStorage.WireClient
WireClient Interface
'delete': function (path,
options)
Compatible with RemoteStorage.WireClient.delete
_shareIfNeeded: function (path)
Calls share, if the provided path resides in a public folder.
share: function (path)
Gets a publicly-accessible URL for the path from Dropbox and stores it in _itemRefs.
info: function ()
Fetches the user’s info from dropbox and returns a promise for it.
_request: function (method,
url,
options)
Make a HTTP request.
fetchDelta: function ()
Fetches the revision of all the files from dropbox API and puts them into _revCache.
_getMetadata: function (path,
options)
Gets metadata for a path (can point to either a file or a folder).
_uploadSimple: function (params)
Upload a simple file (the size is no more than 150MB).
_deleteSimple: function (path)
Deletes a file or a folder.
Close