UNPKG

ares-ide

Version:

A browser-based code editor and UI designer for Enyo 2 projects

1,603 lines (1,408 loc) 103 kB
// Generated by CoffeeScript 1.6.2 (function() { var Dropbox, DropboxChromeOnMessage, DropboxChromeSendMessage, DropboxClient, DropboxXhrArrayBufferView, DropboxXhrCanSendForms, DropboxXhrDoesPreflight, DropboxXhrIeMode, DropboxXhrRequest, DropboxXhrSendArrayBufferView, DropboxXhrWrapBlob, add32, arrayToBase64, atob, atobNibble, base64Digits, base64HmacSha1, base64Sha1, blobError, btoa, btoaNibble, crypto, dropboxEncodeKey, hmacSha1, name, requireError, rotateLeft32, sha1, stringToArray, value, _base64Digits, __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; }, __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; }; Dropbox = function() { return null; }; Dropbox.Util = {}; 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; })(); 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; ApiError.NETWORK_ERROR = 0; ApiError.INVALID_PARAM = 400; ApiError.INVALID_TOKEN = 401; ApiError.OAUTH_ERROR = 403; ApiError.NOT_FOUND = 404; ApiError.INVALID_METHOD = 405; ApiError.RATE_LIMITED = 503; ApiError.OVER_QUOTA = 507; function ApiError(xhr, method, url) { var text, xhrError; this.method = method; this.url = url; this.status = xhr.status; if (xhr.responseType) { try { text = xhr.response || xhr.responseText; } catch (_error) { xhrError = _error; try { text = xhr.responseText; } catch (_error) { xhrError = _error; text = null; } } } else { try { text = xhr.responseText; } catch (_error) { xhrError = _error; text = null; } } if (text) { try { this.responseText = text.toString(); this.response = JSON.parse(text); } catch (_error) { xhrError = _error; 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; })(); Dropbox.AuthDriver = (function() { function AuthDriver() {} AuthDriver.prototype.url = function(token) { return "https://some.url?dboauth_token=" + (Dropbox.Xhr.urlEncode(token)); }; AuthDriver.prototype.doAuthorize = function(authUrl, token, tokenSecret, callback) { return callback('oauth-token'); }; AuthDriver.prototype.onAuthStateChange = function(client, callback) { return callback(); }; return AuthDriver; })(); Dropbox.Drivers = {}; if (typeof atob === 'function' && typeof btoa === 'function') { atob = function(string) { return window.atob(string); }; btoa = function(base64) { return window.btoa(base64); }; } else if ((typeof window !== 'undefined' || typeof self !== 'undefined') && (typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string')) { 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.Util.atob = atob; Dropbox.Util.btoa = btoa; Dropbox.Client = (function() { function Client(options) { var _this = this; 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.xhrOnErrorHandler = function(error, callback) { return _this.handleXhrError(error, callback); }; 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(options, callback) { var interactive, oldAuthState, _fsmStep, _this = this; if (!callback && typeof options === 'function') { callback = options; options = null; } if (options && 'interactive' in options) { interactive = options.interactive; } else { interactive = true; } if (!(this.driver || this.authState === DropboxClient.DONE)) { throw new Error('Call authDriver to set an authentication driver'); } if (this.authState === DropboxClient.ERROR) { throw new Error('Client got in an error state. Call reset() to reuse it!'); } oldAuthState = null; _fsmStep = function() { var authUrl; if (oldAuthState !== _this.authState) { oldAuthState = _this.authState; if (_this.driver && _this.driver.onAuthStateChange) { _this.driver.onAuthStateChange(_this, _fsmStep); return; } } switch (_this.authState) { case DropboxClient.RESET: if (!interactive) { if (callback) { callback(null, _this); } return; } 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; _this.onAuthStateChange.dispatch(_this); return _fsmStep(); }); case DropboxClient.REQUEST: if (!interactive) { if (callback) { callback(null, _this); } return; } 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; _this.onAuthStateChange.dispatch(_this); 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; _this.onAuthStateChange.dispatch(_this); return _fsmStep(); }); case DropboxClient.DONE: if (callback) { callback(null, _this); } break; case DropboxClient.SIGNED_OFF: _this.authState = DropboxClient.RESET; _this.reset(); return _fsmStep(); case DropboxClient.ERROR: if (callback) { callback(_this.authError, _this); } } }; _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) { if (callback) { callback(error); } return; } _this.authState = DropboxClient.RESET; _this.reset(); _this.authState = DropboxClient.SIGNED_OFF; _this.onAuthStateChange.dispatch(_this); if (_this.driver && _this.driver.onAuthStateChange) { return _this.driver.onAuthStateChange(_this, function() { if (callback) { return callback(error); } }); } else { if (callback) { 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 = 'text'; 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.buffer) { responseType = 'buffer'; } 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) { if (rangeHeader) { xhr.setHeader('Range', rangeHeader); } xhr.reportResponseHeaders(); } return this.dispatchXhr(xhr, function(error, data, metadata, headers) { var rangeInfo; if (headers) { rangeInfo = Dropbox.RangeInfo.parse(headers['content-range']); } else { rangeInfo = null; } return callback(error, data, Dropbox.Stat.parse(metadata), rangeInfo); }); }; 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) { if (callback) { 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) { if (callback) { 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 === Dropbox.ApiError.INVALID_PARAM && error.response && 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.overwrite = 'false'; } } xhr = new Dropbox.Xhr('POST', "" + this.urls.commitChunkedUpload + "/" + (this.urlEncodePath(path))); xhr.setParams(params).signWithOauth(this.oauth); return this.dispatchXhr(xhr, function(error, metadata) { if (callback) { 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, _this = this; 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 != null ? urlData.url : void 0)) { 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'; } if (options.arrayBuffer) { responseType = 'arraybuffer'; } if (options.buffer) { responseType = 'buffer'; } } 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) { if (callback) { 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) { if (callback) { 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) { if (callback) { 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) { if (callback) { 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) { if (callback) { 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 callbackUrl, params; callbackUrl = this.driver.url(token); if (callbackUrl === null) { params = { oauth_token: token }; } else { params = { oauth_token: token, oauth_callback: callbackUrl }; } 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.xhrOnErrorHandler; xhr.prepare(); nativeXhr = xhr.xhr; if (this.onXhr.dispatch(xhr)) { xhr.send(); } return nativeXhr; }; Client.prototype.handleXhrError = function(error, callback) { var _this = this; if (error.status === Dropbox.ApiError.INVALID_TOKEN && this.authState === DropboxClient.DONE) { this.authError = error; this.authState = DropboxClient.ERROR; this.onAuthStateChange.dispatch(this); if (this.driver && this.driver.onAuthStateChange) { this.driver.onAuthStateChange(this, function() { _this.onError.dispatch(error); return callback(error); }); return null; } } this.onError.dispatch(error); callback(error); return null; }; 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.Drivers.BrowserBase = (function() { function BrowserBase(options) { this.rememberUser = (options != null ? options.rememberUser : void 0) || false; this.useQuery = (options != null ? options.useQuery : void 0) || false; this.scope = (options != null ? options.scope : void 0) || 'default'; this.storageKey = null; this.dbTokenRe = new RegExp("(#|\\?|&)dboauth_token=([^&#]+)(&|#|$)"); this.rejectedRe = new RegExp("(#|\\?|&)not_approved=true(&|#|$)"); this.tokenRe = new RegExp("(#|\\?|&)oauth_token=([^&#]+)(&|#|$)"); } 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) { return _this.forgetCredentials(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 jsonError, jsonString; jsonString = localStorage.getItem(this.storageKey); if (!jsonString) { callback(null); return this; } try { callback(JSON.parse(jsonString)); } catch (_error) { jsonError = _error; callback(null); } return this; }; BrowserBase.prototype.forgetCredentials = function(callback) { localStorage.removeItem(this.storageKey); callback(); return this; }; BrowserBase.prototype.computeUrl = function(baseUrl) { var fragment, location, locationPair, querySuffix; querySuffix = "_dropboxjs_scope=" + (encodeURIComponent(this.scope)) + "&dboauth_token="; location = baseUrl; 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; } if (fragment) { return [location, '#' + fragment]; } else { return [location, '']; } } else { return [location + '#?' + querySuffix, '']; } }; BrowserBase.prototype.locationToken = function(url) { var location, match, scopePattern; location = url || Dropbox.Drivers.BrowserBase.currentLocation(); scopePattern = "_dropboxjs_scope=" + (encodeURIComponent(this.scope)) + "&"; if ((typeof location.indexOf === "function" ? location.indexOf(scopePattern) : void 0) === -1) { return null; } if (this.rejectedRe.test(location)) { match = this.dbTokenRe.exec(location); if (match) { return decodeURIComponent(match[2]); } else { return null; } } match = this.tokenRe.exec(location); if (match) { return decodeURIComponent(match[2]); } return null; }; BrowserBase.currentLocation = function() { return window.location.href; }; return BrowserBase; })(); Dropbox.Drivers.Redirect = (function(_super) { __extends(Redirect, _super); function Redirect(options) { var _ref; Redirect.__super__.constructor.call(this, options); _ref = this.computeUrl(Dropbox.Drivers.BrowserBase.currentLocation()), this.receiverUrl1 = _ref[0], this.receiverUrl2 = _ref[1]; } 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(token) { return this.receiverUrl1 + encodeURIComponent(token) + this.receiverUrl2; }; Redirect.prototype.doAuthorize = function(authUrl) { return window.location.assign(authUrl); }; return Redirect; })(Dropbox.Drivers.BrowserBase); Dropbox.Drivers.Popup = (function(_super) { __extends(Popup, _super); function Popup(options) { var _ref; Popup.__super__.constructor.call(this, options); _ref = this.computeUrl(this.baseUrl(options)), this.receiverUrl1 = _ref[0], this.receiverUrl2 = _ref[1]; } 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(token) { return this.receiverUrl1 + encodeURIComponent(token) + this.receiverUrl2; }; Popup.prototype.baseUrl = function(options) { var fragments; if (options) { if (options.receiverUrl) { return options.receiverUrl; } else if (options.receiverFile) { fragments = Dropbox.Drivers.BrowserBase.currentLocation().split('/'); fragments[fragments.length - 1] = options.receiverFile; 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 - popupHei