diff --git a/ChangeLog b/ChangeLog index 6b679ec2..f951d2f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -43,6 +43,9 @@ writed root directory. * Changed sync reading of certs to async. +* Updated dropbox to v0.9.2 and moved to packege.json +from storage folder. + 2012.03.01, Version 0.1.9 diff --git a/html/auth/dropbox.html b/html/auth/dropbox.html index cc702b56..51478866 100644 --- a/html/auth/dropbox.html +++ b/html/auth/dropbox.html @@ -1,7 +1,7 @@
- + -``` - -The snippet is not a typo. [cdnjs](https://cdnjs.com) recommends using -[protocol-relative URLs](http://paulirish.com/2010/the-protocol-relative-url/). - -To get the latest development build of dropbox.js, follow the steps in the -[development guide](https://github.com/dropbox/dropbox-js/blob/master/doc/development.md). - - -#### "Powered by Dropbox" Static Web Apps - -Before writing any source code, use the -[console app](https://dl-web.dropbox.com/spa/pjlfdak1tmznswp/powered_by.js/public/index.html) -to set up your Dropbox. After adding an application, place the source code at -`/Apps/Static Web Apps/my_awesome_app/public`. You should find a pre-generated -`index.html` file in there. - -### node.js Applications - -First, install the `dropbox` [npm](https://npmjs.org/) package. - -```bash -npm install dropbox -``` - -Once the npm package is installed, the following `require` statement lets you -access the same API as browser applications - -```javascript -var Dropbox = require("dropbox"); -``` - - -## Initialization - -[Register your application](https://www.dropbox.com/developers/apps) to obtain -an API key. Read the brief -[API core concepts intro](https://www.dropbox.com/developers/start/core). - -Once you have an API key, use it to create a `Dropbox.Client`. - -```javascript -var client = new Dropbox.Client({ - key: "your-key-here", secret: "your-secret-here", sandbox: true -}); -``` - -If your application requires full Dropbox access, leave out the `sandbox: true` -parameter. - - -### Browser and Open-Source Applications - -The Dropbox API guidelines ask that the API key and secret is never exposed in -cleartext. This is an issue for browser-side and open-source applications. - -To meet this requirement, -[encode your API key](https://dl-web.dropbox.com/spa/pjlfdak1tmznswp/api_keys.js/public/index.html) -and pass the encoded key string to the `Dropbox.Client` constructor. - -```javascript -var client = new Dropbox.Client({ - key: "encoded-key-string|it-is-really-really-long", sandbox: true -}); -``` - - -## Authentication - -Before you can make any API calls, you need to authenticate your application's -user with Dropbox, and have them authorize your app's to access their Dropbox. - -This process follows the [OAuth 1.0](http://tools.ietf.org/html/rfc5849) -protocol, which entails sending the user to a Web page on `www.dropbox.com`, -and then having them redirected back to your application. Each Web application -has its requirements, so `dropbox.js` lets you customize the authentication -process by implementing an -[OAuth driver](https://github.com/dropbox/dropbox-js/blob/master/src/drivers.coffee). - -At the same time, dropbox.js ships with a couple of OAuth drivers, and you -should take advantage of them as you prototype your application. - -Read the -[authentication doc](https://github.com/dropbox/dropbox-js/blob/master/doc/auth_drivers.md) -for further information about writing an OAuth driver, and to learn about all -the drivers that ship with `dropbox.js`. - -### Browser Setup - -The following snippet will set up the recommended driver. - -```javascript -client.authDriver(new Dropbox.Drivers.Redirect()); -``` - -The -[authentication doc](https://github.com/dropbox/dropbox-js/blob/master/doc/auth_drivers.md) -describes some useful options that you can pass to the -`Dropbox.Drivers.Redirect` constructor. - -### node.js Setup - -Single-process node.js applications should create one driver to authenticate -all the clients. - -```javascript -client.authDriver(new Dropbox.Drivers.NodeServer(8191)); -``` - -The -[authentication doc](https://github.com/dropbox/dropbox-js/blob/master/doc/auth_drivers.md) -has useful tips on using the `NodeServer` driver. - -### Shared Code - -After setting up an OAuth driver, authenticating the user is one method call -away. - -```javascript -client.authenticate(function(error, client) { - if (error) { - // Replace with a call to your own error-handling code. - // - // Don't forget to return from the callback, so you don't execute the code - // that assumes everything went well. - return showError(error); - } - - // Replace with a call to your own application code. - // - // The user authorized your app, and everything went well. - // client is a Dropbox.Client instance that you can use to make API calls. - doSomethingCool(client); -}); -``` - -## Error Handlng - -When Dropbox API calls fail, dropbox.js methods pass a `Dropbox.ApiError` -instance as the first parameter in their callbacks. This parameter is named -`error` in all the code snippets on this page. - -If `error` is a truthy value, you should either recover from the error, or -notify the user that an error occurred. The `status` field in the -`Dropbox.ApiError` instance contains the HTTP error code, which should be one -of the -[error codes in the REST API](https://www.dropbox.com/developers/reference/api#error-handling). - -The snippet below is a template for an extensive error handler. - -```javascript -var showError = function(error) { - switch (error.status) { - case 401: - // If you're using dropbox.js, the only cause behind this error is that - // the user token expired. - // Get the user through the authentication flow again. - break; - - case 404: - // The file or folder you tried to access is not in the user's Dropbox. - // Handling this error is specific to your application. - break; - - case 507: - // The user is over their Dropbox quota. - // Tell them their Dropbox is full. Refreshing the page won't help. - break; - - case 503: - // Too many API requests. Tell the user to try again later. - // Long-term, optimize your code to use fewer API calls. - break; - - case 400: // Bad input parameter - case 403: // Bad OAuth request. - case 405: // Request method not expected - default: - // Caused by a bug in dropbox.js, in your application, or in Dropbox. - // Tell the user an error occurred, ask them to refresh the page. - } -}; -``` - -`Dropbox.Client` also supports a DOM event-like API for receiving all errors. -This can be used to log API errors, or to upload them to your server for -further analysis. - -```javascript -client.onError.addListener(function(error) { - if (window.console) { // Skip the "if" in node.js code. - console.error(error); - } -}); -``` - - -## The Fun Part - -Authentication was the hard part of the API integration, and error handling was -the most boring part. Now that these are both behind us, you can interact -with the user's Dropbox and focus on coding up your application! - -The following sections have some commonly used code snippets. The -[Dropbox.Client API reference](http://coffeedoc.info/github/dropbox/dropbox-js/master/classes/Dropbox/Client.html) -will help you navigate less common scenarios, and the -[Dropbox REST API reference](https://www.dropbox.com/developers/reference/api) -describes the underlying HTTP protocol, and can come in handy when debugging -your application, or if you want to extend dropbox.js. - -### User Info - -```javascript -client.getUserInfo(function(error, userInfo) { - if (error) { - return showError(error); // Something went wrong. - } - - alert("Hello, " + userInfo.name + "!"); -}); -``` - -### Write a File - -```javascript -client.writeFile("hello_world.txt", "Hello, world!\n", function(error, stat) { - if (error) { - return showError(error); // Something went wrong. - } - - alert("File saved as revision " + stat.revisionTag); -}); -``` - -### Read a File - -```javascript -client.readFile("hello_world.txt", function(error, data) { - if (error) { - return showError(error); // Something went wrong. - } - - alert(data); // data has the file's contents -}); -``` - -### List a Directory's Contents - -```javascript -client.readdir("/", function(error, entries) { - if (error) { - return showError(error); // Something went wrong. - } - - alert("Your Dropbox contains " + entries.join(", ")); -}); -``` - -### Sample Applications - -Check out the -[sample apps](https://github.com/dropbox/dropbox-js/tree/master/samples) -to see how all these concepts play out together. - diff --git a/lib/client/storage/dropbox/lib/README.md b/lib/client/storage/dropbox/lib/README.md deleted file mode 100644 index 6a273731..00000000 --- a/lib/client/storage/dropbox/lib/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# dropbox.js Build Directory - -dropbox.js is written in [CoffeeScript](http://coffeescript.org/), and its -source code is in the `src/` directory. The `lib/` directory contains the -compiled JavaScript produced by the build process. - -The -[development guide](https://github.com/dropbox/dropbox-js/blob/master/doc/development.md) -contains a step-by-step guide to the library's build process, and will help you -populate this directory. diff --git a/lib/client/storage/dropbox/lib/dropbox.js b/lib/client/storage/dropbox/lib/dropbox.js deleted file mode 100644 index 05a073aa..00000000 --- a/lib/client/storage/dropbox/lib/dropbox.js +++ /dev/null @@ -1,2925 +0,0 @@ -// Generated by CoffeeScript 1.4.0 -(function() { - var Dropbox, DropboxChromeOnMessage, DropboxChromeSendMessage, DropboxClient, DropboxXhrArrayBufferView, DropboxXhrCanSendForms, DropboxXhrDoesPreflight, DropboxXhrIeMode, DropboxXhrRequest, DropboxXhrSendArrayBufferView, add32, arrayToBase64, atob, atobNibble, base64Digits, base64HmacSha1, base64Sha1, btoa, btoaNibble, crypto, dropboxEncodeKey, hmacSha1, rotateLeft32, sha1, stringToArray, _base64Digits, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - - Dropbox = (function() { - - function Dropbox(options) { - this.client = new DropboxClient(options); - } - - return Dropbox; - - })(); - - Dropbox.ApiError = (function() { - - ApiError.prototype.status = void 0; - - ApiError.prototype.method = void 0; - - ApiError.prototype.url = void 0; - - ApiError.prototype.responseText = void 0; - - ApiError.prototype.response = void 0; - - function ApiError(xhr, method, url) { - var text; - this.method = method; - this.url = url; - this.status = xhr.status; - if (xhr.responseType) { - try { - text = xhr.response || xhr.responseText; - } catch (e) { - try { - text = xhr.responseText; - } catch (e) { - text = null; - } - } - } else { - try { - text = xhr.responseText; - } catch (e) { - text = null; - } - } - if (text) { - try { - this.responseText = text.toString(); - this.response = JSON.parse(text); - } catch (e) { - this.response = null; - } - } else { - this.responseText = '(no response)'; - this.response = null; - } - } - - ApiError.prototype.toString = function() { - return "Dropbox API error " + this.status + " from " + this.method + " " + this.url + " :: " + this.responseText; - }; - - ApiError.prototype.inspect = function() { - return this.toString(); - }; - - return ApiError; - - })(); - - if (typeof window !== "undefined" && window !== null) { - if (window.atob && window.btoa) { - atob = function(string) { - return window.atob(string); - }; - btoa = function(base64) { - return window.btoa(base64); - }; - } else { - base64Digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - btoaNibble = function(accumulator, bytes, result) { - var i, limit; - limit = 3 - bytes; - accumulator <<= limit * 8; - i = 3; - while (i >= limit) { - result.push(base64Digits.charAt((accumulator >> (i * 6)) & 0x3F)); - i -= 1; - } - i = bytes; - while (i < 3) { - result.push('='); - i += 1; - } - return null; - }; - atobNibble = function(accumulator, digits, result) { - var i, limit; - limit = 4 - digits; - accumulator <<= limit * 6; - i = 2; - while (i >= limit) { - result.push(String.fromCharCode((accumulator >> (8 * i)) & 0xFF)); - i -= 1; - } - return null; - }; - btoa = function(string) { - var accumulator, bytes, i, result, _i, _ref; - result = []; - accumulator = 0; - bytes = 0; - for (i = _i = 0, _ref = string.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - accumulator = (accumulator << 8) | string.charCodeAt(i); - bytes += 1; - if (bytes === 3) { - btoaNibble(accumulator, bytes, result); - accumulator = bytes = 0; - } - } - if (bytes > 0) { - btoaNibble(accumulator, bytes, result); - } - return result.join(''); - }; - atob = function(base64) { - var accumulator, digit, digits, i, result, _i, _ref; - result = []; - accumulator = 0; - digits = 0; - for (i = _i = 0, _ref = base64.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - digit = base64.charAt(i); - if (digit === '=') { - break; - } - accumulator = (accumulator << 6) | base64Digits.indexOf(digit); - digits += 1; - if (digits === 4) { - atobNibble(accumulator, digits, result); - accumulator = digits = 0; - } - } - if (digits > 0) { - atobNibble(accumulator, digits, result); - } - return result.join(''); - }; - } - } else { - atob = function(arg) { - var buffer, i; - buffer = new Buffer(arg, 'base64'); - return ((function() { - var _i, _ref, _results; - _results = []; - for (i = _i = 0, _ref = buffer.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - _results.push(String.fromCharCode(buffer[i])); - } - return _results; - })()).join(''); - }; - btoa = function(arg) { - var buffer, i; - buffer = new Buffer((function() { - var _i, _ref, _results; - _results = []; - for (i = _i = 0, _ref = arg.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - _results.push(arg.charCodeAt(i)); - } - return _results; - })()); - return buffer.toString('base64'); - }; - } - - Dropbox.Client = (function() { - - function Client(options) { - this.sandbox = options.sandbox || false; - this.apiServer = options.server || this.defaultApiServer(); - this.authServer = options.authServer || this.defaultAuthServer(); - this.fileServer = options.fileServer || this.defaultFileServer(); - this.downloadServer = options.downloadServer || this.defaultDownloadServer(); - this.onXhr = new Dropbox.EventSource({ - cancelable: true - }); - this.onError = new Dropbox.EventSource; - this.onAuthStateChange = new Dropbox.EventSource; - this.oauth = new Dropbox.Oauth(options); - this.driver = null; - this.filter = null; - this.uid = null; - this.authState = null; - this.authError = null; - this._credentials = null; - this.setCredentials(options); - this.setupUrls(); - } - - Client.prototype.authDriver = function(driver) { - this.driver = driver; - return this; - }; - - Client.prototype.onXhr = null; - - Client.prototype.onError = null; - - Client.prototype.onAuthStateChange = null; - - Client.prototype.dropboxUid = function() { - return this.uid; - }; - - Client.prototype.credentials = function() { - if (!this._credentials) { - this.computeCredentials(); - } - return this._credentials; - }; - - Client.prototype.authenticate = function(callback) { - var oldAuthState, _fsmStep, - _this = this; - oldAuthState = null; - if (!(this.driver || this.authState === DropboxClient.DONE)) { - throw new Error("Call authDriver to set an authentication driver"); - } - _fsmStep = function() { - var authUrl; - if (oldAuthState !== _this.authState) { - if (oldAuthState !== null) { - _this.onAuthStateChange.dispatch(_this); - } - oldAuthState = _this.authState; - if (_this.driver && _this.driver.onAuthStateChange) { - return _this.driver.onAuthStateChange(_this, _fsmStep); - } - } - switch (_this.authState) { - case DropboxClient.RESET: - return _this.requestToken(function(error, data) { - var token, tokenSecret; - if (error) { - _this.authError = error; - _this.authState = DropboxClient.ERROR; - } else { - token = data.oauth_token; - tokenSecret = data.oauth_token_secret; - _this.oauth.setToken(token, tokenSecret); - _this.authState = DropboxClient.REQUEST; - } - _this._credentials = null; - return _fsmStep(); - }); - case DropboxClient.REQUEST: - authUrl = _this.authorizeUrl(_this.oauth.token); - return _this.driver.doAuthorize(authUrl, _this.oauth.token, _this.oauth.tokenSecret, function() { - _this.authState = DropboxClient.AUTHORIZED; - _this._credentials = null; - return _fsmStep(); - }); - case DropboxClient.AUTHORIZED: - return _this.getAccessToken(function(error, data) { - if (error) { - _this.authError = error; - _this.authState = DropboxClient.ERROR; - } else { - _this.oauth.setToken(data.oauth_token, data.oauth_token_secret); - _this.uid = data.uid; - _this.authState = DropboxClient.DONE; - } - _this._credentials = null; - return _fsmStep(); - }); - case DropboxClient.DONE: - return callback(null, _this); - case DropboxClient.SIGNED_OFF: - _this.authState = DropboxClient.RESET; - _this.reset(); - return _fsmStep(); - case DropboxClient.ERROR: - return callback(_this.authError); - } - }; - _fsmStep(); - return this; - }; - - Client.prototype.isAuthenticated = function() { - return this.authState === DropboxClient.DONE; - }; - - Client.prototype.signOut = function(callback) { - var xhr, - _this = this; - xhr = new Dropbox.Xhr('POST', this.urls.signOut); - xhr.signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error) { - if (error) { - return callback(error); - } - _this.authState = DropboxClient.RESET; - _this.reset(); - _this.authState = DropboxClient.SIGNED_OFF; - _this.onAuthStateChange.dispatch(_this); - if (_this.driver.onAuthStateChange) { - return _this.driver.onAuthStateChange(_this, function() { - return callback(error); - }); - } else { - return callback(error); - } - }); - }; - - Client.prototype.signOff = function(callback) { - return this.signOut(callback); - }; - - Client.prototype.getUserInfo = function(options, callback) { - var httpCache, xhr; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - httpCache = false; - if (options && options.httpCache) { - httpCache = true; - } - xhr = new Dropbox.Xhr('GET', this.urls.accountInfo); - xhr.signWithOauth(this.oauth, httpCache); - return this.dispatchXhr(xhr, function(error, userData) { - return callback(error, Dropbox.UserInfo.parse(userData), userData); - }); - }; - - Client.prototype.readFile = function(path, options, callback) { - var httpCache, params, rangeEnd, rangeHeader, rangeStart, responseType, xhr; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - params = {}; - responseType = null; - rangeHeader = null; - httpCache = false; - if (options) { - if (options.versionTag) { - params.rev = options.versionTag; - } else if (options.rev) { - params.rev = options.rev; - } - if (options.arrayBuffer) { - responseType = 'arraybuffer'; - } else if (options.blob) { - responseType = 'blob'; - } else if (options.binary) { - responseType = 'b'; - } - if (options.length) { - if (options.start != null) { - rangeStart = options.start; - rangeEnd = options.start + options.length - 1; - } else { - rangeStart = ''; - rangeEnd = options.length; - } - rangeHeader = "bytes=" + rangeStart + "-" + rangeEnd; - } else if (options.start != null) { - rangeHeader = "bytes=" + options.start + "-"; - } - if (options.httpCache) { - httpCache = true; - } - } - xhr = new Dropbox.Xhr('GET', "" + this.urls.getFile + "/" + (this.urlEncodePath(path))); - xhr.setParams(params).signWithOauth(this.oauth, httpCache); - xhr.setResponseType(responseType); - if (rangeHeader) { - xhr.setHeader('Range', rangeHeader); - } - return this.dispatchXhr(xhr, function(error, data, metadata) { - return callback(error, data, Dropbox.Stat.parse(metadata)); - }); - }; - - Client.prototype.writeFile = function(path, data, options, callback) { - var useForm; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - useForm = Dropbox.Xhr.canSendForms && typeof data === 'object'; - if (useForm) { - return this.writeFileUsingForm(path, data, options, callback); - } else { - return this.writeFileUsingPut(path, data, options, callback); - } - }; - - Client.prototype.writeFileUsingForm = function(path, data, options, callback) { - var fileName, params, slashIndex, xhr; - slashIndex = path.lastIndexOf('/'); - if (slashIndex === -1) { - fileName = path; - path = ''; - } else { - fileName = path.substring(slashIndex); - path = path.substring(0, slashIndex); - } - params = { - file: fileName - }; - if (options) { - if (options.noOverwrite) { - params.overwrite = 'false'; - } - if (options.lastVersionTag) { - params.parent_rev = options.lastVersionTag; - } else if (options.parentRev || options.parent_rev) { - params.parent_rev = options.parentRev || options.parent_rev; - } - } - xhr = new Dropbox.Xhr('POST', "" + this.urls.postFile + "/" + (this.urlEncodePath(path))); - xhr.setParams(params).signWithOauth(this.oauth).setFileField('file', fileName, data, 'application/octet-stream'); - delete params.file; - return this.dispatchXhr(xhr, function(error, metadata) { - return callback(error, Dropbox.Stat.parse(metadata)); - }); - }; - - Client.prototype.writeFileUsingPut = function(path, data, options, callback) { - var params, xhr; - params = {}; - if (options) { - if (options.noOverwrite) { - params.overwrite = 'false'; - } - if (options.lastVersionTag) { - params.parent_rev = options.lastVersionTag; - } else if (options.parentRev || options.parent_rev) { - params.parent_rev = options.parentRev || options.parent_rev; - } - } - xhr = new Dropbox.Xhr('POST', "" + this.urls.putFile + "/" + (this.urlEncodePath(path))); - xhr.setBody(data).setParams(params).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error, metadata) { - return callback(error, Dropbox.Stat.parse(metadata)); - }); - }; - - Client.prototype.resumableUploadStep = function(data, cursor, callback) { - var params, xhr; - if (cursor) { - params = { - offset: cursor.offset - }; - if (cursor.tag) { - params.upload_id = cursor.tag; - } - } else { - params = { - offset: 0 - }; - } - xhr = new Dropbox.Xhr('POST', this.urls.chunkedUpload); - xhr.setBody(data).setParams(params).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error, cursor) { - if (error && error.status === 400 && error.response.upload_id && error.response.offset) { - return callback(null, Dropbox.UploadCursor.parse(error.response)); - } else { - return callback(error, Dropbox.UploadCursor.parse(cursor)); - } - }); - }; - - Client.prototype.resumableUploadFinish = function(path, cursor, options, callback) { - var params, xhr; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - params = { - upload_id: cursor.tag - }; - if (options) { - if (options.lastVersionTag) { - params.parent_rev = options.lastVersionTag; - } else if (options.parentRev || options.parent_rev) { - params.parent_rev = options.parentRev || options.parent_rev; - } - if (options.noOverwrite) { - params.autorename = true; - } - } - xhr = new Dropbox.Xhr('POST', "" + this.urls.commitChunkedUpload + "/" + (this.urlEncodePath(path))); - xhr.setParams(params).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error, metadata) { - return callback(error, Dropbox.Stat.parse(metadata)); - }); - }; - - Client.prototype.stat = function(path, options, callback) { - var httpCache, params, xhr; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - params = {}; - httpCache = false; - if (options) { - if (options.version != null) { - params.rev = options.version; - } - if (options.removed || options.deleted) { - params.include_deleted = 'true'; - } - if (options.readDir) { - params.list = 'true'; - if (options.readDir !== true) { - params.file_limit = options.readDir.toString(); - } - } - if (options.cacheHash) { - params.hash = options.cacheHash; - } - if (options.httpCache) { - httpCache = true; - } - } - params.include_deleted || (params.include_deleted = 'false'); - params.list || (params.list = 'false'); - xhr = new Dropbox.Xhr('GET', "" + this.urls.metadata + "/" + (this.urlEncodePath(path))); - xhr.setParams(params).signWithOauth(this.oauth, httpCache); - return this.dispatchXhr(xhr, function(error, metadata) { - var entries, entry, stat; - stat = Dropbox.Stat.parse(metadata); - if (metadata != null ? metadata.contents : void 0) { - entries = (function() { - var _i, _len, _ref, _results; - _ref = metadata.contents; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - entry = _ref[_i]; - _results.push(Dropbox.Stat.parse(entry)); - } - return _results; - })(); - } else { - entries = void 0; - } - return callback(error, stat, entries); - }); - }; - - Client.prototype.readdir = function(path, options, callback) { - var statOptions; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - statOptions = { - readDir: true - }; - if (options) { - if (options.limit != null) { - statOptions.readDir = options.limit; - } - if (options.versionTag) { - statOptions.versionTag = options.versionTag; - } - if (options.removed || options.deleted) { - statOptions.removed = options.removed || options.deleted; - } - if (options.httpCache) { - statOptions.httpCache = options.httpCache; - } - } - return this.stat(path, statOptions, function(error, stat, entry_stats) { - var entries, entry_stat; - if (entry_stats) { - entries = (function() { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = entry_stats.length; _i < _len; _i++) { - entry_stat = entry_stats[_i]; - _results.push(entry_stat.name); - } - return _results; - })(); - } else { - entries = null; - } - return callback(error, entries, stat, entry_stats); - }); - }; - - Client.prototype.metadata = function(path, options, callback) { - return this.stat(path, options, callback); - }; - - Client.prototype.makeUrl = function(path, options, callback) { - var isDirect, params, url, useDownloadHack, xhr; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - if (options && (options['long'] || options.longUrl || options.downloadHack)) { - params = { - short_url: 'false' - }; - } else { - params = {}; - } - path = this.urlEncodePath(path); - url = "" + this.urls.shares + "/" + path; - isDirect = false; - useDownloadHack = false; - if (options) { - if (options.downloadHack) { - isDirect = true; - useDownloadHack = true; - } else if (options.download) { - isDirect = true; - url = "" + this.urls.media + "/" + path; - } - } - xhr = new Dropbox.Xhr('POST', url).setParams(params).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error, urlData) { - if (useDownloadHack && urlData && urlData.url) { - urlData.url = urlData.url.replace(this.authServer, this.downloadServer); - } - return callback(error, Dropbox.PublicUrl.parse(urlData, isDirect)); - }); - }; - - Client.prototype.history = function(path, options, callback) { - var httpCache, params, xhr; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - params = {}; - httpCache = false; - if (options) { - if (options.limit != null) { - params.rev_limit = options.limit; - } - if (options.httpCache) { - httpCache = true; - } - } - xhr = new Dropbox.Xhr('GET', "" + this.urls.revisions + "/" + (this.urlEncodePath(path))); - xhr.setParams(params).signWithOauth(this.oauth, httpCache); - return this.dispatchXhr(xhr, function(error, versions) { - var metadata, stats; - if (versions) { - stats = (function() { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = versions.length; _i < _len; _i++) { - metadata = versions[_i]; - _results.push(Dropbox.Stat.parse(metadata)); - } - return _results; - })(); - } else { - stats = void 0; - } - return callback(error, stats); - }); - }; - - Client.prototype.revisions = function(path, options, callback) { - return this.history(path, options, callback); - }; - - Client.prototype.thumbnailUrl = function(path, options) { - var xhr; - xhr = this.thumbnailXhr(path, options); - return xhr.paramsToUrl().url; - }; - - Client.prototype.readThumbnail = function(path, options, callback) { - var responseType, xhr; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - responseType = 'b'; - if (options) { - if (options.blob) { - responseType = 'blob'; - } - } - xhr = this.thumbnailXhr(path, options); - xhr.setResponseType(responseType); - return this.dispatchXhr(xhr, function(error, data, metadata) { - return callback(error, data, Dropbox.Stat.parse(metadata)); - }); - }; - - Client.prototype.thumbnailXhr = function(path, options) { - var params, xhr; - params = {}; - if (options) { - if (options.format) { - params.format = options.format; - } else if (options.png) { - params.format = 'png'; - } - if (options.size) { - params.size = options.size; - } - } - xhr = new Dropbox.Xhr('GET', "" + this.urls.thumbnails + "/" + (this.urlEncodePath(path))); - return xhr.setParams(params).signWithOauth(this.oauth); - }; - - Client.prototype.revertFile = function(path, versionTag, callback) { - var xhr; - xhr = new Dropbox.Xhr('POST', "" + this.urls.restore + "/" + (this.urlEncodePath(path))); - xhr.setParams({ - rev: versionTag - }).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error, metadata) { - return callback(error, Dropbox.Stat.parse(metadata)); - }); - }; - - Client.prototype.restore = function(path, versionTag, callback) { - return this.revertFile(path, versionTag, callback); - }; - - Client.prototype.findByName = function(path, namePattern, options, callback) { - var httpCache, params, xhr; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - params = { - query: namePattern - }; - httpCache = false; - if (options) { - if (options.limit != null) { - params.file_limit = options.limit; - } - if (options.removed || options.deleted) { - params.include_deleted = true; - } - if (options.httpCache) { - httpCache = true; - } - } - xhr = new Dropbox.Xhr('GET', "" + this.urls.search + "/" + (this.urlEncodePath(path))); - xhr.setParams(params).signWithOauth(this.oauth, httpCache); - return this.dispatchXhr(xhr, function(error, results) { - var metadata, stats; - if (results) { - stats = (function() { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = results.length; _i < _len; _i++) { - metadata = results[_i]; - _results.push(Dropbox.Stat.parse(metadata)); - } - return _results; - })(); - } else { - stats = void 0; - } - return callback(error, stats); - }); - }; - - Client.prototype.search = function(path, namePattern, options, callback) { - return this.findByName(path, namePattern, options, callback); - }; - - Client.prototype.makeCopyReference = function(path, callback) { - var xhr; - xhr = new Dropbox.Xhr('GET', "" + this.urls.copyRef + "/" + (this.urlEncodePath(path))); - xhr.signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error, refData) { - return callback(error, Dropbox.CopyReference.parse(refData)); - }); - }; - - Client.prototype.copyRef = function(path, callback) { - return this.makeCopyReference(path, callback); - }; - - Client.prototype.pullChanges = function(cursor, callback) { - var params, xhr; - if ((!callback) && (typeof cursor === 'function')) { - callback = cursor; - cursor = null; - } - if (cursor) { - if (cursor.cursorTag) { - params = { - cursor: cursor.cursorTag - }; - } else { - params = { - cursor: cursor - }; - } - } else { - params = {}; - } - xhr = new Dropbox.Xhr('POST', this.urls.delta); - xhr.setParams(params).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error, deltaInfo) { - return callback(error, Dropbox.PulledChanges.parse(deltaInfo)); - }); - }; - - Client.prototype.delta = function(cursor, callback) { - return this.pullChanges(cursor, callback); - }; - - Client.prototype.mkdir = function(path, callback) { - var xhr; - xhr = new Dropbox.Xhr('POST', this.urls.fileopsCreateFolder); - xhr.setParams({ - root: this.fileRoot, - path: this.normalizePath(path) - }).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error, metadata) { - return callback(error, Dropbox.Stat.parse(metadata)); - }); - }; - - Client.prototype.remove = function(path, callback) { - var xhr; - xhr = new Dropbox.Xhr('POST', this.urls.fileopsDelete); - xhr.setParams({ - root: this.fileRoot, - path: this.normalizePath(path) - }).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error, metadata) { - return callback(error, Dropbox.Stat.parse(metadata)); - }); - }; - - Client.prototype.unlink = function(path, callback) { - return this.remove(path, callback); - }; - - Client.prototype["delete"] = function(path, callback) { - return this.remove(path, callback); - }; - - Client.prototype.copy = function(from, toPath, callback) { - var options, params, xhr; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - params = { - root: this.fileRoot, - to_path: this.normalizePath(toPath) - }; - if (from instanceof Dropbox.CopyReference) { - params.from_copy_ref = from.tag; - } else { - params.from_path = this.normalizePath(from); - } - xhr = new Dropbox.Xhr('POST', this.urls.fileopsCopy); - xhr.setParams(params).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error, metadata) { - return callback(error, Dropbox.Stat.parse(metadata)); - }); - }; - - Client.prototype.move = function(fromPath, toPath, callback) { - var options, xhr; - if ((!callback) && (typeof options === 'function')) { - callback = options; - options = null; - } - xhr = new Dropbox.Xhr('POST', this.urls.fileopsMove); - xhr.setParams({ - root: this.fileRoot, - from_path: this.normalizePath(fromPath), - to_path: this.normalizePath(toPath) - }).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, function(error, metadata) { - return callback(error, Dropbox.Stat.parse(metadata)); - }); - }; - - Client.prototype.reset = function() { - var oldAuthState; - this.uid = null; - this.oauth.setToken(null, ''); - oldAuthState = this.authState; - this.authState = DropboxClient.RESET; - if (oldAuthState !== this.authState) { - this.onAuthStateChange.dispatch(this); - } - this.authError = null; - this._credentials = null; - return this; - }; - - Client.prototype.setCredentials = function(credentials) { - var oldAuthState; - oldAuthState = this.authState; - this.oauth.reset(credentials); - this.uid = credentials.uid || null; - if (credentials.authState) { - this.authState = credentials.authState; - } else { - if (credentials.token) { - this.authState = DropboxClient.DONE; - } else { - this.authState = DropboxClient.RESET; - } - } - this.authError = null; - this._credentials = null; - if (oldAuthState !== this.authState) { - this.onAuthStateChange.dispatch(this); - } - return this; - }; - - Client.prototype.appHash = function() { - return this.oauth.appHash(); - }; - - Client.prototype.setupUrls = function() { - this.fileRoot = this.sandbox ? 'sandbox' : 'dropbox'; - return this.urls = { - requestToken: "" + this.apiServer + "/1/oauth/request_token", - authorize: "" + this.authServer + "/1/oauth/authorize", - accessToken: "" + this.apiServer + "/1/oauth/access_token", - signOut: "" + this.apiServer + "/1/unlink_access_token", - accountInfo: "" + this.apiServer + "/1/account/info", - getFile: "" + this.fileServer + "/1/files/" + this.fileRoot, - postFile: "" + this.fileServer + "/1/files/" + this.fileRoot, - putFile: "" + this.fileServer + "/1/files_put/" + this.fileRoot, - metadata: "" + this.apiServer + "/1/metadata/" + this.fileRoot, - delta: "" + this.apiServer + "/1/delta", - revisions: "" + this.apiServer + "/1/revisions/" + this.fileRoot, - restore: "" + this.apiServer + "/1/restore/" + this.fileRoot, - search: "" + this.apiServer + "/1/search/" + this.fileRoot, - shares: "" + this.apiServer + "/1/shares/" + this.fileRoot, - media: "" + this.apiServer + "/1/media/" + this.fileRoot, - copyRef: "" + this.apiServer + "/1/copy_ref/" + this.fileRoot, - thumbnails: "" + this.fileServer + "/1/thumbnails/" + this.fileRoot, - chunkedUpload: "" + this.fileServer + "/1/chunked_upload", - commitChunkedUpload: "" + this.fileServer + "/1/commit_chunked_upload/" + this.fileRoot, - fileopsCopy: "" + this.apiServer + "/1/fileops/copy", - fileopsCreateFolder: "" + this.apiServer + "/1/fileops/create_folder", - fileopsDelete: "" + this.apiServer + "/1/fileops/delete", - fileopsMove: "" + this.apiServer + "/1/fileops/move" - }; - }; - - Client.prototype.authState = null; - - Client.ERROR = 0; - - Client.RESET = 1; - - Client.REQUEST = 2; - - Client.AUTHORIZED = 3; - - Client.DONE = 4; - - Client.SIGNED_OFF = 5; - - Client.prototype.urlEncodePath = function(path) { - return Dropbox.Xhr.urlEncodeValue(this.normalizePath(path)).replace(/%2F/gi, '/'); - }; - - Client.prototype.normalizePath = function(path) { - var i; - if (path.substring(0, 1) === '/') { - i = 1; - while (path.substring(i, i + 1) === '/') { - i += 1; - } - return path.substring(i); - } else { - return path; - } - }; - - Client.prototype.requestToken = function(callback) { - var xhr; - xhr = new Dropbox.Xhr('POST', this.urls.requestToken).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, callback); - }; - - Client.prototype.authorizeUrl = function(token) { - var params; - params = { - oauth_token: token, - oauth_callback: this.driver.url() - }; - return ("" + this.urls.authorize + "?") + Dropbox.Xhr.urlEncode(params); - }; - - Client.prototype.getAccessToken = function(callback) { - var xhr; - xhr = new Dropbox.Xhr('POST', this.urls.accessToken).signWithOauth(this.oauth); - return this.dispatchXhr(xhr, callback); - }; - - Client.prototype.dispatchXhr = function(xhr, callback) { - var nativeXhr; - xhr.setCallback(callback); - xhr.onError = this.onError; - xhr.prepare(); - nativeXhr = xhr.xhr; - if (this.onXhr.dispatch(xhr)) { - xhr.send(); - } - return nativeXhr; - }; - - Client.prototype.defaultApiServer = function() { - return 'https://api.dropbox.com'; - }; - - Client.prototype.defaultAuthServer = function() { - return this.apiServer.replace('api.', 'www.'); - }; - - Client.prototype.defaultFileServer = function() { - return this.apiServer.replace('api.', 'api-content.'); - }; - - Client.prototype.defaultDownloadServer = function() { - return this.apiServer.replace('api.', 'dl.'); - }; - - Client.prototype.computeCredentials = function() { - var value; - value = { - key: this.oauth.key, - sandbox: this.sandbox - }; - if (this.oauth.secret) { - value.secret = this.oauth.secret; - } - if (this.oauth.token) { - value.token = this.oauth.token; - value.tokenSecret = this.oauth.tokenSecret; - } - if (this.uid) { - value.uid = this.uid; - } - if (this.authState !== DropboxClient.ERROR && this.authState !== DropboxClient.RESET && this.authState !== DropboxClient.DONE && this.authState !== DropboxClient.SIGNED_OFF) { - value.authState = this.authState; - } - if (this.apiServer !== this.defaultApiServer()) { - value.server = this.apiServer; - } - if (this.authServer !== this.defaultAuthServer()) { - value.authServer = this.authServer; - } - if (this.fileServer !== this.defaultFileServer()) { - value.fileServer = this.fileServer; - } - if (this.downloadServer !== this.defaultDownloadServer()) { - value.downloadServer = this.downloadServer; - } - return this._credentials = value; - }; - - return Client; - - })(); - - DropboxClient = Dropbox.Client; - - Dropbox.AuthDriver = (function() { - - function AuthDriver() {} - - AuthDriver.prototype.url = function() { - return 'https://some.url'; - }; - - AuthDriver.prototype.doAuthorize = function(authUrl, token, tokenSecret, callback) { - return callback('oauth-token'); - }; - - AuthDriver.prototype.onAuthStateChange = function(client, callback) { - return callback(); - }; - - return AuthDriver; - - })(); - - Dropbox.Drivers = {}; - - Dropbox.Drivers.BrowserBase = (function() { - - function BrowserBase(options) { - this.rememberUser = (options != null ? options.rememberUser : void 0) || false; - this.scope = (options != null ? options.scope : void 0) || 'default'; - this.storageKey = null; - } - - BrowserBase.prototype.onAuthStateChange = function(client, callback) { - var _this = this; - this.setStorageKey(client); - switch (client.authState) { - case DropboxClient.RESET: - return this.loadCredentials(function(credentials) { - if (!credentials) { - return callback(); - } - if (credentials.authState) { - client.setCredentials(credentials); - return callback(); - } - if (!_this.rememberUser) { - _this.forgetCredentials(); - return callback(); - } - client.setCredentials(credentials); - return client.getUserInfo(function(error) { - if (error) { - client.reset(); - return _this.forgetCredentials(callback); - } else { - return callback(); - } - }); - }); - case DropboxClient.REQUEST: - return this.storeCredentials(client.credentials(), callback); - case DropboxClient.DONE: - if (this.rememberUser) { - return this.storeCredentials(client.credentials(), callback); - } - return this.forgetCredentials(callback); - case DropboxClient.SIGNED_OFF: - return this.forgetCredentials(callback); - case DropboxClient.ERROR: - return this.forgetCredentials(callback); - default: - callback(); - return this; - } - }; - - BrowserBase.prototype.setStorageKey = function(client) { - this.storageKey = "dropbox-auth:" + this.scope + ":" + (client.appHash()); - return this; - }; - - BrowserBase.prototype.storeCredentials = function(credentials, callback) { - localStorage.setItem(this.storageKey, JSON.stringify(credentials)); - callback(); - return this; - }; - - BrowserBase.prototype.loadCredentials = function(callback) { - var jsonString; - jsonString = localStorage.getItem(this.storageKey); - if (!jsonString) { - callback(null); - return this; - } - try { - callback(JSON.parse(jsonString)); - } catch (e) { - callback(null); - } - return this; - }; - - BrowserBase.prototype.forgetCredentials = function(callback) { - localStorage.removeItem(this.storageKey); - callback(); - return this; - }; - - BrowserBase.currentLocation = function() { - return window.location.href; - }; - - return BrowserBase; - - })(); - - Dropbox.Drivers.Redirect = (function(_super) { - - __extends(Redirect, _super); - - function Redirect(options) { - Redirect.__super__.constructor.call(this, options); - this.useQuery = (options != null ? options.useQuery : void 0) || false; - this.receiverUrl = this.computeUrl(options); - this.tokenRe = new RegExp("(#|\\?|&)oauth_token=([^]+)(&|#|$)"); - } - - Redirect.prototype.onAuthStateChange = function(client, callback) { - var superCall, - _this = this; - superCall = (function() { - return function() { - return Redirect.__super__.onAuthStateChange.call(_this, client, callback); - }; - })(); - this.setStorageKey(client); - if (client.authState === DropboxClient.RESET) { - return this.loadCredentials(function(credentials) { - if (credentials && credentials.authState) { - if (credentials.token === _this.locationToken() && credentials.authState === DropboxClient.REQUEST) { - credentials.authState = DropboxClient.AUTHORIZED; - return _this.storeCredentials(credentials, superCall); - } else { - return _this.forgetCredentials(superCall); - } - } - return superCall(); - }); - } else { - return superCall(); - } - }; - - Redirect.prototype.url = function() { - return this.receiverUrl; - }; - - Redirect.prototype.doAuthorize = function(authUrl) { - return window.location.assign(authUrl); - }; - - Redirect.prototype.computeUrl = function() { - var fragment, location, locationPair, querySuffix; - querySuffix = "_dropboxjs_scope=" + (encodeURIComponent(this.scope)); - location = Dropbox.Drivers.BrowserBase.currentLocation(); - if (location.indexOf('#') === -1) { - fragment = null; - } else { - locationPair = location.split('#', 2); - location = locationPair[0]; - fragment = locationPair[1]; - } - if (this.useQuery) { - if (location.indexOf('?') === -1) { - location += "?" + querySuffix; - } else { - location += "&" + querySuffix; - } - } else { - fragment = "?" + querySuffix; - } - if (fragment) { - return location + '#' + fragment; - } else { - return location; - } - }; - - Redirect.prototype.locationToken = function() { - var location, match, scopePattern; - location = Dropbox.Drivers.BrowserBase.currentLocation(); - scopePattern = "_dropboxjs_scope=" + (encodeURIComponent(this.scope)) + "&"; - if ((typeof location.indexOf === "function" ? location.indexOf(scopePattern) : void 0) === -1) { - return null; - } - match = this.tokenRe.exec(location); - if (match) { - return decodeURIComponent(match[2]); - } else { - return null; - } - }; - - return Redirect; - - })(Dropbox.Drivers.BrowserBase); - - Dropbox.Drivers.Popup = (function(_super) { - - __extends(Popup, _super); - - function Popup(options) { - Popup.__super__.constructor.call(this, options); - this.receiverUrl = this.computeUrl(options); - this.tokenRe = new RegExp("(#|\\?|&)oauth_token=([^]+)(&|#|$)"); - } - - Popup.prototype.onAuthStateChange = function(client, callback) { - var superCall, - _this = this; - superCall = (function() { - return function() { - return Popup.__super__.onAuthStateChange.call(_this, client, callback); - }; - })(); - this.setStorageKey(client); - if (client.authState === DropboxClient.RESET) { - return this.loadCredentials(function(credentials) { - if (credentials && credentials.authState) { - return _this.forgetCredentials(superCall); - } - return superCall(); - }); - } else { - return superCall(); - } - }; - - Popup.prototype.doAuthorize = function(authUrl, token, tokenSecret, callback) { - this.listenForMessage(token, callback); - return this.openWindow(authUrl); - }; - - Popup.prototype.url = function() { - return this.receiverUrl; - }; - - Popup.prototype.computeUrl = function(options) { - var fragments; - if (options) { - if (options.receiverUrl) { - if (options.noFragment || options.receiverUrl.indexOf('#') !== -1) { - return options.receiverUrl; - } else { - return options.receiverUrl + '#'; - } - } else if (options.receiverFile) { - fragments = Dropbox.Drivers.BrowserBase.currentLocation().split('/'); - fragments[fragments.length - 1] = options.receiverFile; - if (options.noFragment) { - return fragments.join('/'); - } else { - return fragments.join('/') + '#'; - } - } - } - return Dropbox.Drivers.BrowserBase.currentLocation(); - }; - - Popup.prototype.openWindow = function(url) { - return window.open(url, '_dropboxOauthSigninWindow', this.popupWindowSpec(980, 700)); - }; - - Popup.prototype.popupWindowSpec = function(popupWidth, popupHeight) { - var height, popupLeft, popupTop, width, x0, y0, _ref, _ref1, _ref2, _ref3; - x0 = (_ref = window.screenX) != null ? _ref : window.screenLeft; - y0 = (_ref1 = window.screenY) != null ? _ref1 : window.screenTop; - width = (_ref2 = window.outerWidth) != null ? _ref2 : document.documentElement.clientWidth; - height = (_ref3 = window.outerHeight) != null ? _ref3 : document.documentElement.clientHeight; - popupLeft = Math.round(x0 + (width - popupWidth) / 2); - popupTop = Math.round(y0 + (height - popupHeight) / 2.5); - if (popupLeft < x0) { - popupLeft = x0; - } - if (popupTop < y0) { - popupTop = y0; - } - return ("width=" + popupWidth + ",height=" + popupHeight + ",") + ("left=" + popupLeft + ",top=" + popupTop) + 'dialog=yes,dependent=yes,scrollbars=yes,location=yes'; - }; - - Popup.prototype.listenForMessage = function(token, callback) { - var listener, - _this = this; - listener = function(event) { - var match; - match = _this.tokenRe.exec(event.data.toString()); - if (match && decodeURIComponent(match[2]) === token) { - window.removeEventListener('message', listener); - return callback(); - } - }; - return window.addEventListener('message', listener, false); - }; - - Popup.oauthReceiver = function() { - return window.addEventListener('load', function() { - var opener; - opener = window.opener; - if (window.parent !== window.top) { - opener || (opener = window.parent); - } - if (opener) { - try { - opener.postMessage(window.location.href, '*'); - } catch (e) { - - } - return window.close(); - } - }); - }; - - return Popup; - - })(Dropbox.Drivers.BrowserBase); - - DropboxChromeOnMessage = null; - - DropboxChromeSendMessage = null; - - if (typeof chrome !== "undefined" && chrome !== null) { - if (chrome.runtime) { - if (chrome.runtime.onMessage) { - DropboxChromeOnMessage = chrome.runtime.onMessage; - } - if (chrome.runtime.sendMessage) { - DropboxChromeSendMessage = function(m) { - return chrome.runtime.sendMessage(m); - }; - } - } - if (chrome.extension) { - if (chrome.extension.onMessage) { - DropboxChromeOnMessage || (DropboxChromeOnMessage = chrome.extension.onMessage); - } - if (chrome.extension.sendMessage) { - DropboxChromeSendMessage || (DropboxChromeSendMessage = function(m) { - return chrome.extension.sendMessage(m); - }); - } - } - if (!DropboxChromeOnMessage) { - (function() { - var page, pageHack; - pageHack = function(page) { - if (page.Dropbox) { - Dropbox.Drivers.Chrome.prototype.onMessage = page.Dropbox.Drivers.Chrome.onMessage; - return Dropbox.Drivers.Chrome.prototype.sendMessage = page.Dropbox.Drivers.Chrome.sendMessage; - } else { - page.Dropbox = Dropbox; - Dropbox.Drivers.Chrome.prototype.onMessage = new Dropbox.EventSource; - return Dropbox.Drivers.Chrome.prototype.sendMessage = function(m) { - return Dropbox.Drivers.Chrome.prototype.onMessage.dispatch(m); - }; - } - }; - if (chrome.extension && chrome.extension.getBackgroundPage) { - if (page = chrome.extension.getBackgroundPage()) { - return pageHack(page); - } - } - if (chrome.runtime && chrome.runtime.getBackgroundPage) { - return chrome.runtime.getBackgroundPage(function(page) { - return pageHack(page); - }); - } - })(); - } - } - - Dropbox.Drivers.Chrome = (function() { - - Chrome.prototype.onMessage = DropboxChromeOnMessage; - - Chrome.prototype.sendMessage = DropboxChromeSendMessage; - - Chrome.prototype.expandUrl = function(url) { - if (chrome.runtime && chrome.runtime.getURL) { - return chrome.runtime.getURL(url); - } - if (chrome.extension && chrome.extension.getURL) { - return chrome.extension.getURL(url); - } - return url; - }; - - function Chrome(options) { - var receiverPath, scope; - receiverPath = (options && options.receiverPath) || 'chrome_oauth_receiver.html'; - this.receiverUrl = this.expandUrl(receiverPath); - this.tokenRe = new RegExp("(#|\\?|&)oauth_token=([^]+)(&|#|$)"); - scope = (options && options.scope) || 'default'; - this.storageKey = "dropbox_js_" + scope + "_credentials"; - } - - Chrome.prototype.onAuthStateChange = function(client, callback) { - var _this = this; - switch (client.authState) { - case Dropbox.Client.RESET: - return this.loadCredentials(function(credentials) { - if (credentials) { - if (credentials.authState) { - return _this.forgetCredentials(callback); - } - client.setCredentials(credentials); - } - return callback(); - }); - case Dropbox.Client.DONE: - return this.storeCredentials(client.credentials(), callback); - case Dropbox.Client.SIGNED_OFF: - return this.forgetCredentials(callback); - case Dropbox.Client.ERROR: - return this.forgetCredentials(callback); - default: - return callback(); - } - }; - - Chrome.prototype.doAuthorize = function(authUrl, token, tokenSecret, callback) { - var window; - window = { - handle: null - }; - this.listenForMessage(token, window, callback); - return this.openWindow(authUrl, function(handle) { - return window.handle = handle; - }); - }; - - Chrome.prototype.openWindow = function(url, callback) { - if (chrome.tabs && chrome.tabs.create) { - chrome.tabs.create({ - url: url, - active: true, - pinned: false - }, function(tab) { - return callback(tab); - }); - return this; - } - if (chrome.app && chrome.app.window && chrome.app.window.create) { - chrome.app.window.create(url, { - frame: 'none', - id: 'dropbox-auth' - }, function(window) { - return callback(window); - }); - return this; - } - return this; - }; - - Chrome.prototype.closeWindow = function(handle) { - if (chrome.tabs && chrome.tabs.remove && handle.id) { - chrome.tabs.remove(handle.id); - return this; - } - if (chrome.app && chrome.app.window && handle.close) { - handle.close(); - return this; - } - return this; - }; - - Chrome.prototype.url = function() { - return this.receiverUrl; - }; - - Chrome.prototype.listenForMessage = function(token, window, callback) { - var listener, - _this = this; - listener = function(message, sender) { - var match; - if (sender && sender.tab) { - if (sender.tab.url.substring(0, _this.receiverUrl.length) !== _this.receiverUrl) { - return; - } - } - match = _this.tokenRe.exec(message.dropbox_oauth_receiver_href || ''); - if (match && decodeURIComponent(match[2]) === token) { - if (window.handle) { - _this.closeWindow(window.handle); - } - _this.onMessage.removeListener(listener); - return callback(); - } - }; - return this.onMessage.addListener(listener); - }; - - Chrome.prototype.storeCredentials = function(credentials, callback) { - var items; - items = {}; - items[this.storageKey] = credentials; - chrome.storage.local.set(items, callback); - return this; - }; - - Chrome.prototype.loadCredentials = function(callback) { - var _this = this; - chrome.storage.local.get(this.storageKey, function(items) { - return callback(items[_this.storageKey] || null); - }); - return this; - }; - - Chrome.prototype.forgetCredentials = function(callback) { - chrome.storage.local.remove(this.storageKey, callback); - return this; - }; - - Chrome.oauthReceiver = function() { - return window.addEventListener('load', function() { - var driver; - driver = new Dropbox.Drivers.Chrome(); - driver.sendMessage({ - dropbox_oauth_receiver_href: window.location.href - }); - if (window.close) { - return window.close(); - } - }); - }; - - return Chrome; - - })(); - - Dropbox.Drivers.NodeServer = (function() { - - function NodeServer(options) { - this.port = (options != null ? options.port : void 0) || 8912; - this.faviconFile = (options != null ? options.favicon : void 0) || null; - this.fs = require('fs'); - this.http = require('http'); - this.open = require('open'); - this.callbacks = {}; - this.urlRe = new RegExp("^/oauth_callback\\?"); - this.tokenRe = new RegExp("(\\?|&)oauth_token=([^&]+)(&|$)"); - this.createApp(); - } - - NodeServer.prototype.url = function() { - return "http://localhost:" + this.port + "/oauth_callback"; - }; - - NodeServer.prototype.doAuthorize = function(authUrl, token, tokenSecret, callback) { - this.callbacks[token] = callback; - return this.openBrowser(authUrl); - }; - - NodeServer.prototype.openBrowser = function(url) { - if (!url.match(/^https?:\/\//)) { - throw new Error("Not a http/https URL: " + url); - } - return this.open(url); - }; - - NodeServer.prototype.createApp = function() { - var _this = this; - this.app = this.http.createServer(function(request, response) { - return _this.doRequest(request, response); - }); - return this.app.listen(this.port); - }; - - NodeServer.prototype.closeServer = function() { - return this.app.close(); - }; - - NodeServer.prototype.doRequest = function(request, response) { - var data, match, token, - _this = this; - if (this.urlRe.exec(request.url)) { - match = this.tokenRe.exec(request.url); - if (match) { - token = decodeURIComponent(match[2]); - if (this.callbacks[token]) { - this.callbacks[token](); - delete this.callbacks[token]; - } - } - } - data = ''; - request.on('data', function(dataFragment) { - return data += dataFragment; - }); - return request.on('end', function() { - if (_this.faviconFile && (request.url === '/favicon.ico')) { - return _this.sendFavicon(response); - } else { - return _this.closeBrowser(response); - } - }); - }; - - NodeServer.prototype.closeBrowser = function(response) { - var closeHtml; - closeHtml = "\n\nPlease close this window.
"; - response.writeHead(200, { - 'Content-Length': closeHtml.length, - 'Content-Type': 'text/html' - }); - response.write(closeHtml); - return response.end; - }; - - NodeServer.prototype.sendFavicon = function(response) { - return this.fs.readFile(this.faviconFile, function(error, data) { - response.writeHead(200, { - 'Content-Length': data.length, - 'Content-Type': 'image/x-icon' - }); - response.write(data); - return response.end; - }); - }; - - return NodeServer; - - })(); - - Dropbox.EventSource = (function() { - - function EventSource(options) { - this._cancelable = options && options.cancelable; - this._listeners = []; - } - - EventSource.prototype.addListener = function(listener) { - if (typeof listener !== 'function') { - throw new TypeError('Invalid listener type; expected function'); - } - if (__indexOf.call(this._listeners, listener) < 0) { - this._listeners.push(listener); - } - return this; - }; - - EventSource.prototype.removeListener = function(listener) { - var i, index, subscriber, _i, _len, _ref; - if (this._listeners.indexOf) { - index = this._listeners.indexOf(listener); - if (index !== -1) { - this._listeners.splice(index, 1); - } - } else { - _ref = this._listeners; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { - subscriber = _ref[i]; - if (subscriber === listener) { - this._listeners.splice(i, 1); - break; - } - } - } - return this; - }; - - EventSource.prototype.dispatch = function(event) { - var listener, returnValue, _i, _len, _ref; - _ref = this._listeners; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - listener = _ref[_i]; - returnValue = listener(event); - if (this._cancelable && returnValue === false) { - return false; - } - } - return true; - }; - - return EventSource; - - })(); - - base64HmacSha1 = function(string, key) { - return arrayToBase64(hmacSha1(stringToArray(string), stringToArray(key), string.length, key.length)); - }; - - base64Sha1 = function(string) { - return arrayToBase64(sha1(stringToArray(string), string.length)); - }; - - if (typeof window === "undefined" || window === null) { - crypto = require('crypto'); - base64HmacSha1 = function(string, key) { - var hmac; - hmac = crypto.createHmac('sha1', key); - hmac.update(string); - return hmac.digest('base64'); - }; - base64Sha1 = function(string) { - var hash; - hash = crypto.createHash('sha1'); - hash.update(string); - return hash.digest('base64'); - }; - } - - hmacSha1 = function(string, key, length, keyLength) { - var hash1, i, ipad, opad; - if (key.length > 16) { - key = sha1(key, keyLength); - } - ipad = (function() { - var _i, _results; - _results = []; - for (i = _i = 0; _i < 16; i = ++_i) { - _results.push(key[i] ^ 0x36363636); - } - return _results; - })(); - opad = (function() { - var _i, _results; - _results = []; - for (i = _i = 0; _i < 16; i = ++_i) { - _results.push(key[i] ^ 0x5C5C5C5C); - } - return _results; - })(); - hash1 = sha1(ipad.concat(string), 64 + length); - return sha1(opad.concat(hash1), 64 + 20); - }; - - sha1 = function(string, length) { - var a, a0, b, b0, c, c0, d, d0, e, e0, ft, i, j, kt, limit, state, t, _i; - string[length >> 2] |= 1 << (31 - ((length & 0x03) << 3)); - string[(((length + 8) >> 6) << 4) + 15] = length << 3; - state = Array(80); - a = 1732584193; - b = -271733879; - c = -1732584194; - d = 271733878; - e = -1009589776; - i = 0; - limit = string.length; - while (i < limit) { - a0 = a; - b0 = b; - c0 = c; - d0 = d; - e0 = e; - for (j = _i = 0; _i < 80; j = ++_i) { - if (j < 16) { - state[j] = string[i + j]; - } else { - state[j] = rotateLeft32(state[j - 3] ^ state[j - 8] ^ state[j - 14] ^ state[j - 16], 1); - } - if (j < 20) { - ft = (b & c) | ((~b) & d); - kt = 1518500249; - } else if (j < 40) { - ft = b ^ c ^ d; - kt = 1859775393; - } else if (j < 60) { - ft = (b & c) | (b & d) | (c & d); - kt = -1894007588; - } else { - ft = b ^ c ^ d; - kt = -899497514; - } - t = add32(add32(rotateLeft32(a, 5), ft), add32(add32(e, state[j]), kt)); - e = d; - d = c; - c = rotateLeft32(b, 30); - b = a; - a = t; - } - a = add32(a, a0); - b = add32(b, b0); - c = add32(c, c0); - d = add32(d, d0); - e = add32(e, e0); - i += 16; - } - return [a, b, c, d, e]; - }; - - /* - # Uncomment the definition below for debugging. - # - # Returns the hexadecimal representation of a 32-bit number. - xxx = (n) -> - if n < 0 - n = (1 << 30) * 4 + n - n.toString 16 - */ - - - rotateLeft32 = function(value, count) { - return (value << count) | (value >>> (32 - count)); - }; - - add32 = function(a, b) { - var high, low; - low = (a & 0xFFFF) + (b & 0xFFFF); - high = (a >> 16) + (b >> 16) + (low >> 16); - return (high << 16) | (low & 0xFFFF); - }; - - arrayToBase64 = function(array) { - var i, i2, limit, string, trit; - string = ""; - i = 0; - limit = array.length * 4; - while (i < limit) { - i2 = i; - trit = ((array[i2 >> 2] >> ((3 - (i2 & 3)) << 3)) & 0xFF) << 16; - i2 += 1; - trit |= ((array[i2 >> 2] >> ((3 - (i2 & 3)) << 3)) & 0xFF) << 8; - i2 += 1; - trit |= (array[i2 >> 2] >> ((3 - (i2 & 3)) << 3)) & 0xFF; - string += _base64Digits[(trit >> 18) & 0x3F]; - string += _base64Digits[(trit >> 12) & 0x3F]; - i += 1; - if (i >= limit) { - string += '='; - } else { - string += _base64Digits[(trit >> 6) & 0x3F]; - } - i += 1; - if (i >= limit) { - string += '='; - } else { - string += _base64Digits[trit & 0x3F]; - } - i += 1; - } - return string; - }; - - _base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - stringToArray = function(string) { - var array, i, mask, _i, _ref; - array = []; - mask = 0xFF; - for (i = _i = 0, _ref = string.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - array[i >> 2] |= (string.charCodeAt(i) & mask) << ((3 - (i & 3)) << 3); - } - return array; - }; - - Dropbox.Oauth = (function() { - - function Oauth(options) { - this.key = this.k = null; - this.secret = this.s = null; - this.token = null; - this.tokenSecret = null; - this._appHash = null; - this.reset(options); - } - - Oauth.prototype.reset = function(options) { - var k, s, secret, _ref; - if (options.secret) { - this.k = this.key = options.key; - this.s = this.secret = options.secret; - this._appHash = null; - } else if (options.key) { - this.key = options.key; - this.secret = null; - secret = atob(dropboxEncodeKey(this.key).split('|', 2)[1]); - _ref = secret.split('?', 2), k = _ref[0], s = _ref[1]; - this.k = decodeURIComponent(k); - this.s = decodeURIComponent(s); - this._appHash = null; - } else { - if (!this.k) { - throw new Error('No API key supplied'); - } - } - if (options.token) { - return this.setToken(options.token, options.tokenSecret); - } else { - return this.setToken(null, ''); - } - }; - - Oauth.prototype.setToken = function(token, tokenSecret) { - if (token && (!tokenSecret)) { - throw new Error('No secret supplied with the user token'); - } - this.token = token; - this.tokenSecret = tokenSecret || ''; - this.hmacKey = Dropbox.Xhr.urlEncodeValue(this.s) + '&' + Dropbox.Xhr.urlEncodeValue(tokenSecret); - return null; - }; - - Oauth.prototype.authHeader = function(method, url, params) { - var header, oauth_params, param, value, _i, _len; - this.addAuthParams(method, url, params); - oauth_params = []; - for (param in params) { - value = params[param]; - if (param.substring(0, 6) === 'oauth_') { - oauth_params.push(param); - } - } - oauth_params.sort(); - header = []; - for (_i = 0, _len = oauth_params.length; _i < _len; _i++) { - param = oauth_params[_i]; - header.push(Dropbox.Xhr.urlEncodeValue(param) + '="' + Dropbox.Xhr.urlEncodeValue(params[param]) + '"'); - delete params[param]; - } - return 'OAuth ' + header.join(','); - }; - - Oauth.prototype.addAuthParams = function(method, url, params) { - this.boilerplateParams(params); - params.oauth_signature = this.signature(method, url, params); - return params; - }; - - Oauth.prototype.boilerplateParams = function(params) { - params.oauth_consumer_key = this.k; - params.oauth_nonce = this.nonce(); - params.oauth_signature_method = 'HMAC-SHA1'; - if (this.token) { - params.oauth_token = this.token; - } - params.oauth_timestamp = Math.floor(Date.now() / 1000); - params.oauth_version = '1.0'; - return params; - }; - - Oauth.prototype.nonce = function() { - return Date.now().toString(36) + Math.random().toString(36); - }; - - Oauth.prototype.signature = function(method, url, params) { - var string; - string = method.toUpperCase() + '&' + Dropbox.Xhr.urlEncodeValue(url) + '&' + Dropbox.Xhr.urlEncodeValue(Dropbox.Xhr.urlEncode(params)); - return base64HmacSha1(string, this.hmacKey); - }; - - Oauth.prototype.appHash = function() { - if (this._appHash) { - return this._appHash; - } - return this._appHash = base64Sha1(this.k).replace(/\=/g, ''); - }; - - return Oauth; - - })(); - - if (Date.now == null) { - Date.now = function() { - return (new Date()).getTime(); - }; - } - - dropboxEncodeKey = function(key, secret) { - var i, k, result, s, x, y, z, _i, _j, _ref, _ref1, _results; - if (secret) { - secret = [encodeURIComponent(key), encodeURIComponent(secret)].join('?'); - key = (function() { - var _i, _ref, _results; - _results = []; - for (i = _i = 0, _ref = key.length / 2; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - _results.push(((key.charCodeAt(i * 2) & 15) * 16) + (key.charCodeAt(i * 2 + 1) & 15)); - } - return _results; - })(); - } else { - _ref = key.split('|', 2), key = _ref[0], secret = _ref[1]; - key = atob(key); - key = (function() { - var _i, _ref1, _results; - _results = []; - for (i = _i = 0, _ref1 = key.length; 0 <= _ref1 ? _i < _ref1 : _i > _ref1; i = 0 <= _ref1 ? ++_i : --_i) { - _results.push(key.charCodeAt(i)); - } - return _results; - })(); - secret = atob(secret); - } - s = (function() { - _results = []; - for (_i = 0; _i < 256; _i++){ _results.push(_i); } - return _results; - }).apply(this); - y = 0; - for (x = _j = 0; _j < 256; x = ++_j) { - y = (y + s[i] + key[x % key.length]) % 256; - _ref1 = [s[y], s[x]], s[x] = _ref1[0], s[y] = _ref1[1]; - } - x = y = 0; - result = (function() { - var _k, _ref2, _ref3, _results1; - _results1 = []; - for (z = _k = 0, _ref2 = secret.length; 0 <= _ref2 ? _k < _ref2 : _k > _ref2; z = 0 <= _ref2 ? ++_k : --_k) { - x = (x + 1) % 256; - y = (y + s[x]) % 256; - _ref3 = [s[y], s[x]], s[x] = _ref3[0], s[y] = _ref3[1]; - k = s[(s[x] + s[y]) % 256]; - _results1.push(String.fromCharCode((k ^ secret.charCodeAt(z)) % 256)); - } - return _results1; - })(); - key = (function() { - var _k, _ref2, _results1; - _results1 = []; - for (i = _k = 0, _ref2 = key.length; 0 <= _ref2 ? _k < _ref2 : _k > _ref2; i = 0 <= _ref2 ? ++_k : --_k) { - _results1.push(String.fromCharCode(key[i])); - } - return _results1; - })(); - return [btoa(key.join('')), btoa(result.join(''))].join('|'); - }; - - Dropbox.PulledChanges = (function() { - - PulledChanges.parse = function(deltaInfo) { - if (deltaInfo && typeof deltaInfo === 'object') { - return new Dropbox.PulledChanges(deltaInfo); - } else { - return deltaInfo; - } - }; - - PulledChanges.prototype.blankSlate = void 0; - - PulledChanges.prototype.cursorTag = void 0; - - PulledChanges.prototype.changes = void 0; - - PulledChanges.prototype.shouldPullAgain = void 0; - - PulledChanges.prototype.shouldBackOff = void 0; - - PulledChanges.prototype.cursor = function() { - return this.cursorTag; - }; - - function PulledChanges(deltaInfo) { - var entry; - this.blankSlate = deltaInfo.reset || false; - this.cursorTag = deltaInfo.cursor; - this.shouldPullAgain = deltaInfo.has_more; - this.shouldBackOff = !this.shouldPullAgain; - if (deltaInfo.cursor && deltaInfo.cursor.length) { - this.changes = (function() { - var _i, _len, _ref, _results; - _ref = deltaInfo.entries; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - entry = _ref[_i]; - _results.push(Dropbox.PullChange.parse(entry)); - } - return _results; - })(); - } else { - this.changes = []; - } - } - - return PulledChanges; - - })(); - - Dropbox.PullChange = (function() { - - PullChange.parse = function(entry) { - if (entry && typeof entry === 'object') { - return new Dropbox.PullChange(entry); - } else { - return entry; - } - }; - - PullChange.prototype.path = void 0; - - PullChange.prototype.wasRemoved = void 0; - - PullChange.prototype.stat = void 0; - - function PullChange(entry) { - this.path = entry[0]; - this.stat = Dropbox.Stat.parse(entry[1]); - if (this.stat) { - this.wasRemoved = false; - } else { - this.stat = null; - this.wasRemoved = true; - } - } - - return PullChange; - - })(); - - Dropbox.PublicUrl = (function() { - - PublicUrl.parse = function(urlData, isDirect) { - if (urlData && typeof urlData === 'object') { - return new Dropbox.PublicUrl(urlData, isDirect); - } else { - return urlData; - } - }; - - PublicUrl.prototype.url = null; - - PublicUrl.prototype.expiresAt = null; - - PublicUrl.prototype.isDirect = null; - - PublicUrl.prototype.isPreview = null; - - PublicUrl.prototype.json = function() { - return this._json || (this._json = { - url: this.url, - expires: this.expiresAt.toString(), - direct: this.isDirect - }); - }; - - function PublicUrl(urlData, isDirect) { - this.url = urlData.url; - this.expiresAt = new Date(Date.parse(urlData.expires)); - if (isDirect === true) { - this.isDirect = true; - } else if (isDirect === false) { - this.isDirect = false; - } else { - if ('direct' in urlData) { - this.isDirect = urlData.direct; - } else { - this.isDirect = Date.now() - this.expiresAt <= 86400000; - } - } - this.isPreview = !this.isDirect; - this._json = null; - } - - return PublicUrl; - - })(); - - Dropbox.CopyReference = (function() { - - CopyReference.parse = function(refData) { - if (refData && (typeof refData === 'object' || typeof refData === 'string')) { - return new Dropbox.CopyReference(refData); - } else { - return refData; - } - }; - - CopyReference.prototype.tag = null; - - CopyReference.prototype.expiresAt = null; - - CopyReference.prototype.json = function() { - return this._json || (this._json = { - copy_ref: this.tag, - expires: this.expiresAt.toString() - }); - }; - - function CopyReference(refData) { - if (typeof refData === 'object') { - this.tag = refData.copy_ref; - this.expiresAt = new Date(Date.parse(refData.expires)); - this._json = refData; - } else { - this.tag = refData; - this.expiresAt = new Date(Math.ceil(Date.now() / 1000) * 1000); - this._json = null; - } - } - - return CopyReference; - - })(); - - Dropbox.Stat = (function() { - - Stat.parse = function(metadata) { - if (metadata && typeof metadata === 'object') { - return new Dropbox.Stat(metadata); - } else { - return metadata; - } - }; - - Stat.prototype.path = null; - - Stat.prototype.name = null; - - Stat.prototype.inAppFolder = null; - - Stat.prototype.isFolder = null; - - Stat.prototype.isFile = null; - - Stat.prototype.isRemoved = null; - - Stat.prototype.typeIcon = null; - - Stat.prototype.versionTag = null; - - Stat.prototype.mimeType = null; - - Stat.prototype.size = null; - - Stat.prototype.humanSize = null; - - Stat.prototype.hasThumbnail = null; - - Stat.prototype.modifiedAt = null; - - Stat.prototype.clientModifiedAt = null; - - Stat.prototype.json = function() { - return this._json; - }; - - function Stat(metadata) { - var lastIndex, nameSlash, _ref, _ref1; - this._json = metadata; - this.path = metadata.path; - if (this.path.substring(0, 1) !== '/') { - this.path = '/' + this.path; - } - lastIndex = this.path.length - 1; - if (lastIndex >= 0 && this.path.substring(lastIndex) === '/') { - this.path = this.path.substring(0, lastIndex); - } - nameSlash = this.path.lastIndexOf('/'); - this.name = this.path.substring(nameSlash + 1); - this.isFolder = metadata.is_dir || false; - this.isFile = !this.isFolder; - this.isRemoved = metadata.is_deleted || false; - this.typeIcon = metadata.icon; - if ((_ref = metadata.modified) != null ? _ref.length : void 0) { - this.modifiedAt = new Date(Date.parse(metadata.modified)); - } else { - this.modifiedAt = null; - } - if ((_ref1 = metadata.client_mtime) != null ? _ref1.length : void 0) { - this.clientModifiedAt = new Date(Date.parse(metadata.client_mtime)); - } else { - this.clientModifiedAt = null; - } - switch (metadata.root) { - case 'dropbox': - this.inAppFolder = false; - break; - case 'app_folder': - this.inAppFolder = true; - break; - default: - this.inAppFolder = null; - } - this.size = metadata.bytes || 0; - this.humanSize = metadata.size || ''; - this.hasThumbnail = metadata.thumb_exists || false; - if (this.isFolder) { - this.versionTag = metadata.hash; - this.mimeType = metadata.mime_type || 'inode/directory'; - } else { - this.versionTag = metadata.rev; - this.mimeType = metadata.mime_type || 'application/octet-stream'; - } - } - - return Stat; - - })(); - - Dropbox.UploadCursor = (function() { - - UploadCursor.parse = function(cursorData) { - if (cursorData && (typeof cursorData === 'object' || typeof cursorData === 'string')) { - return new Dropbox.UploadCursor(cursorData); - } else { - return cursorData; - } - }; - - UploadCursor.prototype.tag = null; - - UploadCursor.prototype.offset = null; - - UploadCursor.prototype.expiresAt = null; - - UploadCursor.prototype.json = function() { - return this._json || (this._json = { - upload_id: this.tag, - offset: this.offset, - expires: this.expiresAt.toString() - }); - }; - - function UploadCursor(cursorData) { - this.replace(cursorData); - } - - UploadCursor.prototype.replace = function(cursorData) { - if (typeof cursorData === 'object') { - this.tag = cursorData.upload_id || null; - this.offset = cursorData.offset || 0; - this.expiresAt = new Date(Date.parse(cursorData.expires) || Date.now()); - this._json = cursorData; - } else { - this.tag = cursorData || null; - this.offset = 0; - this.expiresAt = new Date(Math.floor(Date.now() / 1000) * 1000); - this._json = null; - } - return this; - }; - - return UploadCursor; - - })(); - - Dropbox.UserInfo = (function() { - - UserInfo.parse = function(userInfo) { - if (userInfo && typeof userInfo === 'object') { - return new Dropbox.UserInfo(userInfo); - } else { - return userInfo; - } - }; - - UserInfo.prototype.name = null; - - UserInfo.prototype.email = null; - - UserInfo.prototype.countryCode = null; - - UserInfo.prototype.uid = null; - - UserInfo.prototype.referralUrl = null; - - UserInfo.prototype.publicAppUrl = null; - - UserInfo.prototype.quota = null; - - UserInfo.prototype.usedQuota = null; - - UserInfo.prototype.privateBytes = null; - - UserInfo.prototype.sharedBytes = null; - - UserInfo.prototype.json = function() { - return this._json; - }; - - function UserInfo(userInfo) { - var lastIndex; - this._json = userInfo; - this.name = userInfo.display_name; - this.email = userInfo.email; - this.countryCode = userInfo.country || null; - this.uid = userInfo.uid.toString(); - if (userInfo.public_app_url) { - this.publicAppUrl = userInfo.public_app_url; - lastIndex = this.publicAppUrl.length - 1; - if (lastIndex >= 0 && this.publicAppUrl.substring(lastIndex) === '/') { - this.publicAppUrl = this.publicAppUrl.substring(0, lastIndex); - } - } else { - this.publicAppUrl = null; - } - this.referralUrl = userInfo.referral_link; - this.quota = userInfo.quota_info.quota; - this.privateBytes = userInfo.quota_info.normal || 0; - this.sharedBytes = userInfo.quota_info.shared || 0; - this.usedQuota = this.privateBytes + this.sharedBytes; - } - - return UserInfo; - - })(); - - if (typeof window !== "undefined" && window !== null) { - if (window.XDomainRequest && !('withCredentials' in new XMLHttpRequest())) { - DropboxXhrRequest = window.XDomainRequest; - DropboxXhrIeMode = true; - DropboxXhrCanSendForms = false; - } else { - DropboxXhrRequest = window.XMLHttpRequest; - DropboxXhrIeMode = false; - DropboxXhrCanSendForms = window.navigator.userAgent.indexOf('Firefox') === -1; - } - DropboxXhrDoesPreflight = true; - } else { - DropboxXhrRequest = require('xmlhttprequest').XMLHttpRequest; - DropboxXhrIeMode = false; - DropboxXhrCanSendForms = false; - DropboxXhrDoesPreflight = false; - } - - if (typeof Uint8Array === 'undefined') { - DropboxXhrArrayBufferView = null; - DropboxXhrSendArrayBufferView = false; - } else { - if (Object.getPrototypeOf) { - DropboxXhrArrayBufferView = Object.getPrototypeOf(Object.getPrototypeOf(new Uint8Array(0))).constructor; - } else if (Object.__proto__) { - DropboxXhrArrayBufferView = (new Uint8Array(0)).__proto__.__proto__.constructor; - } - DropboxXhrSendArrayBufferView = DropboxXhrArrayBufferView !== Object; - } - - Dropbox.Xhr = (function() { - - Xhr.Request = DropboxXhrRequest; - - Xhr.ieXdr = DropboxXhrIeMode; - - Xhr.canSendForms = DropboxXhrCanSendForms; - - Xhr.doesPreflight = DropboxXhrDoesPreflight; - - Xhr.ArrayBufferView = DropboxXhrArrayBufferView; - - Xhr.sendArrayBufferView = DropboxXhrSendArrayBufferView; - - function Xhr(method, baseUrl) { - this.method = method; - this.isGet = this.method === 'GET'; - this.url = baseUrl; - this.headers = {}; - this.params = null; - this.body = null; - this.preflight = !(this.isGet || (this.method === 'POST')); - this.signed = false; - this.responseType = null; - this.callback = null; - this.xhr = null; - this.onError = null; - } - - Xhr.prototype.xhr = null; - - Xhr.prototype.onError = null; - - Xhr.prototype.setParams = function(params) { - if (this.signed) { - throw new Error('setParams called after addOauthParams or addOauthHeader'); - } - if (this.params) { - throw new Error('setParams cannot be called twice'); - } - this.params = params; - return this; - }; - - Xhr.prototype.setCallback = function(callback) { - this.callback = callback; - return this; - }; - - Xhr.prototype.signWithOauth = function(oauth, cacheFriendly) { - if (Dropbox.Xhr.ieXdr) { - return this.addOauthParams(oauth); - } else if (this.preflight || !Dropbox.Xhr.doesPreflight) { - return this.addOauthHeader(oauth); - } else { - if (this.isGet && cacheFriendly) { - return this.addOauthHeader(oauth); - } else { - return this.addOauthParams(oauth); - } - } - }; - - Xhr.prototype.addOauthParams = function(oauth) { - if (this.signed) { - throw new Error('Request already has an OAuth signature'); - } - this.params || (this.params = {}); - oauth.addAuthParams(this.method, this.url, this.params); - this.signed = true; - return this; - }; - - Xhr.prototype.addOauthHeader = function(oauth) { - if (this.signed) { - throw new Error('Request already has an OAuth signature'); - } - this.params || (this.params = {}); - this.signed = true; - return this.setHeader('Authorization', oauth.authHeader(this.method, this.url, this.params)); - }; - - Xhr.prototype.setBody = function(body) { - if (this.isGet) { - throw new Error('setBody cannot be called on GET requests'); - } - if (this.body !== null) { - throw new Error('Request already has a body'); - } - if (typeof body === 'string') { - - } else if ((typeof FormData !== 'undefined') && (body instanceof FormData)) { - - } else { - this.headers['Content-Type'] = 'application/octet-stream'; - this.preflight = true; - } - this.body = body; - return this; - }; - - Xhr.prototype.setResponseType = function(responseType) { - this.responseType = responseType; - return this; - }; - - Xhr.prototype.setHeader = function(headerName, value) { - var oldValue; - if (this.headers[headerName]) { - oldValue = this.headers[headerName]; - throw new Error("HTTP header " + headerName + " already set to " + oldValue); - } - if (headerName === 'Content-Type') { - throw new Error('Content-Type is automatically computed based on setBody'); - } - this.preflight = true; - this.headers[headerName] = value; - return this; - }; - - Xhr.prototype.setFileField = function(fieldName, fileName, fileData, contentType) { - var boundary, useFormData; - if (this.body !== null) { - throw new Error('Request already has a body'); - } - if (this.isGet) { - throw new Error('setFileField cannot be called on GET requests'); - } - if (typeof fileData === 'object' && typeof Blob !== 'undefined') { - if (typeof ArrayBuffer !== 'undefined') { - if (fileData instanceof ArrayBuffer) { - if (Dropbox.Xhr.sendArrayBufferView) { - fileData = new Uint8Array(fileData); - } - } else { - if (!Dropbox.Xhr.sendArrayBufferView && fileData.byteOffset === 0 && fileData.buffer instanceof ArrayBuffer) { - fileData = fileData.buffer; - } - } - } - contentType || (contentType = 'application/octet-stream'); - fileData = new Blob([fileData], { - type: contentType - }); - if (typeof File !== 'undefined' && fileData instanceof File) { - fileData = new Blob([fileData], { - type: fileData.type - }); - } - useFormData = fileData instanceof Blob; - } else { - useFormData = false; - } - if (useFormData) { - this.body = new FormData(); - return this.body.append(fieldName, fileData, fileName); - } else { - contentType || (contentType = 'application/octet-stream'); - boundary = this.multipartBoundary(); - this.headers['Content-Type'] = "multipart/form-data; boundary=" + boundary; - return this.body = ['--', boundary, "\r\n", 'Content-Disposition: form-data; name="', fieldName, '"; filename="', fileName, "\"\r\n", 'Content-Type: ', contentType, "\r\n", "Content-Transfer-Encoding: binary\r\n\r\n", fileData, "\r\n", '--', boundary, '--', "\r\n"].join(''); - } - }; - - Xhr.prototype.multipartBoundary = function() { - return [Date.now().toString(36), Math.random().toString(36)].join('----'); - }; - - Xhr.prototype.paramsToUrl = function() { - var queryString; - if (this.params) { - queryString = Dropbox.Xhr.urlEncode(this.params); - if (queryString.length !== 0) { - this.url = [this.url, '?', queryString].join(''); - } - this.params = null; - } - return this; - }; - - Xhr.prototype.paramsToBody = function() { - if (this.params) { - if (this.body !== null) { - throw new Error('Request already has a body'); - } - if (this.isGet) { - throw new Error('paramsToBody cannot be called on GET requests'); - } - this.headers['Content-Type'] = 'application/x-www-form-urlencoded'; - this.body = Dropbox.Xhr.urlEncode(this.params); - this.params = null; - } - return this; - }; - - Xhr.prototype.prepare = function() { - var header, ieXdr, value, _ref, - _this = this; - ieXdr = Dropbox.Xhr.ieXdr; - if (this.isGet || this.body !== null || ieXdr) { - this.paramsToUrl(); - if (this.body !== null && typeof this.body === 'string') { - this.headers['Content-Type'] = 'text/plain; charset=utf8'; - } - } else { - this.paramsToBody(); - } - this.xhr = new Dropbox.Xhr.Request(); - if (ieXdr) { - this.xhr.onload = function() { - return _this.onXdrLoad(); - }; - this.xhr.onerror = function() { - return _this.onXdrError(); - }; - this.xhr.ontimeout = function() { - return _this.onXdrError(); - }; - this.xhr.onprogress = function() {}; - } else { - this.xhr.onreadystatechange = function() { - return _this.onReadyStateChange(); - }; - } - this.xhr.open(this.method, this.url, true); - if (!ieXdr) { - _ref = this.headers; - for (header in _ref) { - if (!__hasProp.call(_ref, header)) continue; - value = _ref[header]; - this.xhr.setRequestHeader(header, value); - } - } - if (this.responseType) { - if (this.responseType === 'b') { - if (this.xhr.overrideMimeType) { - this.xhr.overrideMimeType('text/plain; charset=x-user-defined'); - } - } else { - this.xhr.responseType = this.responseType; - } - } - return this; - }; - - Xhr.prototype.send = function(callback) { - var body; - this.callback = callback || this.callback; - if (this.body !== null) { - body = this.body; - if (Dropbox.Xhr.sendArrayBufferView && body instanceof ArrayBuffer) { - body = new Uint8Array(body); - } - try { - this.xhr.send(body); - } catch (e) { - if (!Dropbox.Xhr.sendArrayBufferView && typeof Blob !== 'undefined') { - body = new Blob([body], { - type: 'application/octet-stream' - }); - this.xhr.send(body); - } else { - throw e; - } - } - } else { - this.xhr.send(); - } - return this; - }; - - Xhr.urlEncode = function(object) { - var chunks, key, value; - chunks = []; - for (key in object) { - value = object[key]; - chunks.push(this.urlEncodeValue(key) + '=' + this.urlEncodeValue(value)); - } - return chunks.sort().join('&'); - }; - - Xhr.urlEncodeValue = function(object) { - return encodeURIComponent(object.toString()).replace(/\!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A'); - }; - - Xhr.urlDecode = function(string) { - var kvp, result, token, _i, _len, _ref; - result = {}; - _ref = string.split('&'); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - token = _ref[_i]; - kvp = token.split('='); - result[decodeURIComponent(kvp[0])] = decodeURIComponent(kvp[1]); - } - return result; - }; - - Xhr.prototype.onReadyStateChange = function() { - var apiError, bytes, dirtyText, i, metadata, metadataJson, text, _i, _ref; - if (this.xhr.readyState !== 4) { - return true; - } - if (this.xhr.status < 200 || this.xhr.status >= 300) { - apiError = new Dropbox.ApiError(this.xhr, this.method, this.url); - if (this.onError) { - this.onError.dispatch(apiError); - } - this.callback(apiError); - return true; - } - metadataJson = this.xhr.getResponseHeader('x-dropbox-metadata'); - if (metadataJson != null ? metadataJson.length : void 0) { - try { - metadata = JSON.parse(metadataJson); - } catch (e) { - metadata = void 0; - } - } else { - metadata = void 0; - } - if (this.responseType) { - if (this.responseType === 'b') { - dirtyText = this.xhr.responseText != null ? this.xhr.responseText : this.xhr.response; - /* - jsString = ['["'] - for i in [0...dirtyText.length] - hexByte = (dirtyText.charCodeAt(i) & 0xFF).toString(16) - if hexByte.length is 2 - jsString.push "\\u00#{hexByte}" - else - jsString.push "\\u000#{hexByte}" - jsString.push '"]' - console.log jsString - text = JSON.parse(jsString.join(''))[0] - */ - - bytes = []; - for (i = _i = 0, _ref = dirtyText.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - bytes.push(String.fromCharCode(dirtyText.charCodeAt(i) & 0xFF)); - } - text = bytes.join(''); - this.callback(null, text, metadata); - } else { - this.callback(null, this.xhr.response, metadata); - } - return true; - } - text = this.xhr.responseText != null ? this.xhr.responseText : this.xhr.response; - switch (this.xhr.getResponseHeader('Content-Type')) { - case 'application/x-www-form-urlencoded': - this.callback(null, Dropbox.Xhr.urlDecode(text), metadata); - break; - case 'application/json': - case 'text/javascript': - this.callback(null, JSON.parse(text), metadata); - break; - default: - this.callback(null, text, metadata); - } - return true; - }; - - Xhr.prototype.onXdrLoad = function() { - var text; - text = this.xhr.responseText; - switch (this.xhr.contentType) { - case 'application/x-www-form-urlencoded': - this.callback(null, Dropbox.Xhr.urlDecode(text), void 0); - break; - case 'application/json': - case 'text/javascript': - this.callback(null, JSON.parse(text), void 0); - break; - default: - this.callback(null, text, void 0); - } - return true; - }; - - Xhr.prototype.onXdrError = function() { - var apiError; - apiError = new Dropbox.ApiError(this.xhr, this.method, this.url); - if (this.onError) { - this.onError.dispatch(apiError); - } - this.callback(apiError); - return true; - }; - - return Xhr; - - })(); - - if ((typeof module !== "undefined" && module !== null ? module.exports : void 0) != null) { - module.exports = Dropbox; - } else if (typeof window !== "undefined" && window !== null) { - window.Dropbox = Dropbox; - } else { - throw new Error('This library only supports node.js and modern browsers.'); - } - - Dropbox.atob = atob; - - Dropbox.btoa = btoa; - - Dropbox.hmac = base64HmacSha1; - - Dropbox.sha1 = base64Sha1; - - Dropbox.encodeKey = dropboxEncodeKey; - -}).call(this); diff --git a/lib/client/storage/dropbox/lib/dropbox.min.js b/lib/client/storage/dropbox/lib/dropbox.min.js deleted file mode 100644 index f14c0b0b..00000000 --- a/lib/client/storage/dropbox/lib/dropbox.min.js +++ /dev/null @@ -1,2 +0,0 @@ -(function(){var t,e,r,n,o,i,s,a,h,u,l,p,c,d,f,y,v,m,g,w,S,b,_,E,C,x,R={}.hasOwnProperty,T=function(t,e){function r(){this.constructor=t}for(var n in e)R.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},k=[].indexOf||function(t){for(var e=0,r=this.length;r>e;e++)if(e in this&&this[e]===t)return e;return-1};if(t=function(){function t(t){this.client=new n(t)}return t}(),t.ApiError=function(){function t(t,e,r){var n;if(this.method=e,this.url=r,this.status=t.status,t.responseType)try{n=t.response||t.responseText}catch(o){try{n=t.responseText}catch(o){n=null}}else try{n=t.responseText}catch(o){n=null}if(n)try{this.responseText=""+n,this.response=JSON.parse(n)}catch(o){this.response=null}else this.responseText="(no response)",this.response=null}return t.prototype.status=void 0,t.prototype.method=void 0,t.prototype.url=void 0,t.prototype.responseText=void 0,t.prototype.response=void 0,t.prototype.toString=function(){return"Dropbox API error "+this.status+" from "+this.method+" "+this.url+" :: "+this.responseText},t.prototype.inspect=function(){return""+this},t}(),"undefined"!=typeof window&&null!==window?window.atob&&window.btoa?(c=function(t){return window.atob(t)},m=function(t){return window.btoa(t)}):(f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",g=function(t,e,r){var n,o;for(o=3-e,t<<=8*o,n=3;n>=o;)r.push(f.charAt(63&t>>6*n)),n-=1;for(n=e;3>n;)r.push("="),n+=1;return null},d=function(t,e,r){var n,o;for(o=4-e,t<<=6*o,n=2;n>=o;)r.push(String.fromCharCode(255&t>>8*n)),n-=1;return null},m=function(t){var e,r,n,o,i,s;for(o=[],e=0,r=0,n=i=0,s=t.length;s>=0?s>i:i>s;n=s>=0?++i:--i)e=e<<8|t.charCodeAt(n),r+=1,3===r&&(g(e,r,o),e=r=0);return r>0&&g(e,r,o),o.join("")},c=function(t){var e,r,n,o,i,s,a;for(i=[],e=0,n=0,o=s=0,a=t.length;(a>=0?a>s:s>a)&&(r=t.charAt(o),"="!==r);o=a>=0?++s:--s)e=e<<6|f.indexOf(r),n+=1,4===n&&(d(e,n,i),e=n=0);return n>0&&d(e,n,i),i.join("")}):(c=function(t){var e,r;return e=new Buffer(t,"base64"),function(){var t,n,o;for(o=[],r=t=0,n=e.length;n>=0?n>t:t>n;r=n>=0?++t:--t)o.push(String.fromCharCode(e[r]));return o}().join("")},m=function(t){var e,r;return e=new Buffer(function(){var e,n,o;for(o=[],r=e=0,n=t.length;n>=0?n>e:e>n;r=n>=0?++e:--e)o.push(t.charCodeAt(r));return o}()),e.toString("base64")}),t.Client=function(){function e(e){this.sandbox=e.sandbox||!1,this.apiServer=e.server||this.defaultApiServer(),this.authServer=e.authServer||this.defaultAuthServer(),this.fileServer=e.fileServer||this.defaultFileServer(),this.downloadServer=e.downloadServer||this.defaultDownloadServer(),this.onXhr=new t.EventSource({cancelable:!0}),this.onError=new t.EventSource,this.onAuthStateChange=new t.EventSource,this.oauth=new t.Oauth(e),this.driver=null,this.filter=null,this.uid=null,this.authState=null,this.authError=null,this._credentials=null,this.setCredentials(e),this.setupUrls()}return e.prototype.authDriver=function(t){return this.driver=t,this},e.prototype.onXhr=null,e.prototype.onError=null,e.prototype.onAuthStateChange=null,e.prototype.dropboxUid=function(){return this.uid},e.prototype.credentials=function(){return this._credentials||this.computeCredentials(),this._credentials},e.prototype.authenticate=function(t){var e,r,o=this;if(e=null,!this.driver&&this.authState!==n.DONE)throw Error("Call authDriver to set an authentication driver");return r=function(){var i;if(e!==o.authState&&(null!==e&&o.onAuthStateChange.dispatch(o),e=o.authState,o.driver&&o.driver.onAuthStateChange))return o.driver.onAuthStateChange(o,r);switch(o.authState){case n.RESET:return o.requestToken(function(t,e){var i,s;return t?(o.authError=t,o.authState=n.ERROR):(i=e.oauth_token,s=e.oauth_token_secret,o.oauth.setToken(i,s),o.authState=n.REQUEST),o._credentials=null,r()});case n.REQUEST:return i=o.authorizeUrl(o.oauth.token),o.driver.doAuthorize(i,o.oauth.token,o.oauth.tokenSecret,function(){return o.authState=n.AUTHORIZED,o._credentials=null,r()});case n.AUTHORIZED:return o.getAccessToken(function(t,e){return t?(o.authError=t,o.authState=n.ERROR):(o.oauth.setToken(e.oauth_token,e.oauth_token_secret),o.uid=e.uid,o.authState=n.DONE),o._credentials=null,r()});case n.DONE:return t(null,o);case n.SIGNED_OFF:return o.authState=n.RESET,o.reset(),r();case n.ERROR:return t(o.authError)}},r(),this},e.prototype.isAuthenticated=function(){return this.authState===n.DONE},e.prototype.signOut=function(e){var r,o=this;return r=new t.Xhr("POST",this.urls.signOut),r.signWithOauth(this.oauth),this.dispatchXhr(r,function(t){return t?e(t):(o.authState=n.RESET,o.reset(),o.authState=n.SIGNED_OFF,o.onAuthStateChange.dispatch(o),o.driver.onAuthStateChange?o.driver.onAuthStateChange(o,function(){return e(t)}):e(t))})},e.prototype.signOff=function(t){return this.signOut(t)},e.prototype.getUserInfo=function(e,r){var n,o;return r||"function"!=typeof e||(r=e,e=null),n=!1,e&&e.httpCache&&(n=!0),o=new t.Xhr("GET",this.urls.accountInfo),o.signWithOauth(this.oauth,n),this.dispatchXhr(o,function(e,n){return r(e,t.UserInfo.parse(n),n)})},e.prototype.readFile=function(e,r,n){var o,i,s,a,h,u,l;return n||"function"!=typeof r||(n=r,r=null),i={},u=null,a=null,o=!1,r&&(r.versionTag?i.rev=r.versionTag:r.rev&&(i.rev=r.rev),r.arrayBuffer?u="arraybuffer":r.blob?u="blob":r.binary&&(u="b"),r.length?(null!=r.start?(h=r.start,s=r.start+r.length-1):(h="",s=r.length),a="bytes="+h+"-"+s):null!=r.start&&(a="bytes="+r.start+"-"),r.httpCache&&(o=!0)),l=new t.Xhr("GET",""+this.urls.getFile+"/"+this.urlEncodePath(e)),l.setParams(i).signWithOauth(this.oauth,o),l.setResponseType(u),a&&l.setHeader("Range",a),this.dispatchXhr(l,function(e,r,o){return n(e,r,t.Stat.parse(o))})},e.prototype.writeFile=function(e,r,n,o){var i;return o||"function"!=typeof n||(o=n,n=null),i=t.Xhr.canSendForms&&"object"==typeof r,i?this.writeFileUsingForm(e,r,n,o):this.writeFileUsingPut(e,r,n,o)},e.prototype.writeFileUsingForm=function(e,r,n,o){var i,s,a,h;return a=e.lastIndexOf("/"),-1===a?(i=e,e=""):(i=e.substring(a),e=e.substring(0,a)),s={file:i},n&&(n.noOverwrite&&(s.overwrite="false"),n.lastVersionTag?s.parent_rev=n.lastVersionTag:(n.parentRev||n.parent_rev)&&(s.parent_rev=n.parentRev||n.parent_rev)),h=new t.Xhr("POST",""+this.urls.postFile+"/"+this.urlEncodePath(e)),h.setParams(s).signWithOauth(this.oauth).setFileField("file",i,r,"application/octet-stream"),delete s.file,this.dispatchXhr(h,function(e,r){return o(e,t.Stat.parse(r))})},e.prototype.writeFileUsingPut=function(e,r,n,o){var i,s;return i={},n&&(n.noOverwrite&&(i.overwrite="false"),n.lastVersionTag?i.parent_rev=n.lastVersionTag:(n.parentRev||n.parent_rev)&&(i.parent_rev=n.parentRev||n.parent_rev)),s=new t.Xhr("POST",""+this.urls.putFile+"/"+this.urlEncodePath(e)),s.setBody(r).setParams(i).signWithOauth(this.oauth),this.dispatchXhr(s,function(e,r){return o(e,t.Stat.parse(r))})},e.prototype.resumableUploadStep=function(e,r,n){var o,i;return r?(o={offset:r.offset},r.tag&&(o.upload_id=r.tag)):o={offset:0},i=new t.Xhr("POST",this.urls.chunkedUpload),i.setBody(e).setParams(o).signWithOauth(this.oauth),this.dispatchXhr(i,function(e,r){return e&&400===e.status&&e.response.upload_id&&e.response.offset?n(null,t.UploadCursor.parse(e.response)):n(e,t.UploadCursor.parse(r))})},e.prototype.resumableUploadFinish=function(e,r,n,o){var i,s;return o||"function"!=typeof n||(o=n,n=null),i={upload_id:r.tag},n&&(n.lastVersionTag?i.parent_rev=n.lastVersionTag:(n.parentRev||n.parent_rev)&&(i.parent_rev=n.parentRev||n.parent_rev),n.noOverwrite&&(i.autorename=!0)),s=new t.Xhr("POST",""+this.urls.commitChunkedUpload+"/"+this.urlEncodePath(e)),s.setParams(i).signWithOauth(this.oauth),this.dispatchXhr(s,function(e,r){return o(e,t.Stat.parse(r))})},e.prototype.stat=function(e,r,n){var o,i,s;return n||"function"!=typeof r||(n=r,r=null),i={},o=!1,r&&(null!=r.version&&(i.rev=r.version),(r.removed||r.deleted)&&(i.include_deleted="true"),r.readDir&&(i.list="true",r.readDir!==!0&&(i.file_limit=""+r.readDir)),r.cacheHash&&(i.hash=r.cacheHash),r.httpCache&&(o=!0)),i.include_deleted||(i.include_deleted="false"),i.list||(i.list="false"),s=new t.Xhr("GET",""+this.urls.metadata+"/"+this.urlEncodePath(e)),s.setParams(i).signWithOauth(this.oauth,o),this.dispatchXhr(s,function(e,r){var o,i,s;return s=t.Stat.parse(r),o=(null!=r?r.contents:void 0)?function(){var e,n,o,s;for(o=r.contents,s=[],e=0,n=o.length;n>e;e++)i=o[e],s.push(t.Stat.parse(i));return s}():void 0,n(e,s,o)})},e.prototype.readdir=function(t,e,r){var n;return r||"function"!=typeof e||(r=e,e=null),n={readDir:!0},e&&(null!=e.limit&&(n.readDir=e.limit),e.versionTag&&(n.versionTag=e.versionTag),(e.removed||e.deleted)&&(n.removed=e.removed||e.deleted),e.httpCache&&(n.httpCache=e.httpCache)),this.stat(t,n,function(t,e,n){var o,i;return o=n?function(){var t,e,r;for(r=[],t=0,e=n.length;e>t;t++)i=n[t],r.push(i.name);return r}():null,r(t,o,e,n)})},e.prototype.metadata=function(t,e,r){return this.stat(t,e,r)},e.prototype.makeUrl=function(e,r,n){var o,i,s,a,h;return n||"function"!=typeof r||(n=r,r=null),i=r&&(r["long"]||r.longUrl||r.downloadHack)?{short_url:"false"}:{},e=this.urlEncodePath(e),s=""+this.urls.shares+"/"+e,o=!1,a=!1,r&&(r.downloadHack?(o=!0,a=!0):r.download&&(o=!0,s=""+this.urls.media+"/"+e)),h=new t.Xhr("POST",s).setParams(i).signWithOauth(this.oauth),this.dispatchXhr(h,function(e,r){return a&&r&&r.url&&(r.url=r.url.replace(this.authServer,this.downloadServer)),n(e,t.PublicUrl.parse(r,o))})},e.prototype.history=function(e,r,n){var o,i,s;return n||"function"!=typeof r||(n=r,r=null),i={},o=!1,r&&(null!=r.limit&&(i.rev_limit=r.limit),r.httpCache&&(o=!0)),s=new t.Xhr("GET",""+this.urls.revisions+"/"+this.urlEncodePath(e)),s.setParams(i).signWithOauth(this.oauth,o),this.dispatchXhr(s,function(e,r){var o,i;return i=r?function(){var e,n,i;for(i=[],e=0,n=r.length;n>e;e++)o=r[e],i.push(t.Stat.parse(o));return i}():void 0,n(e,i)})},e.prototype.revisions=function(t,e,r){return this.history(t,e,r)},e.prototype.thumbnailUrl=function(t,e){var r;return r=this.thumbnailXhr(t,e),r.paramsToUrl().url},e.prototype.readThumbnail=function(e,r,n){var o,i;return n||"function"!=typeof r||(n=r,r=null),o="b",r&&r.blob&&(o="blob"),i=this.thumbnailXhr(e,r),i.setResponseType(o),this.dispatchXhr(i,function(e,r,o){return n(e,r,t.Stat.parse(o))})},e.prototype.thumbnailXhr=function(e,r){var n,o;return n={},r&&(r.format?n.format=r.format:r.png&&(n.format="png"),r.size&&(n.size=r.size)),o=new t.Xhr("GET",""+this.urls.thumbnails+"/"+this.urlEncodePath(e)),o.setParams(n).signWithOauth(this.oauth)},e.prototype.revertFile=function(e,r,n){var o;return o=new t.Xhr("POST",""+this.urls.restore+"/"+this.urlEncodePath(e)),o.setParams({rev:r}).signWithOauth(this.oauth),this.dispatchXhr(o,function(e,r){return n(e,t.Stat.parse(r))})},e.prototype.restore=function(t,e,r){return this.revertFile(t,e,r)},e.prototype.findByName=function(e,r,n,o){var i,s,a;return o||"function"!=typeof n||(o=n,n=null),s={query:r},i=!1,n&&(null!=n.limit&&(s.file_limit=n.limit),(n.removed||n.deleted)&&(s.include_deleted=!0),n.httpCache&&(i=!0)),a=new t.Xhr("GET",""+this.urls.search+"/"+this.urlEncodePath(e)),a.setParams(s).signWithOauth(this.oauth,i),this.dispatchXhr(a,function(e,r){var n,i;return i=r?function(){var e,o,i;for(i=[],e=0,o=r.length;o>e;e++)n=r[e],i.push(t.Stat.parse(n));return i}():void 0,o(e,i)})},e.prototype.search=function(t,e,r,n){return this.findByName(t,e,r,n)},e.prototype.makeCopyReference=function(e,r){var n;return n=new t.Xhr("GET",""+this.urls.copyRef+"/"+this.urlEncodePath(e)),n.signWithOauth(this.oauth),this.dispatchXhr(n,function(e,n){return r(e,t.CopyReference.parse(n))})},e.prototype.copyRef=function(t,e){return this.makeCopyReference(t,e)},e.prototype.pullChanges=function(e,r){var n,o;return r||"function"!=typeof e||(r=e,e=null),n=e?e.cursorTag?{cursor:e.cursorTag}:{cursor:e}:{},o=new t.Xhr("POST",this.urls.delta),o.setParams(n).signWithOauth(this.oauth),this.dispatchXhr(o,function(e,n){return r(e,t.PulledChanges.parse(n))})},e.prototype.delta=function(t,e){return this.pullChanges(t,e)},e.prototype.mkdir=function(e,r){var n;return n=new t.Xhr("POST",this.urls.fileopsCreateFolder),n.setParams({root:this.fileRoot,path:this.normalizePath(e)}).signWithOauth(this.oauth),this.dispatchXhr(n,function(e,n){return r(e,t.Stat.parse(n))})},e.prototype.remove=function(e,r){var n;return n=new t.Xhr("POST",this.urls.fileopsDelete),n.setParams({root:this.fileRoot,path:this.normalizePath(e)}).signWithOauth(this.oauth),this.dispatchXhr(n,function(e,n){return r(e,t.Stat.parse(n))})},e.prototype.unlink=function(t,e){return this.remove(t,e)},e.prototype["delete"]=function(t,e){return this.remove(t,e)},e.prototype.copy=function(e,r,n){var o,i,s;return n||"function"!=typeof o||(n=o,o=null),i={root:this.fileRoot,to_path:this.normalizePath(r)},e instanceof t.CopyReference?i.from_copy_ref=e.tag:i.from_path=this.normalizePath(e),s=new t.Xhr("POST",this.urls.fileopsCopy),s.setParams(i).signWithOauth(this.oauth),this.dispatchXhr(s,function(e,r){return n(e,t.Stat.parse(r))})},e.prototype.move=function(e,r,n){var o,i;return n||"function"!=typeof o||(n=o,o=null),i=new t.Xhr("POST",this.urls.fileopsMove),i.setParams({root:this.fileRoot,from_path:this.normalizePath(e),to_path:this.normalizePath(r)}).signWithOauth(this.oauth),this.dispatchXhr(i,function(e,r){return n(e,t.Stat.parse(r))})},e.prototype.reset=function(){var t;return this.uid=null,this.oauth.setToken(null,""),t=this.authState,this.authState=n.RESET,t!==this.authState&&this.onAuthStateChange.dispatch(this),this.authError=null,this._credentials=null,this},e.prototype.setCredentials=function(t){var e;return e=this.authState,this.oauth.reset(t),this.uid=t.uid||null,this.authState=t.authState?t.authState:t.token?n.DONE:n.RESET,this.authError=null,this._credentials=null,e!==this.authState&&this.onAuthStateChange.dispatch(this),this},e.prototype.appHash=function(){return this.oauth.appHash()},e.prototype.setupUrls=function(){return this.fileRoot=this.sandbox?"sandbox":"dropbox",this.urls={requestToken:""+this.apiServer+"/1/oauth/request_token",authorize:""+this.authServer+"/1/oauth/authorize",accessToken:""+this.apiServer+"/1/oauth/access_token",signOut:""+this.apiServer+"/1/unlink_access_token",accountInfo:""+this.apiServer+"/1/account/info",getFile:""+this.fileServer+"/1/files/"+this.fileRoot,postFile:""+this.fileServer+"/1/files/"+this.fileRoot,putFile:""+this.fileServer+"/1/files_put/"+this.fileRoot,metadata:""+this.apiServer+"/1/metadata/"+this.fileRoot,delta:""+this.apiServer+"/1/delta",revisions:""+this.apiServer+"/1/revisions/"+this.fileRoot,restore:""+this.apiServer+"/1/restore/"+this.fileRoot,search:""+this.apiServer+"/1/search/"+this.fileRoot,shares:""+this.apiServer+"/1/shares/"+this.fileRoot,media:""+this.apiServer+"/1/media/"+this.fileRoot,copyRef:""+this.apiServer+"/1/copy_ref/"+this.fileRoot,thumbnails:""+this.fileServer+"/1/thumbnails/"+this.fileRoot,chunkedUpload:""+this.fileServer+"/1/chunked_upload",commitChunkedUpload:""+this.fileServer+"/1/commit_chunked_upload/"+this.fileRoot,fileopsCopy:""+this.apiServer+"/1/fileops/copy",fileopsCreateFolder:""+this.apiServer+"/1/fileops/create_folder",fileopsDelete:""+this.apiServer+"/1/fileops/delete",fileopsMove:""+this.apiServer+"/1/fileops/move"}},e.prototype.authState=null,e.ERROR=0,e.RESET=1,e.REQUEST=2,e.AUTHORIZED=3,e.DONE=4,e.SIGNED_OFF=5,e.prototype.urlEncodePath=function(e){return t.Xhr.urlEncodeValue(this.normalizePath(e)).replace(/%2F/gi,"/")},e.prototype.normalizePath=function(t){var e;if("/"===t.substring(0,1)){for(e=1;"/"===t.substring(e,e+1);)e+=1;return t.substring(e)}return t},e.prototype.requestToken=function(e){var r;return r=new t.Xhr("POST",this.urls.requestToken).signWithOauth(this.oauth),this.dispatchXhr(r,e)},e.prototype.authorizeUrl=function(e){var r;return r={oauth_token:e,oauth_callback:this.driver.url()},""+this.urls.authorize+"?"+t.Xhr.urlEncode(r)},e.prototype.getAccessToken=function(e){var r;return r=new t.Xhr("POST",this.urls.accessToken).signWithOauth(this.oauth),this.dispatchXhr(r,e)},e.prototype.dispatchXhr=function(t,e){var r;return t.setCallback(e),t.onError=this.onError,t.prepare(),r=t.xhr,this.onXhr.dispatch(t)&&t.send(),r},e.prototype.defaultApiServer=function(){return"https://api.dropbox.com"},e.prototype.defaultAuthServer=function(){return this.apiServer.replace("api.","www.")},e.prototype.defaultFileServer=function(){return this.apiServer.replace("api.","api-content.")},e.prototype.defaultDownloadServer=function(){return this.apiServer.replace("api.","dl.")},e.prototype.computeCredentials=function(){var t;return t={key:this.oauth.key,sandbox:this.sandbox},this.oauth.secret&&(t.secret=this.oauth.secret),this.oauth.token&&(t.token=this.oauth.token,t.tokenSecret=this.oauth.tokenSecret),this.uid&&(t.uid=this.uid),this.authState!==n.ERROR&&this.authState!==n.RESET&&this.authState!==n.DONE&&this.authState!==n.SIGNED_OFF&&(t.authState=this.authState),this.apiServer!==this.defaultApiServer()&&(t.server=this.apiServer),this.authServer!==this.defaultAuthServer()&&(t.authServer=this.authServer),this.fileServer!==this.defaultFileServer()&&(t.fileServer=this.fileServer),this.downloadServer!==this.defaultDownloadServer()&&(t.downloadServer=this.downloadServer),this._credentials=t},e}(),n=t.Client,t.AuthDriver=function(){function t(){}return t.prototype.url=function(){return"https://some.url"},t.prototype.doAuthorize=function(t,e,r,n){return n("oauth-token")},t.prototype.onAuthStateChange=function(t,e){return e()},t}(),t.Drivers={},t.Drivers.BrowserBase=function(){function t(t){this.rememberUser=(null!=t?t.rememberUser:void 0)||!1,this.scope=(null!=t?t.scope:void 0)||"default",this.storageKey=null}return t.prototype.onAuthStateChange=function(t,e){var r=this;switch(this.setStorageKey(t),t.authState){case n.RESET:return this.loadCredentials(function(n){return n?n.authState?(t.setCredentials(n),e()):r.rememberUser?(t.setCredentials(n),t.getUserInfo(function(n){return n?(t.reset(),r.forgetCredentials(e)):e()})):(r.forgetCredentials(),e()):e()});case n.REQUEST:return this.storeCredentials(t.credentials(),e);case n.DONE:return this.rememberUser?this.storeCredentials(t.credentials(),e):this.forgetCredentials(e);case n.SIGNED_OFF:return this.forgetCredentials(e);case n.ERROR:return this.forgetCredentials(e);default:return e(),this}},t.prototype.setStorageKey=function(t){return this.storageKey="dropbox-auth:"+this.scope+":"+t.appHash(),this},t.prototype.storeCredentials=function(t,e){return localStorage.setItem(this.storageKey,JSON.stringify(t)),e(),this},t.prototype.loadCredentials=function(t){var e;if(e=localStorage.getItem(this.storageKey),!e)return t(null),this;try{t(JSON.parse(e))}catch(r){t(null)}return this},t.prototype.forgetCredentials=function(t){return localStorage.removeItem(this.storageKey),t(),this},t.currentLocation=function(){return window.location.href},t}(),t.Drivers.Redirect=function(e){function r(t){r.__super__.constructor.call(this,t),this.useQuery=(null!=t?t.useQuery:void 0)||!1,this.receiverUrl=this.computeUrl(t),this.tokenRe=RegExp("(#|\\?|&)oauth_token=([^]+)(&|#|$)")}return T(r,e),r.prototype.onAuthStateChange=function(t,e){var o,i=this;return o=function(){return function(){return r.__super__.onAuthStateChange.call(i,t,e)}}(),this.setStorageKey(t),t.authState===n.RESET?this.loadCredentials(function(t){return t&&t.authState?t.token===i.locationToken()&&t.authState===n.REQUEST?(t.authState=n.AUTHORIZED,i.storeCredentials(t,o)):i.forgetCredentials(o):o()}):o()},r.prototype.url=function(){return this.receiverUrl},r.prototype.doAuthorize=function(t){return window.location.assign(t)},r.prototype.computeUrl=function(){var e,r,n,o;return o="_dropboxjs_scope="+encodeURIComponent(this.scope),r=t.Drivers.BrowserBase.currentLocation(),-1===r.indexOf("#")?e=null:(n=r.split("#",2),r=n[0],e=n[1]),this.useQuery?r+=-1===r.indexOf("?")?"?"+o:"&"+o:e="?"+o,e?r+"#"+e:r},r.prototype.locationToken=function(){var e,r,n;return e=t.Drivers.BrowserBase.currentLocation(),n="_dropboxjs_scope="+encodeURIComponent(this.scope)+"&",-1===("function"==typeof e.indexOf?e.indexOf(n):void 0)?null:(r=this.tokenRe.exec(e),r?decodeURIComponent(r[2]):null)},r}(t.Drivers.BrowserBase),t.Drivers.Popup=function(e){function r(t){r.__super__.constructor.call(this,t),this.receiverUrl=this.computeUrl(t),this.tokenRe=RegExp("(#|\\?|&)oauth_token=([^]+)(&|#|$)")}return T(r,e),r.prototype.onAuthStateChange=function(t,e){var o,i=this;return o=function(){return function(){return r.__super__.onAuthStateChange.call(i,t,e)}}(),this.setStorageKey(t),t.authState===n.RESET?this.loadCredentials(function(t){return t&&t.authState?i.forgetCredentials(o):o()}):o()},r.prototype.doAuthorize=function(t,e,r,n){return this.listenForMessage(e,n),this.openWindow(t)},r.prototype.url=function(){return this.receiverUrl},r.prototype.computeUrl=function(e){var r;if(e){if(e.receiverUrl)return e.noFragment||-1!==e.receiverUrl.indexOf("#")?e.receiverUrl:e.receiverUrl+"#";if(e.receiverFile)return r=t.Drivers.BrowserBase.currentLocation().split("/"),r[r.length-1]=e.receiverFile,e.noFragment?r.join("/"):r.join("/")+"#"}return t.Drivers.BrowserBase.currentLocation()},r.prototype.openWindow=function(t){return window.open(t,"_dropboxOauthSigninWindow",this.popupWindowSpec(980,700))},r.prototype.popupWindowSpec=function(t,e){var r,n,o,i,s,a,h,u,l,p;return s=null!=(h=window.screenX)?h:window.screenLeft,a=null!=(u=window.screenY)?u:window.screenTop,i=null!=(l=window.outerWidth)?l:document.documentElement.clientWidth,r=null!=(p=window.outerHeight)?p:document.documentElement.clientHeight,n=Math.round(s+(i-t)/2),o=Math.round(a+(r-e)/2.5),s>n&&(n=s),a>o&&(o=a),"width="+t+",height="+e+","+("left="+n+",top="+o)+"dialog=yes,dependent=yes,scrollbars=yes,location=yes"},r.prototype.listenForMessage=function(t,e){var r,n=this;return r=function(o){var i;return i=n.tokenRe.exec(""+o.data),i&&decodeURIComponent(i[2])===t?(window.removeEventListener("message",r),e()):void 0},window.addEventListener("message",r,!1)},r.oauthReceiver=function(){return window.addEventListener("load",function(){var t;if(t=window.opener,window.parent!==window.top&&(t||(t=window.parent)),t){try{t.postMessage(window.location.href,"*")}catch(e){}return window.close()}})},r}(t.Drivers.BrowserBase),e=null,r=null,"undefined"!=typeof chrome&&null!==chrome&&(chrome.runtime&&(chrome.runtime.onMessage&&(e=chrome.runtime.onMessage),chrome.runtime.sendMessage&&(r=function(t){return chrome.runtime.sendMessage(t)})),chrome.extension&&(chrome.extension.onMessage&&(e||(e=chrome.extension.onMessage)),chrome.extension.sendMessage&&(r||(r=function(t){return chrome.extension.sendMessage(t)}))),e||function(){var e,r;return r=function(e){return e.Dropbox?(t.Drivers.Chrome.prototype.onMessage=e.Dropbox.Drivers.Chrome.onMessage,t.Drivers.Chrome.prototype.sendMessage=e.Dropbox.Drivers.Chrome.sendMessage):(e.Dropbox=t,t.Drivers.Chrome.prototype.onMessage=new t.EventSource,t.Drivers.Chrome.prototype.sendMessage=function(e){return t.Drivers.Chrome.prototype.onMessage.dispatch(e)})},chrome.extension&&chrome.extension.getBackgroundPage&&(e=chrome.extension.getBackgroundPage())?r(e):chrome.runtime&&chrome.runtime.getBackgroundPage?chrome.runtime.getBackgroundPage(function(t){return r(t)}):void 0}()),t.Drivers.Chrome=function(){function n(t){var e,r;e=t&&t.receiverPath||"chrome_oauth_receiver.html",this.receiverUrl=this.expandUrl(e),this.tokenRe=RegExp("(#|\\?|&)oauth_token=([^]+)(&|#|$)"),r=t&&t.scope||"default",this.storageKey="dropbox_js_"+r+"_credentials"}return n.prototype.onMessage=e,n.prototype.sendMessage=r,n.prototype.expandUrl=function(t){return chrome.runtime&&chrome.runtime.getURL?chrome.runtime.getURL(t):chrome.extension&&chrome.extension.getURL?chrome.extension.getURL(t):t},n.prototype.onAuthStateChange=function(e,r){var n=this;switch(e.authState){case t.Client.RESET:return this.loadCredentials(function(t){if(t){if(t.authState)return n.forgetCredentials(r);e.setCredentials(t)}return r()});case t.Client.DONE:return this.storeCredentials(e.credentials(),r);case t.Client.SIGNED_OFF:return this.forgetCredentials(r);case t.Client.ERROR:return this.forgetCredentials(r);default:return r()}},n.prototype.doAuthorize=function(t,e,r,n){var o;return o={handle:null},this.listenForMessage(e,o,n),this.openWindow(t,function(t){return o.handle=t})},n.prototype.openWindow=function(t,e){return chrome.tabs&&chrome.tabs.create?(chrome.tabs.create({url:t,active:!0,pinned:!1},function(t){return e(t)}),this):chrome.app&&chrome.app.window&&chrome.app.window.create?(chrome.app.window.create(t,{frame:"none",id:"dropbox-auth"},function(t){return e(t)}),this):this},n.prototype.closeWindow=function(t){return chrome.tabs&&chrome.tabs.remove&&t.id?(chrome.tabs.remove(t.id),this):chrome.app&&chrome.app.window&&t.close?(t.close(),this):this},n.prototype.url=function(){return this.receiverUrl},n.prototype.listenForMessage=function(t,e,r){var n,o=this;return n=function(i,s){var a;if(!s||!s.tab||s.tab.url.substring(0,o.receiverUrl.length)===o.receiverUrl)return a=o.tokenRe.exec(i.dropbox_oauth_receiver_href||""),a&&decodeURIComponent(a[2])===t?(e.handle&&o.closeWindow(e.handle),o.onMessage.removeListener(n),r()):void 0},this.onMessage.addListener(n)},n.prototype.storeCredentials=function(t,e){var r;return r={},r[this.storageKey]=t,chrome.storage.local.set(r,e),this},n.prototype.loadCredentials=function(t){var e=this;return chrome.storage.local.get(this.storageKey,function(r){return t(r[e.storageKey]||null)}),this},n.prototype.forgetCredentials=function(t){return chrome.storage.local.remove(this.storageKey,t),this},n.oauthReceiver=function(){return window.addEventListener("load",function(){var e;return e=new t.Drivers.Chrome,e.sendMessage({dropbox_oauth_receiver_href:window.location.href}),window.close?window.close():void 0})},n}(),t.Drivers.NodeServer=function(){function t(t){this.port=(null!=t?t.port:void 0)||8912,this.faviconFile=(null!=t?t.favicon:void 0)||null,this.fs=require("fs"),this.http=require("http"),this.open=require("open"),this.callbacks={},this.urlRe=RegExp("^/oauth_callback\\?"),this.tokenRe=RegExp("(\\?|&)oauth_token=([^&]+)(&|$)"),this.createApp()}return t.prototype.url=function(){return"http://localhost:"+this.port+"/oauth_callback"},t.prototype.doAuthorize=function(t,e,r,n){return this.callbacks[e]=n,this.openBrowser(t)},t.prototype.openBrowser=function(t){if(!t.match(/^https?:\/\//))throw Error("Not a http/https URL: "+t);return this.open(t)},t.prototype.createApp=function(){var t=this;return this.app=this.http.createServer(function(e,r){return t.doRequest(e,r)}),this.app.listen(this.port)},t.prototype.closeServer=function(){return this.app.close()},t.prototype.doRequest=function(t,e){var r,n,o,i=this;return this.urlRe.exec(t.url)&&(n=this.tokenRe.exec(t.url),n&&(o=decodeURIComponent(n[2]),this.callbacks[o]&&(this.callbacks[o](),delete this.callbacks[o]))),r="",t.on("data",function(t){return r+=t}),t.on("end",function(){return i.faviconFile&&"/favicon.ico"===t.url?i.sendFavicon(e):i.closeBrowser(e)})},t.prototype.closeBrowser=function(t){var e;return e='\n\nPlease close this window.
',t.writeHead(200,{"Content-Length":e.length,"Content-Type":"text/html"}),t.write(e),t.end},t.prototype.sendFavicon=function(t){return this.fs.readFile(this.faviconFile,function(e,r){return t.writeHead(200,{"Content-Length":r.length,"Content-Type":"image/x-icon"}),t.write(r),t.end})},t}(),t.EventSource=function(){function t(t){this._cancelable=t&&t.cancelable,this._listeners=[]}return t.prototype.addListener=function(t){if("function"!=typeof t)throw new TypeError("Invalid listener type; expected function");return 0>k.call(this._listeners,t)&&this._listeners.push(t),this},t.prototype.removeListener=function(t){var e,r,n,o,i,s;if(this._listeners.indexOf)r=this._listeners.indexOf(t),-1!==r&&this._listeners.splice(r,1);else for(s=this._listeners,e=o=0,i=s.length;i>o;e=++o)if(n=s[e],n===t){this._listeners.splice(e,1);break}return this},t.prototype.dispatch=function(t){var e,r,n,o,i;for(i=this._listeners,n=0,o=i.length;o>n;n++)if(e=i[n],r=e(t),this._cancelable&&r===!1)return!1;return!0},t}(),y=function(t,e){return p(b(C(t),C(e),t.length,e.length))},v=function(t){return p(E(C(t),t.length))},("undefined"==typeof window||null===window)&&(w=require("crypto"),y=function(t,e){var r;return r=w.createHmac("sha1",e),r.update(t),r.digest("base64")},v=function(t){var e;return e=w.createHash("sha1"),e.update(t),e.digest("base64")}),b=function(t,e,r,n){var o,i,s,a;return e.length>16&&(e=E(e,n)),s=function(){var t,r;for(r=[],i=t=0;16>t;i=++t)r.push(909522486^e[i]);return r}(),a=function(){var t,r;for(r=[],i=t=0;16>t;i=++t)r.push(1549556828^e[i]);return r}(),o=E(s.concat(t),64+r),E(a.concat(o),84)},E=function(t,e){var r,n,o,i,s,a,h,u,p,c,d,f,y,v,m,g,w,S;for(t[e>>2]|=1<<31-((3&e)<<3),t[(e+8>>6<<4)+15]=e<<3,g=Array(80),r=1732584193,o=-271733879,s=-1732584194,h=271733878,p=-1009589776,f=0,m=t.length;m>f;){for(n=r,i=o,a=s,u=h,c=p,y=S=0;80>S;y=++S)g[y]=16>y?t[f+y]:_(g[y-3]^g[y-8]^g[y-14]^g[y-16],1),20>y?(d=o&s|~o&h,v=1518500249):40>y?(d=o^s^h,v=1859775393):60>y?(d=o&s|o&h|s&h,v=-1894007588):(d=o^s^h,v=-899497514),w=l(l(_(r,5),d),l(l(p,g[y]),v)),p=h,h=s,s=_(o,30),o=r,r=w;r=l(r,n),o=l(o,i),s=l(s,a),h=l(h,u),p=l(p,c),f+=16}return[r,o,s,h,p]},_=function(t,e){return t<e;e++)if(e in this&&this[e]===t)return e;return-1};if(t=function(){function t(t){this.client=new e(t)}return t}(),t.ApiError=function(){function t(t,e,r){var n;if(this.method=e,this.url=r,this.status=t.status,n=t.responseType?t.response||t.responseText:t.responseText)try{this.responseText=""+n,this.response=JSON.parse(n)}catch(o){this.response=null}else this.responseText="(no response)",this.response=null}return t.prototype.status=void 0,t.prototype.method=void 0,t.prototype.url=void 0,t.prototype.responseText=void 0,t.prototype.response=void 0,t.prototype.toString=function(){return"Dropbox API error "+this.status+" from "+this.method+" "+this.url+" :: "+this.responseText},t.prototype.inspect=function(){return""+this},t}(),"undefined"!=typeof window&&null!==window?window.atob&&window.btoa?(u=function(t){return window.atob(t)},f=function(t){return window.btoa(t)}):(p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",y=function(t,e,r){var n,o;for(o=3-e,t<<=8*o,n=3;n>=o;)r.push(p.charAt(63&t>>6*n)),n-=1;for(n=e;3>n;)r.push("="),n+=1;return null},l=function(t,e,r){var n,o;for(o=4-e,t<<=6*o,n=2;n>=o;)r.push(String.fromCharCode(255&t>>8*n)),n-=1;return null},f=function(t){var e,r,n,o,i,s;for(o=[],e=0,r=0,n=i=0,s=t.length;s>=0?s>i:i>s;n=s>=0?++i:--i)e=e<<8|t.charCodeAt(n),r+=1,3===r&&(y(e,r,o),e=r=0);return r>0&&y(e,r,o),o.join("")},u=function(t){var e,r,n,o,i,s,a;for(i=[],e=0,n=0,o=s=0,a=t.length;(a>=0?a>s:s>a)&&(r=t.charAt(o),"="!==r);o=a>=0?++s:--s)e=e<<6|p.indexOf(r),n+=1,4===n&&(l(e,n,i),e=n=0);return n>0&&l(e,n,i),i.join("")}):(u=function(t){var e,r;return e=new Buffer(t,"base64"),function(){var t,n,o;for(o=[],r=t=0,n=e.length;n>=0?n>t:t>n;r=n>=0?++t:--t)o.push(String.fromCharCode(e[r]));return o}().join("")},f=function(t){var e,r;return e=new Buffer(function(){var e,n,o;for(o=[],r=e=0,n=t.length;n>=0?n>e:e>n;r=n>=0?++e:--e)o.push(t.charCodeAt(r));return o}()),e.toString("base64")}),t.Client=function(){function r(e){this.sandbox=e.sandbox||!1,this.apiServer=e.server||this.defaultApiServer(),this.authServer=e.authServer||this.defaultAuthServer(),this.fileServer=e.fileServer||this.defaultFileServer(),this.downloadServer=e.downloadServer||this.defaultDownloadServer(),this.onXhr=new t.EventSource({cancelable:!0}),this.onError=new t.EventSource,this.onAuthStateChange=new t.EventSource,this.oauth=new t.Oauth(e),this.driver=null,this.filter=null,this.uid=null,this.authState=null,this.authError=null,this._credentials=null,this.setCredentials(e),this.setupUrls()}return r.prototype.authDriver=function(t){return this.driver=t,this},r.prototype.onXhr=null,r.prototype.onError=null,r.prototype.onAuthStateChange=null,r.prototype.dropboxUid=function(){return this.uid},r.prototype.credentials=function(){return this._credentials||this.computeCredentials(),this._credentials},r.prototype.authenticate=function(r){var n,o,i=this;if(n=null,!this.driver&&this.authState!==e.DONE)throw Error("Call authDriver to set an authentication driver");return o=function(){var s;if(n!==i.authState&&(null!==n&&i.onAuthStateChange.dispatch(i),n=i.authState,i.driver&&i.driver.onAuthStateChange))return i.driver.onAuthStateChange(i,o);switch(i.authState){case e.RESET:return i.requestToken(function(t,r){var n,s;return t?(i.authError=t,i.authState=e.ERROR):(n=r.oauth_token,s=r.oauth_token_secret,i.oauth.setToken(n,s),i.authState=e.REQUEST),i._credentials=null,o()});case e.REQUEST:return s=i.authorizeUrl(i.oauth.token),i.driver.doAuthorize(s,i.oauth.token,i.oauth.tokenSecret,function(){return i.authState=e.AUTHORIZED,i._credentials=null,o()});case e.AUTHORIZED:return i.getAccessToken(function(t,r){return t?(i.authError=t,i.authState=e.ERROR):(i.oauth.setToken(r.oauth_token,r.oauth_token_secret),i.uid=r.uid,i.authState=e.DONE),i._credentials=null,o()});case e.DONE:return r(null,i);case t.SIGNED_OFF:return i.authState=e.RESET,i.reset(),o();case e.ERROR:return r(i.authError)}},o(),this},r.prototype.isAuthenticated=function(){return this.authState===e.DONE},r.prototype.signOut=function(r){var n,o=this;return n=new t.Xhr("POST",this.urls.signOut),n.signWithOauth(this.oauth),this.dispatchXhr(n,function(t){return t?r(t):(o.authState=e.RESET,o.reset(),o.authState=e.SIGNED_OFF,o.onAuthStateChange.dispatch(o),o.driver.onAuthStateChange?o.driver.onAuthStateChange(o,function(){return r(t)}):r(t))})},r.prototype.signOff=function(t){return this.signOut(t)},r.prototype.getUserInfo=function(e){var r;return r=new t.Xhr("GET",this.urls.accountInfo),r.signWithOauth(this.oauth),this.dispatchXhr(r,function(r,n){return e(r,t.UserInfo.parse(n),n)})},r.prototype.readFile=function(e,r,n){var o,i,s,a,h,u;return n||"function"!=typeof r||(n=r,r=null),o={},h=null,s=null,r&&(r.versionTag?o.rev=r.versionTag:r.rev&&(o.rev=r.rev),r.arrayBuffer?h="arraybuffer":r.blob?h="blob":r.binary&&(h="b"),r.length?(null!=r.start?(a=r.start,i=r.start+r.length-1):(a="",i=r.length),s="bytes="+a+"-"+i):null!=r.start&&(s="bytes="+r.start+"-")),u=new t.Xhr("GET",""+this.urls.getFile+"/"+this.urlEncodePath(e)),u.setParams(o).signWithOauth(this.oauth).setResponseType(h),s&&u.setHeader("Range",s),this.dispatchXhr(u,function(e,r,o){return n(e,r,t.Stat.parse(o))})},r.prototype.writeFile=function(e,r,n,o){var i;return o||"function"!=typeof n||(o=n,n=null),i=t.Xhr.canSendForms&&"object"==typeof r,i?this.writeFileUsingForm(e,r,n,o):this.writeFileUsingPut(e,r,n,o)},r.prototype.writeFileUsingForm=function(e,r,n,o){var i,s,a,h;return a=e.lastIndexOf("/"),-1===a?(i=e,e=""):(i=e.substring(a),e=e.substring(0,a)),s={file:i},n&&(n.noOverwrite&&(s.overwrite="false"),n.lastVersionTag?s.parent_rev=n.lastVersionTag:(n.parentRev||n.parent_rev)&&(s.parent_rev=n.parentRev||n.parent_rev)),h=new t.Xhr("POST",""+this.urls.postFile+"/"+this.urlEncodePath(e)),h.setParams(s).signWithOauth(this.oauth).setFileField("file",i,r,"application/octet-stream"),delete s.file,this.dispatchXhr(h,function(e,r){return o(e,t.Stat.parse(r))})},r.prototype.writeFileUsingPut=function(e,r,n,o){var i,s;return i={},n&&(n.noOverwrite&&(i.overwrite="false"),n.lastVersionTag?i.parent_rev=n.lastVersionTag:(n.parentRev||n.parent_rev)&&(i.parent_rev=n.parentRev||n.parent_rev)),s=new t.Xhr("POST",""+this.urls.putFile+"/"+this.urlEncodePath(e)),s.setBody(r).setParams(i).signWithOauth(this.oauth),this.dispatchXhr(s,function(e,r){return o(e,t.Stat.parse(r))})},r.prototype.resumableUploadStep=function(e,r,n){var o,i;return r?(o={offset:r.offset},r.tag&&(o.upload_id=r.tag)):o={offset:0},i=new t.Xhr("POST",this.urls.chunkedUpload),i.setBody(e).setParams(o).signWithOauth(this.oauth),this.dispatchXhr(i,function(e,r){return e&&400===e.status&&e.response.upload_id&&e.response.offset?n(null,t.UploadCursor.parse(e.response)):n(e,t.UploadCursor.parse(r))})},r.prototype.resumableUploadFinish=function(e,r,n,o){var i,s;return o||"function"!=typeof n||(o=n,n=null),i={upload_id:r.tag},n&&(n.lastVersionTag?i.parent_rev=n.lastVersionTag:(n.parentRev||n.parent_rev)&&(i.parent_rev=n.parentRev||n.parent_rev),n.noOverwrite&&(i.autorename=!0)),s=new t.Xhr("POST",""+this.urls.commitChunkedUpload+"/"+this.urlEncodePath(e)),s.setParams(i).signWithOauth(this.oauth),this.dispatchXhr(s,function(e,r){return o(e,t.Stat.parse(r))})},r.prototype.stat=function(e,r,n){var o,i;return n||"function"!=typeof r||(n=r,r=null),o={},r&&(null!=r.version&&(o.rev=r.version),(r.removed||r.deleted)&&(o.include_deleted="true"),r.readDir&&(o.list="true",r.readDir!==!0&&(o.file_limit=""+r.readDir)),r.cacheHash&&(o.hash=r.cacheHash)),o.include_deleted||(o.include_deleted="false"),o.list||(o.list="false"),i=new t.Xhr("GET",""+this.urls.metadata+"/"+this.urlEncodePath(e)),i.setParams(o).signWithOauth(this.oauth),this.dispatchXhr(i,function(e,r){var o,i,s;return s=t.Stat.parse(r),o=(null!=r?r.contents:void 0)?function(){var e,n,o,s;for(o=r.contents,s=[],e=0,n=o.length;n>e;e++)i=o[e],s.push(t.Stat.parse(i));return s}():void 0,n(e,s,o)})},r.prototype.readdir=function(t,e,r){var n;return r||"function"!=typeof e||(r=e,e=null),n={readDir:!0},e&&(null!=e.limit&&(n.readDir=e.limit),e.versionTag&&(n.versionTag=e.versionTag)),this.stat(t,n,function(t,e,n){var o,i;return o=n?function(){var t,e,r;for(r=[],t=0,e=n.length;e>t;t++)i=n[t],r.push(i.name);return r}():null,r(t,o,e,n)})},r.prototype.metadata=function(t,e,r){return this.stat(t,e,r)},r.prototype.makeUrl=function(e,r,n){var o,i,s,a,h;return n||"function"!=typeof r||(n=r,r=null),i=r&&(r["long"]||r.longUrl||r.downloadHack)?{short_url:"false"}:{},e=this.urlEncodePath(e),s=""+this.urls.shares+"/"+e,o=!1,a=!1,r&&(r.downloadHack?(o=!0,a=!0):r.download&&(o=!0,s=""+this.urls.media+"/"+e)),h=new t.Xhr("POST",s).setParams(i).signWithOauth(this.oauth),this.dispatchXhr(h,function(e,r){return a&&r&&r.url&&(r.url=r.url.replace(this.authServer,this.downloadServer)),n(e,t.PublicUrl.parse(r,o))})},r.prototype.history=function(e,r,n){var o,i;return n||"function"!=typeof r||(n=r,r=null),o={},r&&null!=r.limit&&(o.rev_limit=r.limit),i=new t.Xhr("GET",""+this.urls.revisions+"/"+this.urlEncodePath(e)),i.setParams(o).signWithOauth(this.oauth),this.dispatchXhr(i,function(e,r){var o,i;return i=r?function(){var e,n,i;for(i=[],e=0,n=r.length;n>e;e++)o=r[e],i.push(t.Stat.parse(o));return i}():void 0,n(e,i)})},r.prototype.revisions=function(t,e,r){return this.history(t,e,r)},r.prototype.thumbnailUrl=function(t,e){var r;return r=this.thumbnailXhr(t,e),r.paramsToUrl().url},r.prototype.readThumbnail=function(e,r,n){var o,i;return n||"function"!=typeof r||(n=r,r=null),o="b",r&&r.blob&&(o="blob"),i=this.thumbnailXhr(e,r),i.setResponseType(o),this.dispatchXhr(i,function(e,r,o){return n(e,r,t.Stat.parse(o))})},r.prototype.thumbnailXhr=function(e,r){var n,o;return n={},r&&(r.format?n.format=r.format:r.png&&(n.format="png"),r.size&&(n.size=r.size)),o=new t.Xhr("GET",""+this.urls.thumbnails+"/"+this.urlEncodePath(e)),o.setParams(n).signWithOauth(this.oauth)},r.prototype.revertFile=function(e,r,n){var o;return o=new t.Xhr("POST",""+this.urls.restore+"/"+this.urlEncodePath(e)),o.setParams({rev:r}).signWithOauth(this.oauth),this.dispatchXhr(o,function(e,r){return n(e,t.Stat.parse(r))})},r.prototype.restore=function(t,e,r){return this.revertFile(t,e,r)},r.prototype.findByName=function(e,r,n,o){var i,s;return o||"function"!=typeof n||(o=n,n=null),i={query:r},n&&(null!=n.limit&&(i.file_limit=n.limit),(n.removed||n.deleted)&&(i.include_deleted=!0)),s=new t.Xhr("GET",""+this.urls.search+"/"+this.urlEncodePath(e)),s.setParams(i).signWithOauth(this.oauth),this.dispatchXhr(s,function(e,r){var n,i;return i=r?function(){var e,o,i;for(i=[],e=0,o=r.length;o>e;e++)n=r[e],i.push(t.Stat.parse(n));return i}():void 0,o(e,i)})},r.prototype.search=function(t,e,r,n){return this.findByName(t,e,r,n)},r.prototype.makeCopyReference=function(e,r){var n;return n=new t.Xhr("GET",""+this.urls.copyRef+"/"+this.urlEncodePath(e)),n.signWithOauth(this.oauth),this.dispatchXhr(n,function(e,n){return r(e,t.CopyReference.parse(n))})},r.prototype.copyRef=function(t,e){return this.makeCopyReference(t,e)},r.prototype.pullChanges=function(e,r){var n,o;return r||"function"!=typeof e||(r=e,e=null),n=e?e.cursorTag?{cursor:e.cursorTag}:{cursor:e}:{},o=new t.Xhr("POST",this.urls.delta),o.setParams(n).signWithOauth(this.oauth),this.dispatchXhr(o,function(e,n){return r(e,t.PulledChanges.parse(n))})},r.prototype.delta=function(t,e){return this.pullChanges(t,e)},r.prototype.mkdir=function(e,r){var n;return n=new t.Xhr("POST",this.urls.fileopsCreateFolder),n.setParams({root:this.fileRoot,path:this.normalizePath(e)}).signWithOauth(this.oauth),this.dispatchXhr(n,function(e,n){return r(e,t.Stat.parse(n))})},r.prototype.remove=function(e,r){var n;return n=new t.Xhr("POST",this.urls.fileopsDelete),n.setParams({root:this.fileRoot,path:this.normalizePath(e)}).signWithOauth(this.oauth),this.dispatchXhr(n,function(e,n){return r(e,t.Stat.parse(n))})},r.prototype.unlink=function(t,e){return this.remove(t,e)},r.prototype["delete"]=function(t,e){return this.remove(t,e)},r.prototype.copy=function(e,r,n){var o,i,s;return n||"function"!=typeof o||(n=o,o=null),i={root:this.fileRoot,to_path:this.normalizePath(r)},e instanceof t.CopyReference?i.from_copy_ref=e.tag:i.from_path=this.normalizePath(e),s=new t.Xhr("POST",this.urls.fileopsCopy),s.setParams(i).signWithOauth(this.oauth),this.dispatchXhr(s,function(e,r){return n(e,t.Stat.parse(r))})},r.prototype.move=function(e,r,n){var o,i;return n||"function"!=typeof o||(n=o,o=null),i=new t.Xhr("POST",this.urls.fileopsMove),i.setParams({root:this.fileRoot,from_path:this.normalizePath(e),to_path:this.normalizePath(r)}).signWithOauth(this.oauth),this.dispatchXhr(i,function(e,r){return n(e,t.Stat.parse(r))})},r.prototype.reset=function(){var t;return this.uid=null,this.oauth.setToken(null,""),t=this.authState,this.authState=e.RESET,t!==this.authState&&this.onAuthStateChange.dispatch(this),this.authError=null,this._credentials=null,this},r.prototype.setCredentials=function(t){var r;return r=this.authState,this.oauth.reset(t),this.uid=t.uid||null,this.authState=t.authState?t.authState:t.token?e.DONE:e.RESET,this.authError=null,this._credentials=null,r!==this.authState&&this.onAuthStateChange.dispatch(this),this},r.prototype.appHash=function(){return this.oauth.appHash()},r.prototype.setupUrls=function(){return this.fileRoot=this.sandbox?"sandbox":"dropbox",this.urls={requestToken:""+this.apiServer+"/1/oauth/request_token",authorize:""+this.authServer+"/1/oauth/authorize",accessToken:""+this.apiServer+"/1/oauth/access_token",signOut:""+this.apiServer+"/1/unlink_access_token",accountInfo:""+this.apiServer+"/1/account/info",getFile:""+this.fileServer+"/1/files/"+this.fileRoot,postFile:""+this.fileServer+"/1/files/"+this.fileRoot,putFile:""+this.fileServer+"/1/files_put/"+this.fileRoot,metadata:""+this.apiServer+"/1/metadata/"+this.fileRoot,delta:""+this.apiServer+"/1/delta",revisions:""+this.apiServer+"/1/revisions/"+this.fileRoot,restore:""+this.apiServer+"/1/restore/"+this.fileRoot,search:""+this.apiServer+"/1/search/"+this.fileRoot,shares:""+this.apiServer+"/1/shares/"+this.fileRoot,media:""+this.apiServer+"/1/media/"+this.fileRoot,copyRef:""+this.apiServer+"/1/copy_ref/"+this.fileRoot,thumbnails:""+this.fileServer+"/1/thumbnails/"+this.fileRoot,chunkedUpload:""+this.fileServer+"/1/chunked_upload",commitChunkedUpload:""+this.fileServer+"/1/commit_chunked_upload/"+this.fileRoot,fileopsCopy:""+this.apiServer+"/1/fileops/copy",fileopsCreateFolder:""+this.apiServer+"/1/fileops/create_folder",fileopsDelete:""+this.apiServer+"/1/fileops/delete",fileopsMove:""+this.apiServer+"/1/fileops/move"}},r.prototype.authState=null,r.ERROR=0,r.RESET=1,r.REQUEST=2,r.AUTHORIZED=3,r.DONE=4,r.SIGNED_OFF=5,r.prototype.urlEncodePath=function(e){return t.Xhr.urlEncodeValue(this.normalizePath(e)).replace(/%2F/gi,"/")},r.prototype.normalizePath=function(t){var e;if("/"===t.substring(0,1)){for(e=1;"/"===t.substring(e,e+1);)e+=1;return t.substring(e)}return t},r.prototype.requestToken=function(e){var r;return r=new t.Xhr("POST",this.urls.requestToken).signWithOauth(this.oauth),this.dispatchXhr(r,e)},r.prototype.authorizeUrl=function(e){var r;return r={oauth_token:e,oauth_callback:this.driver.url()},""+this.urls.authorize+"?"+t.Xhr.urlEncode(r)},r.prototype.getAccessToken=function(e){var r;return r=new t.Xhr("POST",this.urls.accessToken).signWithOauth(this.oauth),this.dispatchXhr(r,e)},r.prototype.dispatchXhr=function(t,e){var r;return t.setCallback(e),t.onError=this.onError,t.prepare(),r=t.xhr,this.onXhr.dispatch(t)&&t.send(),r},r.prototype.defaultApiServer=function(){return"https://api.dropbox.com"},r.prototype.defaultAuthServer=function(){return this.apiServer.replace("api.","www.")},r.prototype.defaultFileServer=function(){return this.apiServer.replace("api.","api-content.")},r.prototype.defaultDownloadServer=function(){return this.apiServer.replace("api.","dl.")},r.prototype.computeCredentials=function(){var t;return t={key:this.oauth.key,sandbox:this.sandbox},this.oauth.secret&&(t.secret=this.oauth.secret),this.oauth.token&&(t.token=this.oauth.token,t.tokenSecret=this.oauth.tokenSecret),this.uid&&(t.uid=this.uid),this.authState!==e.ERROR&&this.authState!==e.RESET&&this.authState!==e.DONE&&this.authState!==e.SIGNED_OFF&&(t.authState=this.authState),this.apiServer!==this.defaultApiServer()&&(t.server=this.apiServer),this.authServer!==this.defaultAuthServer()&&(t.authServer=this.authServer),this.fileServer!==this.defaultFileServer()&&(t.fileServer=this.fileServer),this.downloadServer!==this.defaultDownloadServer()&&(t.downloadServer=this.downloadServer),this._credentials=t},r}(),e=t.Client,t.AuthDriver=function(){function t(){}return t.prototype.url=function(){return"https://some.url"},t.prototype.doAuthorize=function(t,e,r,n){return n("oauth-token")},t.prototype.onAuthStateChange=function(t,e){return e()},t}(),t.Drivers={},t.Drivers.BrowserBase=function(){function t(t){this.rememberUser=(null!=t?t.rememberUser:void 0)||!1,this.scope=(null!=t?t.scope:void 0)||"default"}return t.prototype.onAuthStateChange=function(t,r){var n=this;switch(this.setStorageKey(t),t.authState){case e.RESET:return this.loadCredentials(function(e){return e?e.authState?(t.setCredentials(e),r()):n.rememberUser?(t.setCredentials(e),t.getUserInfo(function(e){return e?(t.reset(),n.forgetCredentials(r)):r()})):(n.forgetCredentials(),r()):r()});case e.REQUEST:return this.storeCredentials(t.credentials(),r);case e.DONE:return this.rememberUser?this.storeCredentials(t.credentials(),r):this.forgetCredentials(r);case e.SIGNED_OFF:return this.forgetCredentials(r);case e.ERROR:return this.forgetCredentials(r);default:return r(),this}},t.prototype.setStorageKey=function(t){return this.storageKey="dropbox-auth:"+this.scope+":"+t.appHash(),this},t.prototype.storeCredentials=function(t,e){return localStorage.setItem(this.storageKey,JSON.stringify(t)),e(),this},t.prototype.loadCredentials=function(t){var e;if(e=localStorage.getItem(this.storageKey),!e)return t(null),this;try{t(JSON.parse(e))}catch(r){t(null)}return this},t.prototype.forgetCredentials=function(t){return localStorage.removeItem(this.storageKey),t(),this},t.currentLocation=function(){return window.location.href},t}(),t.Drivers.Redirect=function(r){function n(t){n.__super__.constructor.call(this,t),this.useQuery=(null!=t?t.useQuery:void 0)||!1,this.receiverUrl=this.computeUrl(t),this.tokenRe=RegExp("(#|\\?|&)oauth_token=([^]+)(&|#|$)")}return T(n,r),n.prototype.onAuthStateChange=function(t,r){var o,i=this;return o=function(){return function(){return n.__super__.onAuthStateChange.call(i,t,r)}}(),this.setStorageKey(t),t.authState===e.RESET?this.loadCredentials(function(t){return t&&t.authState?t.token===i.locationToken()&&t.authState===e.REQUEST?(t.authState=e.AUTHORIZED,i.storeCredentials(t,o)):i.forgetCredentials(o):o()}):o()},n.prototype.url=function(){return this.receiverUrl},n.prototype.doAuthorize=function(t){return window.location.assign(t)},n.prototype.computeUrl=function(){var e,r,n,o;return o="_dropboxjs_scope="+encodeURIComponent(this.scope),r=t.Drivers.BrowserBase.currentLocation(),-1===r.indexOf("#")?e=null:(n=r.split("#",2),r=n[0],e=n[1]),this.useQuery?r+=-1===r.indexOf("?")?"?"+o:"&"+o:e="?"+o,e?r+"#"+e:r},n.prototype.locationToken=function(){var e,r,n;return e=t.Drivers.BrowserBase.currentLocation(),n="_dropboxjs_scope="+encodeURIComponent(this.scope)+"&",-1===("function"==typeof e.indexOf?e.indexOf(n):void 0)?null:(r=this.tokenRe.exec(e),r?decodeURIComponent(r[2]):null)},n}(t.Drivers.BrowserBase),t.Drivers.Popup=function(r){function n(t){n.__super__.constructor.call(this,t),this.receiverUrl=this.computeUrl(t),this.tokenRe=RegExp("(#|\\?|&)oauth_token=([^]+)(&|#|$)")}return T(n,r),n.prototype.onAuthStateChange=function(t,r){var o,i=this;return o=function(){return function(){return n.__super__.onAuthStateChange.call(i,t,r)}}(),this.setStorageKey(t),t.authState===e.RESET?this.loadCredentials(function(t){return t&&t.authState?i.forgetCredentials(o):o()}):o()},n.prototype.doAuthorize=function(t,e,r,n){return this.listenForMessage(e,n),this.openWindow(t)},n.prototype.url=function(){return this.receiverUrl},n.prototype.computeUrl=function(e){var r;if(e){if(e.receiverUrl)return e.noFragment||-1!==e.receiverUrl.indexOf("#")?e.receiverUrl:e.receiverUrl+"#";if(e.receiverFile)return r=t.Drivers.BrowserBase.currentLocation().split("/"),r[r.length-1]=e.receiverFile,e.noFragment?r.join("/"):r.join("/")+"#"}return t.Drivers.BrowserBase.currentLocation()},n.prototype.openWindow=function(t){return window.open(t,"_dropboxOauthSigninWindow",this.popupWindowSpec(980,700))},n.prototype.popupWindowSpec=function(t,e){var r,n,o,i,s,a,h,u,l,p;return s=null!=(h=window.screenX)?h:window.screenLeft,a=null!=(u=window.screenY)?u:window.screenTop,i=null!=(l=window.outerWidth)?l:document.documentElement.clientWidth,r=null!=(p=window.outerHeight)?p:document.documentElement.clientHeight,n=Math.round(s+(i-t)/2),o=Math.round(a+(r-e)/2.5),s>n&&(n=s),a>o&&(o=a),"width="+t+",height="+e+","+("left="+n+",top="+o)+"dialog=yes,dependent=yes,scrollbars=yes,location=yes"},n.prototype.listenForMessage=function(t,e){var r,n=this;return r=function(o){var i;return i=n.tokenRe.exec(""+o.data),i&&decodeURIComponent(i[2])===t?(window.removeEventListener("message",r),e()):void 0},window.addEventListener("message",r,!1)},n}(t.Drivers.BrowserBase),t.Drivers.NodeServer=function(){function t(t){this.port=(null!=t?t.port:void 0)||8912,this.faviconFile=(null!=t?t.favicon:void 0)||null,this.fs=require("fs"),this.http=require("http"),this.open=require("open"),this.callbacks={},this.urlRe=RegExp("^/oauth_callback\\?"),this.tokenRe=RegExp("(\\?|&)oauth_token=([^&]+)(&|$)"),this.createApp()}return t.prototype.url=function(){return"http://localhost:"+this.port+"/oauth_callback"},t.prototype.doAuthorize=function(t,e,r,n){return this.callbacks[e]=n,this.openBrowser(t)},t.prototype.openBrowser=function(t){if(!t.match(/^https?:\/\//))throw Error("Not a http/https URL: "+t);return this.open(t)},t.prototype.createApp=function(){var t=this;return this.app=this.http.createServer(function(e,r){return t.doRequest(e,r)}),this.app.listen(this.port)},t.prototype.closeServer=function(){return this.app.close()},t.prototype.doRequest=function(t,e){var r,n,o,i=this;return this.urlRe.exec(t.url)&&(n=this.tokenRe.exec(t.url),n&&(o=decodeURIComponent(n[2]),this.callbacks[o]&&(this.callbacks[o](),delete this.callbacks[o]))),r="",t.on("data",function(t){return r+=t}),t.on("end",function(){return i.faviconFile&&"/favicon.ico"===t.url?i.sendFavicon(e):i.closeBrowser(e)})},t.prototype.closeBrowser=function(t){var e;return e='\n\n
Please close this window.
',t.writeHead(200,{"Content-Length":e.length,"Content-Type":"text/html"}),t.write(e),t.end},t.prototype.sendFavicon=function(t){return this.fs.readFile(this.faviconFile,function(e,r){return t.writeHead(200,{"Content-Length":r.length,"Content-Type":"image/x-icon"}),t.write(r),t.end})},t}(),t.EventSource=function(){function t(t){this._cancelable=t&&t.cancelable,this._listeners=[]}return t.prototype.addListener=function(t){if("function"!=typeof t)throw new TypeError("Invalid listener type; expected function");return 0>R.call(this._listeners,t)&&this._listeners.push(t),this},t.prototype.removeListener=function(t){var e,r,n,o,i,s;if(this._listeners.indexOf)r=this._listeners.indexOf(t),-1!==r&&this._listeners.splice(r,1);else for(s=this._listeners,e=o=0,i=s.length;i>o;e=++o)if(n=s[e],n===t){this._listeners.splice(e,1);break}return this},t.prototype.dispatch=function(t){var e,r,n,o,i;for(i=this._listeners,n=0,o=i.length;o>n;n++)if(e=i[n],r=e(t),this._cancelable&&r===!1)return!1;return!0},t}(),c=function(t,e){return h(g(b(t),b(e),t.length,e.length))},d=function(t){return h(S(b(t),t.length))},("undefined"==typeof window||null===window)&&(v=require("crypto"),c=function(t,e){var r;return r=v.createHmac("sha1",e),r.update(t),r.digest("base64")},d=function(t){var e;return e=v.createHash("sha1"),e.update(t),e.digest("base64")}),g=function(t,e,r,n){var o,i,s,a;return e.length>16&&(e=S(e,n)),s=function(){var t,r;for(r=[],i=t=0;16>t;i=++t)r.push(909522486^e[i]);return r}(),a=function(){var t,r;for(r=[],i=t=0;16>t;i=++t)r.push(1549556828^e[i]);return r}(),o=S(s.concat(t),64+r),S(a.concat(o),84)},S=function(t,e){var r,n,o,i,s,h,u,l,p,c,d,f,y,v,m,g,S,b;for(t[e>>2]|=1<<31-((3&e)<<3),t[(e+8>>6<<4)+15]=e<<3,g=Array(80),r=1732584193,o=-271733879,s=-1732584194,u=271733878,p=-1009589776,f=0,m=t.length;m>f;){for(n=r,i=o,h=s,l=u,c=p,y=b=0;80>b;y=++b)g[y]=16>y?t[f+y]:w(g[y-3]^g[y-8]^g[y-14]^g[y-16],1),20>y?(d=o&s|~o&u,v=1518500249):40>y?(d=o^s^u,v=1859775393):60>y?(d=o&s|o&u|s&u,v=-1894007588):(d=o^s^u,v=-899497514),S=a(a(w(r,5),d),a(a(p,g[y]),v)),p=u,u=s,s=w(o,30),o=r,r=S;r=a(r,n),o=a(o,i),s=a(s,h),u=a(u,l),p=a(p,c),f+=16}return[r,o,s,u,p]},w=function(t,e){return t<| t |