!function(){var t,e,r,n,i,o,s,a,u,h,l,p,c,d={}.hasOwnProperty,f=[].indexOf||function(t){for(var e=0,r=this.length;r>e;e++)if(e in this&&this[e]===t)return e;return-1},y=function(t,e){function r(){this.constructor=t}for(var n in e)d.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};if(c=function(){function t(){}return t}(),c.Util=function(){function t(){}return t}(),c.Http=function(){function t(){}return t}(),c.File=function(){function t(){}return t}(),"undefined"!=typeof global&&"undefined"!=typeof module&&"exports"in module)n=global,i=module.require.bind(module),module.exports=c;else if("undefined"!=typeof window&&"undefined"!=typeof navigator)n=window,i=null,window.Dropbox&&function(){var t,e,r,n;r=window.Dropbox,n=[];for(t in r)d.call(r,t)&&(e=r[t],n.push(c[t]=e));return n}(),window.Dropbox=c;else{if("undefined"==typeof self||"undefined"==typeof navigator)throw new Error("dropbox.js loaded in an unsupported JavaScript environment.");n=self,i=self.importScripts.bind(self),self.Dropbox=c}if(c.Env=function(){function t(){}return t.global=n,t.require=i,t}(),c.Util.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 f.call(this._listeners,t)<0&&this._listeners.push(t),this},t.prototype.removeListener=function(t){var e,r,n,i,o,s;if(this._listeners.indexOf)r=this._listeners.indexOf(t),-1!==r&&this._listeners.splice(r,1);else for(s=this._listeners,e=i=0,o=s.length;o>i;e=++i)if(n=s[e],n===t){this._listeners.splice(e,1);break}return this},t.prototype.dispatch=function(t){var e,r,n,i,o;for(o=this._listeners,n=0,i=o.length;i>n;n++)if(e=o[n],r=e(t),this._cancelable&&r===!1)return!1;return!0},t}(),c.AccountInfo=function(){function t(t){var e;this._json=t,this.name=t.display_name,this.email=t.email,this.countryCode=t.country||null,this.uid=t.uid.toString(),t.public_app_url?(this.publicAppUrl=t.public_app_url,e=this.publicAppUrl.length-1,e>=0&&"/"===this.publicAppUrl.substring(e)&&(this.publicAppUrl=this.publicAppUrl.substring(0,e))):this.publicAppUrl=null,this.referralUrl=t.referral_link,this.quota=t.quota_info.quota,this.privateBytes=t.quota_info.normal||0,this.sharedBytes=t.quota_info.shared||0,this.usedQuota=this.privateBytes+this.sharedBytes}return t.parse=function(t){return t&&"object"==typeof t?new c.AccountInfo(t):t},t.prototype.name=null,t.prototype.email=null,t.prototype.countryCode=null,t.prototype.uid=null,t.prototype.referralUrl=null,t.prototype.publicAppUrl=null,t.prototype.quota=null,t.prototype.usedQuota=null,t.prototype.privateBytes=null,t.prototype.sharedBytes=null,t.prototype.json=function(){return this._json},t}(),c.ApiError=function(){function t(t,e,r){var n,i;if(this.method=e,this.url=r,this.status=t.status,t.responseType)try{n=t.response||t.responseText}catch(o){i=o;try{n=t.responseText}catch(o){i=o,n=null}}else try{n=t.responseText}catch(o){i=o,n=null}if(n)try{this.responseText=n.toString(),this.response=JSON.parse(n)}catch(o){i=o,this.response=null}else this.responseText="(no response)",this.response=null}return t.prototype.status=null,t.prototype.method=null,t.prototype.url=null,t.prototype.responseText=null,t.prototype.response=null,t.NETWORK_ERROR=0,t.NO_CONTENT=304,t.INVALID_PARAM=400,t.INVALID_TOKEN=401,t.OAUTH_ERROR=403,t.NOT_FOUND=404,t.INVALID_METHOD=405,t.NOT_ACCEPTABLE=406,t.CONFLICT=409,t.RATE_LIMITED=429,t.SERVER_ERROR=503,t.OVER_QUOTA=507,t.prototype.toString=function(){return"Dropbox API error "+this.status+" from "+this.method+" "+this.url+" :: "+this.responseText},t.prototype.inspect=function(){return this.toString()},t}(),c.AuthDriver=function(){function t(){}return t.prototype.authType=function(){return"code"},t.prototype.url=function(){return"https://some.url"},t.prototype.doAuthorize=function(t,e,r,n){return n({code:"access-code"})},t.prototype.getStateParam=function(t,e){return e(c.Util.Oauth.randomAuthStateParam())},t.prototype.resumeAuthorize=function(t,e,r){return r({code:"access-code"})},t.prototype.onAuthStateChange=function(t,e){return e()},t.oauthQueryParams=["access_token","expires_in","scope","token_type","code","error","error_description","error_uri","mac_key","mac_algorithm"].sort(),t}(),c.AuthDriver.autoConfigure=function(t){if("undefined"!=typeof chrome&&(chrome.extension||chrome.app&&chrome.app.runtime))return t.authDriver(new c.AuthDriver.Chrome),void 0;if("undefined"!=typeof window){if(window.cordova)return t.authDriver(new c.AuthDriver.Cordova),void 0;window&&window.navigator&&t.authDriver(new c.AuthDriver.Redirect)}},c.AuthDriver.BrowserBase=function(){function t(t){t?(this.rememberUser="rememberUser"in t?t.rememberUser:!0,this.scope=t.scope||"default"):(this.rememberUser=!0,this.scope="default"),this.storageKey=null,this.stateRe=/^[^#]+\#(.*&)?state=([^&]+)(&|$)/}return t.prototype.authType=function(){return"token"},t.prototype.onAuthStepChange=function(t,e){var r=this;switch(this.setStorageKey(t),t.authStep){case c.Client.RESET:return this.loadCredentials(function(n){return n?(t.setCredentials(n),t.authStep!==c.Client.DONE?e():r.rememberUser?(t.setCredentials(n),t.getAccountInfo(function(n){return n&&n.status===c.ApiError.INVALID_TOKEN?(t.reset(),r.forgetCredentials(e)):e()})):r.forgetCredentials(e)):e()});case c.Client.DONE:return this.rememberUser?this.storeCredentials(t.credentials(),e):this.forgetCredentials(e);case c.Client.SIGNED_OUT:return this.forgetCredentials(e);case c.Client.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,r;if(r=localStorage.getItem(this.storageKey),!r)return t(null),this;try{t(JSON.parse(r))}catch(n){e=n,t(null)}return this},t.prototype.forgetCredentials=function(t){return localStorage.removeItem(this.storageKey),t(),this},t.prototype.locationStateParam=function(t){var e,r;return e=t||c.AuthDriver.BrowserBase.currentLocation(),r=this.stateRe.exec(e),r?decodeURIComponent(r[2]):null},t.prototype.replaceUrlBasename=function(t,e){var r,n,i;return n=t.indexOf("#"),-1!==n&&(t=t.substring(0,n)),i=t.indexOf("?"),-1!==i&&(t=t.substring(0,i)),r=t.split("/"),r[r.length-1]=e,r.join("/")},t.currentLocation=function(){return window.location.href},t.cleanupLocation=function(){var t,e;window.history&&window.history.replaceState?(e=this.currentLocation(),t=e.indexOf("#"),window.history.replaceState({},document.title,e.substring(0,t))):window.location.hash=""},t}(),c.AuthDriver.Redirect=function(t){function e(t){e.__super__.constructor.call(this,t),this.receiverUrl=this.baseUrl(t)}return y(e,t),e.prototype.baseUrl=function(t){var e,r;if(r=c.AuthDriver.BrowserBase.currentLocation(),t){if(t.redirectUrl)return t.redirectUrl;if(t.redirectFile)return this.replaceUrlBasename(r,t.redirectFile)}return e=r.indexOf("#"),-1!==e&&(r=r.substring(0,e)),r},e.prototype.url=function(){return this.receiverUrl},e.prototype.doAuthorize=function(t,e,r){return this.storeCredentials(r.credentials(),function(){return window.location.assign(t)})},e.prototype.resumeAuthorize=function(t,e,r){var n;return this.locationStateParam()===t?(n=c.AuthDriver.BrowserBase.currentLocation(),c.AuthDriver.BrowserBase.cleanupLocation(),r(c.Util.Oauth.queryParamsFromUrl(n))):this.forgetCredentials(function(){return r({error:"Authorization error"})})},e}(c.AuthDriver.BrowserBase),c.AuthDriver.Popup=function(t){function e(t){e.__super__.constructor.call(this,t),this.receiverUrl=this.baseUrl(t)}return y(e,t),e.prototype.url=function(){return this.receiverUrl},e.prototype.doAuthorize=function(t,e,r,n){return this.listenForMessage(e,n),this.openWindow(t)},e.prototype.baseUrl=function(t){var e;if(e=c.AuthDriver.BrowserBase.currentLocation(),t){if(t.receiverUrl)return t.receiverUrl;if(t.receiverFile)return this.replaceUrlBasename(e,t.receiverFile)}return e},e.prototype.openWindow=function(t){return window.open(t,"_dropboxOauthSigninWindow",this.popupWindowSpec(980,700))},e.prototype.popupWindowSpec=function(t,e){var r,n,i,o,s,a,u,h,l,p;return s=null!=(u=window.screenX)?u:window.screenLeft,a=null!=(h=window.screenY)?h:window.screenTop,o=null!=(l=window.outerWidth)?l:document.documentElement.clientWidth,r=null!=(p=window.outerHeight)?p:document.documentElement.clientHeight,n=Math.round(s+(o-t)/2),i=Math.round(a+(r-e)/2.5),s>n&&(n=s),a>i&&(i=a),"width="+t+",height="+e+","+("left="+n+",top="+i)+"dialog=yes,dependent=yes,scrollbars=yes,location=yes"},e.prototype.listenForMessage=function(t,e){var r,n=this;return r=function(i){var o,s,a;o=i.data?i.data:i;try{a=JSON.parse(o)._dropboxjs_oauth_info}catch(u){return s=u,void 0}if(a)return n.locationStateParam(a)===t?(t=!1,window.removeEventListener("message",r),c.AuthDriver.Popup.onMessage.removeListener(r),e(c.Util.Oauth.queryParamsFromUrl(o))):void 0},window.addEventListener("message",r,!1),c.AuthDriver.Popup.onMessage.addListener(r)},e.locationOrigin=function(t){var e;return(e=/^(file:\/\/[^\?\#]*)(\?|\#|$)/.exec(t))?e[1]:(e=/^([^\:]+\:\/\/[^\/\?\#]*)(\/|\?|\#|$)/.exec(t),e?e[1]:t)},e.oauthReceiver=function(){window.addEventListener("load",function(){var t,e,r,n,i,o;if(o=window.location.href,r=JSON.stringify({_dropboxjs_oauth_info:o}),c.AuthDriver.BrowserBase.cleanupLocation(),n=window.opener,window.parent!==window.top&&(n||(n=window.parent)),n){try{i=window.location.origin||locationOrigin(o),n.postMessage(r,i),window.close()}catch(s){e=s}try{return n.Dropbox.AuthDriver.Popup.onMessage.dispatch(r),window.close()}catch(s){t=s}}})},e.onMessage=new c.Util.EventSource,e}(c.AuthDriver.BrowserBase),t=null,e=null,"undefined"!=typeof chrome&&null!==chrome&&(chrome.runtime&&(chrome.runtime.onMessage&&(t=chrome.runtime.onMessage),chrome.runtime.sendMessage&&(e=chrome.runtime.sendMessage.bind(chrome.runtime))),chrome.extension&&(chrome.extension.onMessage&&(t||(t=chrome.extension.onMessage)),chrome.extension.sendMessage&&(e||(e=chrome.extension.sendMessage.bind(chrome.extension))))),c.AuthDriver.Chrome=function(r){function n(t){var e;n.__super__.constructor.call(this,t),e=t&&t.receiverPath||"chrome_oauth_receiver.html",this.useQuery=!0,this.receiverUrl=this.expandUrl(e),this.storageKey="dropbox_js_"+this.scope+"_credentials"}return y(n,r),n.prototype.onMessage=t,n.prototype.sendMessage=e,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.onAuthStepChange=function(t,e){var r=this;switch(t.authStep){case c.Client.RESET:return this.loadCredentials(function(n){if(n){if(n.authStep)return r.forgetCredentials(e);t.setCredentials(n)}return e()});case c.Client.DONE:return this.storeCredentials(t.credentials(),e);case c.Client.SIGNED_OUT:return this.forgetCredentials(e);case c.Client.ERROR:return this.forgetCredentials(e);default:return e()}},n.prototype.doAuthorize=function(t,e,r,n){var i,o,s,a,u=this;return(null!=(o=chrome.identity)?o.launchWebAuthFlow:void 0)?chrome.identity.launchWebAuthFlow({url:t,interactive:!0},function(t){return u.locationStateParam(t)===e?(e=!1,n(c.Util.Oauth.queryParamsFromUrl(t))):void 0}):(null!=(s=chrome.experimental)?null!=(a=s.identity)?a.launchWebAuthFlow:void 0:void 0)?chrome.experimental.identity.launchWebAuthFlow({url:t,interactive:!0},function(t){return u.locationStateParam(t)===e?(e=!1,n(c.Util.Oauth.queryParamsFromUrl(t))):void 0}):(i={handle:null},this.listenForMessage(e,i,n),this.openWindow(t,function(t){return i.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):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,i=this;return n=function(o,s){var a;if((!s||!s.tab||s.tab.url.substring(0,i.receiverUrl.length)===i.receiverUrl)&&o.dropbox_oauth_receiver_href)return a=o.dropbox_oauth_receiver_href,i.locationStateParam(a)===t?(t=!1,e.handle&&i.closeWindow(e.handle),i.onMessage.removeListener(n),r(c.Util.Oauth.queryParamsFromUrl(a))):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 t,e;return t=new c.AuthDriver.Chrome,e=window.location.href,window.location.hash="",t.sendMessage({dropbox_oauth_receiver_href:e}),window.close?window.close():void 0})},n}(c.AuthDriver.BrowserBase),c.AuthDriver.Cordova=function(t){function e(t){e.__super__.constructor.call(this,t)}return y(e,t),e.prototype.url=function(){return"https://www.dropbox.com/1/oauth2/redirect_receiver"},e.prototype.doAuthorize=function(t,e,r,n){var i,o,s,a,u,h=this;return o=window.open(t,"_blank","location=yes,closebuttoncaption=Cancel"),a=!1,i=/^[^/]*\/\/[^/]*\//.exec(t)[0],u=!1,s=function(t){if(t.url&&h.locationStateParam(t.url)===e){if(u)return;return o.removeEventListener("loadstart",s),o.removeEventListener("loaderror",s),o.removeEventListener("loadstop",s),o.removeEventListener("exit",s),u=!0,window.setTimeout(function(){return o.close()},10),n(c.Util.Oauth.queryParamsFromUrl(t.url)),void 0}if("exit"===t.type){if(u)return;o.removeEventListener("loadstart",s),o.removeEventListener("loaderror",s),o.removeEventListener("loadstop",s),o.removeEventListener("exit",s),u=!0,n(new AuthError("error=access_denied&error_description=User+closed+browser+window"))}},o.addEventListener("loadstart",s),o.addEventListener("loaderror",s),o.addEventListener("loadstop",s),o.addEventListener("exit",s)},e}(c.AuthDriver.BrowserBase),c.AuthDriver.NodeServer=function(){function t(t){this._port=(null!=t?t.port:void 0)||8912,(null!=t?t.tls:void 0)?(this._tlsOptions=t.tls,("string"==typeof this._tlsOptions||this._tlsOptions instanceof Buffer)&&(this._tlsOptions={key:this._tlsOptions,cert:this._tlsOptions})):this._tlsOptions=null,this._fs=c.Env.require("fs"),this._http=c.Env.require("http"),this._https=c.Env.require("https"),this._open=c.Env.require("open"),this._callbacks={},this._nodeUrl=c.Env.require("url"),this.createApp()}return t.prototype.authType=function(){return"code"},t.prototype.url=function(){var t;return t=null===this._tlsOptions?"http":"https",""+t+"://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 new Error("Not a http/https URL: "+t);return"BROWSER"in process.env?this._open(t,process.env.BROWSER):this._open(t)},t.prototype.createApp=function(){var t=this;return this._app=this._tlsOptions?this._https.createServer(this._tlsOptions,function(e,r){return t.doRequest(e,r)}):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,i,o=this;return i=this._nodeUrl.parse(t.url,!0),"/oauth_callback"===i.pathname&&(n=i.query.state,this._callbacks[n]&&(this._callbacks[n](i.query),delete this._callbacks[n])),r="",t.on("data",function(t){return r+=t}),t.on("end",function(){return o.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}(),c.AuthError=function(){function t(t){var e;if(!t.error)throw new Error("Not an OAuth 2.0 error: "+JSON.stringify(t));e="object"==typeof t.error&&t.error.error?t.error:t,this.code=e.error,this.description=e.error_description||null,this.uri=e.error_uri||null}return t.prototype.code=null,t.prototype.description=null,t.prototype.uri=null,t.ACCESS_DENIED="access_denied",t.INVALID_REQUEST="invalid_request",t.UNAUTHORIZED_CLIENT="unauthorized_client",t.INVALID_GRANT="invalid_grant",t.INVALID_SCOPE="invalid_scope",t.UNSUPPORTED_GRANT_TYPE="unsupported_grant_type",t.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",t.SERVER_ERROR="server_error",t.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",t.prototype.toString=function(){return"Dropbox OAuth error "+this.code+" :: "+this.description},t.prototype.inspect=function(){return this.toString()},t}(),c.Client=function(){function t(t){var e=this;this.serverRoot=t.server||this.defaultServerRoot(),this.maxApiServer="maxApiServer"in t?t.maxApiServer:this.defaultMaxApiServer(),this.authServer=t.authServer||this.defaultAuthServer(),this.fileServer=t.fileServer||this.defaultFileServer(),this.downloadServer=t.downloadServer||this.defaultDownloadServer(),this.onXhr=new c.Util.EventSource({cancelable:!0}),this.onError=new c.Util.EventSource,this.onAuthStepChange=new c.Util.EventSource,this.xhrOnErrorHandler=function(t,r){return e.handleXhrError(t,r)},this.oauth=new c.Util.Oauth(t),this.uid=t.uid||null,this.authStep=this.oauth.step(),this.driver=null,this.filter=null,this.authError=null,this._credentials=null,this.setupUrls()}return t.prototype.onXhr=null,t.prototype.onError=null,t.prototype.onAuthStepChange=null,t.prototype.authDriver=function(t){return this.driver=t,this},t.prototype.dropboxUid=function(){return this.uid},t.prototype.credentials=function(){return this._credentials||this.computeCredentials(),this._credentials},t.prototype.authenticate=function(t,e){var n,i,o,s,a,u=this;if(e||"function"!=typeof t||(e=t,t=null),n=t&&"interactive"in t?t.interactive:!0,!this.driver&&this.authStep!==r.DONE&&(c.AuthDriver.autoConfigure(this),!this.driver))throw new Error("OAuth driver auto-configuration failed. Call authDriver.");if(this.authStep===r.ERROR)throw new Error("Client got in an error state. Call reset() to reuse it!");return s=function(){return u.authStep=u.oauth.step(),u.authStep===r.ERROR&&(u.authError=u.oauth.error()),u._credentials=null,u.onAuthStepChange.dispatch(u),a()},o=function(){return u.authStep=r.ERROR,u._credentials=null,u.onAuthStepChange.dispatch(u),a()},i=null,a=function(){var t;if(i!==u.authStep&&(i=u.authStep,u.driver&&u.driver.onAuthStepChange))return u.driver.onAuthStepChange(u,a),void 0;switch(u.authStep){case r.RESET:return n?(u.driver.getStateParam&&u.driver.getStateParam(function(t){return u.client.authStep===r.RESET&&u.oauth.setAuthStateParam(t),s()}),u.oauth.setAuthStateParam(c.Util.Oauth.randomAuthStateParam()),s()):(e&&e(null,u),void 0);case r.PARAM_SET:return n?(t=u.authorizeUrl(),u.driver.doAuthorize(t,u.oauth.authStateParam(),u,function(t){return u.oauth.processRedirectParams(t),t.uid&&(u.uid=t.uid),s()})):(e&&e(null,u),void 0);case r.PARAM_LOADED:return u.driver.resumeAuthorize?u.driver.resumeAuthorize(u.oauth.authStateParam(),u,function(t){return u.oauth.processRedirectParams(t),t.uid&&(u.uid=t.uid),s()}):(u.oauth.setAuthStateParam(u.oauth.authStateParam()),s(),void 0);case r.AUTHORIZED:return u.getAccessToken(function(t,e){return t?(u.authError=t,o()):(u.oauth.processRedirectParams(e),u.uid=e.uid,s())});case r.DONE:e&&e(null,u);break;case r.SIGNED_OUT:return u.authStep=r.RESET,u.reset(),a();case r.ERROR:e&&e(u.authError,u)}},a(),this},t.prototype.isAuthenticated=function(){return this.authStep===r.DONE},t.prototype.signOut=function(t,e){var n,i,o=this;if(e||"function"!=typeof t||(e=t,t=null),n=t&&t.mustInvalidate,this.authStep!==r.DONE)throw new Error("This client doesn't have a user's token");return i=new c.Util.Xhr("POST",this.urls.signOut),i.signWithOauth(this.oauth),this.dispatchXhr(i,function(t){if(t)if(t.status===c.ApiError.INVALID_TOKEN)t=null;else if(n)return e&&e(t),void 0;return o.authStep=r.RESET,o.reset(),o.authStep=r.SIGNED_OUT,o.onAuthStepChange.dispatch(o),o.driver&&o.driver.onAuthStepChange?o.driver.onAuthStepChange(o,function(){return e?e(null):void 0}):e?e(null):void 0})},t.prototype.signOff=function(t,e){return this.signOut(t,e)},t.prototype.getAccountInfo=function(t,e){var r,n;return e||"function"!=typeof t||(e=t,t=null),r=!1,t&&t.httpCache&&(r=!0),n=new c.Util.Xhr("GET",this.urls.accountInfo),n.signWithOauth(this.oauth,r),this.dispatchXhr(n,function(t,r){return e(t,c.AccountInfo.parse(r),r)})},t.prototype.getUserInfo=function(t,e){return this.getAccountInfo(t,e)},t.prototype.readFile=function(t,e,r){var n,i,o,s,a,u,h;return r||"function"!=typeof e||(r=e,e=null),i={},u="text",s=null,n=!1,e&&(e.versionTag?i.rev=e.versionTag:e.rev&&(i.rev=e.rev),e.arrayBuffer?u="arraybuffer":e.blob?u="blob":e.buffer?u="buffer":e.binary&&(u="b"),e.length?(null!=e.start?(a=e.start,o=e.start+e.length-1):(a="",o=e.length),s="bytes="+a+"-"+o):null!=e.start&&(s="bytes="+e.start+"-"),e.httpCache&&(n=!0)),h=new c.Util.Xhr("GET",""+this.urls.getFile+"/"+this.urlEncodePath(t)),h.setParams(i).signWithOauth(this.oauth,n),h.setResponseType(u),s&&(s&&h.setHeader("Range",s),h.reportResponseHeaders()),this.dispatchXhr(h,function(t,e,n,i){var o;return o=i?c.Http.RangeInfo.parse(i["content-range"]):null,r(t,e,c.File.Stat.parse(n),o)})},t.prototype.writeFile=function(t,e,r,n){var i;return n||"function"!=typeof r||(n=r,r=null),i=c.Util.Xhr.canSendForms&&"object"==typeof e,i?this.writeFileUsingForm(t,e,r,n):this.writeFileUsingPut(t,e,r,n)},t.prototype.writeFileUsingForm=function(t,e,r,n){var i,o,s,a;return s=t.lastIndexOf("/"),-1===s?(i=t,t=""):(i=t.substring(s),t=t.substring(0,s)),o={file:i},r&&(r.noOverwrite&&(o.overwrite="false"),r.lastVersionTag?o.parent_rev=r.lastVersionTag:(r.parentRev||r.parent_rev)&&(o.parent_rev=r.parentRev||r.parent_rev)),a=new c.Util.Xhr("POST",""+this.urls.postFile+"/"+this.urlEncodePath(t)),a.setParams(o).signWithOauth(this.oauth).setFileField("file",i,e,"application/octet-stream"),delete o.file,this.dispatchXhr(a,function(t,e){return n?n(t,c.File.Stat.parse(e)):void 0})},t.prototype.writeFileUsingPut=function(t,e,r,n){var i,o;return i={},r&&(r.noOverwrite&&(i.overwrite="false"),r.lastVersionTag?i.parent_rev=r.lastVersionTag:(r.parentRev||r.parent_rev)&&(i.parent_rev=r.parentRev||r.parent_rev)),o=new c.Util.Xhr("POST",""+this.urls.putFile+"/"+this.urlEncodePath(t)),o.setBody(e).setParams(i).signWithOauth(this.oauth),this.dispatchXhr(o,function(t,e){return n?n(t,c.File.Stat.parse(e)):void 0})},t.prototype.resumableUploadStep=function(t,e,r){var n,i;return e?(n={offset:e.offset},e.tag&&(n.upload_id=e.tag)):n={offset:0},i=new c.Util.Xhr("POST",this.urls.chunkedUpload),i.setBody(t).setParams(n).signWithOauth(this.oauth),this.dispatchXhr(i,function(t,e){return t&&t.status===c.ApiError.INVALID_PARAM&&t.response&&t.response.upload_id&&t.response.offset?r(null,c.Http.UploadCursor.parse(t.response)):r(t,c.Http.UploadCursor.parse(e))})},t.prototype.resumableUploadFinish=function(t,e,r,n){var i,o;return n||"function"!=typeof r||(n=r,r=null),i={upload_id:e.tag},r&&(r.lastVersionTag?i.parent_rev=r.lastVersionTag:(r.parentRev||r.parent_rev)&&(i.parent_rev=r.parentRev||r.parent_rev),r.noOverwrite&&(i.overwrite="false")),o=new c.Util.Xhr("POST",""+this.urls.commitChunkedUpload+"/"+this.urlEncodePath(t)),o.setParams(i).signWithOauth(this.oauth),this.dispatchXhr(o,function(t,e){return n?n(t,c.File.Stat.parse(e)):void 0})},t.prototype.stat=function(t,e,r){var n,i,o;return r||"function"!=typeof e||(r=e,e=null),i={},n=!1,e&&(e.versionTag?i.rev=e.versionTag:e.rev&&(i.rev=e.rev),e.contentHash?i.hash=e.contentHash:e.hash&&(i.hash=e.hash),(e.removed||e.deleted)&&(i.include_deleted="true"),e.readDir&&(i.list="true",e.readDir!==!0&&(i.file_limit=e.readDir.toString())),e.cacheHash&&(i.hash=e.cacheHash),e.httpCache&&(n=!0)),i.include_deleted||(i.include_deleted="false"),i.list||(i.list="false"),o=new c.Util.Xhr("GET",""+this.urls.metadata+"/"+this.urlEncodePath(t)),o.setParams(i).signWithOauth(this.oauth,n),this.dispatchXhr(o,function(t,e){var n,i,o;return o=c.File.Stat.parse(e),n=(null!=e?e.contents:void 0)?function(){var t,r,n,o;for(n=e.contents,o=[],t=0,r=n.length;r>t;t++)i=n[t],o.push(c.File.Stat.parse(i));return o}():void 0,r(t,o,n)})},t.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.rev&&(n.versionTag=e.rev),e.contentHash?n.contentHash=e.contentHash:e.hash&&(n.contentHash=e.hash),(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 i,o;return i=n?function(){var t,e,r;for(r=[],t=0,e=n.length;e>t;t++)o=n[t],r.push(o.name);return r}():null,r(t,i,e,n)})},t.prototype.metadata=function(t,e,r){return this.stat(t,e,r)},t.prototype.makeUrl=function(t,e,r){var n,i,o,s,a,u=this;return r||"function"!=typeof e||(r=e,e=null),i=e&&(e["long"]||e.longUrl||e.downloadHack)?{short_url:"false"}:{},t=this.urlEncodePath(t),o=""+this.urls.shares+"/"+t,n=!1,s=!1,e&&(e.downloadHack?(n=!0,s=!0):e.download&&(n=!0,o=""+this.urls.media+"/"+t)),a=new c.Util.Xhr("POST",o).setParams(i).signWithOauth(this.oauth),this.dispatchXhr(a,function(t,e){return s&&(null!=e?e.url:void 0)&&(e.url=e.url.replace(u.authServer,u.downloadServer)),r(t,c.File.ShareUrl.parse(e,n))})},t.prototype.history=function(t,e,r){var n,i,o;return r||"function"!=typeof e||(r=e,e=null),i={},n=!1,e&&(null!=e.limit&&(i.rev_limit=e.limit),e.httpCache&&(n=!0)),o=new c.Util.Xhr("GET",""+this.urls.revisions+"/"+this.urlEncodePath(t)),o.setParams(i).signWithOauth(this.oauth,n),this.dispatchXhr(o,function(t,e){var n,i;return i=e?function(){var t,r,i;for(i=[],t=0,r=e.length;r>t;t++)n=e[t],i.push(c.File.Stat.parse(n));return i}():void 0,r(t,i)})},t.prototype.revisions=function(t,e,r){return this.history(t,e,r)},t.prototype.thumbnailUrl=function(t,e){var r;return r=this.thumbnailXhr(t,e),r.paramsToUrl().url},t.prototype.readThumbnail=function(t,e,r){var n,i;return r||"function"!=typeof e||(r=e,e=null),n="b",e&&(e.blob&&(n="blob"),e.arrayBuffer&&(n="arraybuffer"),e.buffer&&(n="buffer")),i=this.thumbnailXhr(t,e),i.setResponseType(n),this.dispatchXhr(i,function(t,e,n){return r(t,e,c.File.Stat.parse(n))})},t.prototype.thumbnailXhr=function(t,e){var r,n;return r={},e&&(e.format?r.format=e.format:e.png&&(r.format="png"),e.size&&(r.size=e.size)),n=new c.Util.Xhr("GET",""+this.urls.thumbnails+"/"+this.urlEncodePath(t)),n.setParams(r).signWithOauth(this.oauth)},t.prototype.revertFile=function(t,e,r){var n;return n=new c.Util.Xhr("POST",""+this.urls.restore+"/"+this.urlEncodePath(t)),n.setParams({rev:e}).signWithOauth(this.oauth),this.dispatchXhr(n,function(t,e){return r?r(t,c.File.Stat.parse(e)):void 0})},t.prototype.restore=function(t,e,r){return this.revertFile(t,e,r)},t.prototype.findByName=function(t,e,r,n){var i,o,s;return n||"function"!=typeof r||(n=r,r=null),o={query:e},i=!1,r&&(null!=r.limit&&(o.file_limit=r.limit),(r.removed||r.deleted)&&(o.include_deleted=!0),r.httpCache&&(i=!0)),s=new c.Util.Xhr("GET",""+this.urls.search+"/"+this.urlEncodePath(t)),s.setParams(o).signWithOauth(this.oauth,i),this.dispatchXhr(s,function(t,e){var r,i;return i=e?function(){var t,n,i;for(i=[],t=0,n=e.length;n>t;t++)r=e[t],i.push(c.File.Stat.parse(r));return i}():void 0,n(t,i)})},t.prototype.search=function(t,e,r,n){return this.findByName(t,e,r,n)},t.prototype.makeCopyReference=function(t,e){var r;return r=new c.Util.Xhr("GET",""+this.urls.copyRef+"/"+this.urlEncodePath(t)),r.signWithOauth(this.oauth),this.dispatchXhr(r,function(t,r){return e(t,c.File.CopyReference.parse(r))})},t.prototype.copyRef=function(t,e){return this.makeCopyReference(t,e)},t.prototype.pullChanges=function(t,e){var r,n;return e||"function"!=typeof t||(e=t,t=null),r=t?t.cursorTag?{cursor:t.cursorTag}:{cursor:t}:{},n=new c.Util.Xhr("POST",this.urls.delta),n.setParams(r).signWithOauth(this.oauth),this.dispatchXhr(n,function(t,r){return e(t,c.Http.PulledChanges.parse(r))})},t.prototype.delta=function(t,e){return this.pullChanges(t,e)},t.prototype.mkdir=function(t,e){var r;return r=new c.Util.Xhr("POST",this.urls.fileopsCreateFolder),r.setParams({root:"auto",path:this.normalizePath(t)}).signWithOauth(this.oauth),this.dispatchXhr(r,function(t,r){return e?e(t,c.File.Stat.parse(r)):void 0})},t.prototype.remove=function(t,e){var r;return r=new c.Util.Xhr("POST",this.urls.fileopsDelete),r.setParams({root:"auto",path:this.normalizePath(t)}).signWithOauth(this.oauth),this.dispatchXhr(r,function(t,r){return e?e(t,c.File.Stat.parse(r)):void 0})},t.prototype.unlink=function(t,e){return this.remove(t,e)},t.prototype["delete"]=function(t,e){return this.remove(t,e)},t.prototype.copy=function(t,e,r){var n,i,o;return r||"function"!=typeof n||(r=n,n=null),i={root:"auto",to_path:this.normalizePath(e)},t instanceof c.File.CopyReference?i.from_copy_ref=t.tag:i.from_path=this.normalizePath(t),o=new c.Util.Xhr("POST",this.urls.fileopsCopy),o.setParams(i).signWithOauth(this.oauth),this.dispatchXhr(o,function(t,e){return r?r(t,c.File.Stat.parse(e)):void 0})},t.prototype.move=function(t,e,r){var n,i;return r||"function"!=typeof n||(r=n,n=null),i=new c.Util.Xhr("POST",this.urls.fileopsMove),i.setParams({root:"auto",from_path:this.normalizePath(t),to_path:this.normalizePath(e)}).signWithOauth(this.oauth),this.dispatchXhr(i,function(t,e){return r?r(t,c.File.Stat.parse(e)):void 0})},t.prototype.appInfo=function(t,e){var r;return e||"function"!=typeof t||(e=t,t=this.oauth.credentials().key),r=new c.Util.Xhr("GET",this.urls.appsInfo),r.setParams({app_key:t}),this.dispatchXhr(r,function(r,n){return e(r,c.Http.AppInfo.parse(n,t))})},t.prototype.isAppDeveloper=function(t,e,r){var n;return"object"==typeof t&&"uid"in t&&(t=t.uid),r||"function"!=typeof e?"object"==typeof e&&"key"in e&&(e=e.key):(r=e,e=this.oauth.credentials().key),n=new c.Util.Xhr("GET",this.urls.appsCheckDeveloper),n.setParams({app_key:e,uid:t}),this.dispatchXhr(n,function(t,e){return e?r(t,e.is_developer):r(t)})},t.prototype.hasOauthRedirectUri=function(t,e,r){var n;return r||"function"!=typeof e?"object"==typeof e&&"key"in e&&(e=e.key):(r=e,e=this.oauth.credentials().key),n=new c.Util.Xhr("GET",this.urls.appsCheckRedirectUri),n.setParams({app_key:e,redirect_uri:t}),this.dispatchXhr(n,function(t,e){return e?r(t,e.has_redirect_uri):r(t)})},t.prototype.reset=function(){var t;return this.uid=null,this.oauth.reset(),t=this.authStep,this.authStep=this.oauth.step(),t!==this.authStep&&this.onAuthStepChange.dispatch(this),this.authError=null,this._credentials=null,this},t.prototype.setCredentials=function(t){var e;return e=this.authStep,this.oauth.setCredentials(t),this.authStep=this.oauth.step(),this.uid=t.uid||null,this.authError=null,this._credentials=null,e!==this.authStep&&this.onAuthStepChange.dispatch(this),this},t.prototype.appHash=function(){return this.oauth.appHash()},t.prototype.setupUrls=function(){return this.apiServer=this.chooseApiServer(),this.urls={authorize:""+this.authServer+"/1/oauth2/authorize",token:""+this.apiServer+"/1/oauth2/token",signOut:""+this.apiServer+"/1/unlink_access_token",accountInfo:""+this.apiServer+"/1/account/info",getFile:""+this.fileServer+"/1/files/auto",postFile:""+this.fileServer+"/1/files/auto",putFile:""+this.fileServer+"/1/files_put/auto",metadata:""+this.apiServer+"/1/metadata/auto",delta:""+this.apiServer+"/1/delta",revisions:""+this.apiServer+"/1/revisions/auto",restore:""+this.apiServer+"/1/restore/auto",search:""+this.apiServer+"/1/search/auto",shares:""+this.apiServer+"/1/shares/auto",media:""+this.apiServer+"/1/media/auto",copyRef:""+this.apiServer+"/1/copy_ref/auto",thumbnails:""+this.fileServer+"/1/thumbnails/auto",chunkedUpload:""+this.fileServer+"/1/chunked_upload",commitChunkedUpload:""+this.fileServer+"/1/commit_chunked_upload/auto",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",appsInfo:""+this.apiServer+"/1/apps/info",appsCheckDeveloper:""+this.apiServer+"/1/apps/check_developer",appsCheckRedirectUri:""+this.apiServer+"/1/apps/check_redirect_uri"} },t.prototype.chooseApiServer=function(){var t,e;return e=Math.floor(Math.random()*(this.maxApiServer+1)),t=0===e?"":e.toString(),this.serverRoot.replace("$",t)},t.prototype.authStep=null,t.ERROR=0,t.RESET=1,t.PARAM_SET=2,t.PARAM_LOADED=3,t.AUTHORIZED=4,t.DONE=5,t.SIGNED_OUT=6,t.prototype.urlEncodePath=function(t){return c.Util.Xhr.urlEncodeValue(this.normalizePath(t)).replace(/%2F/gi,"/")},t.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},t.prototype.authorizeUrl=function(){var t;return t=this.oauth.authorizeUrlParams(this.driver.authType(),this.driver.url()),this.urls.authorize+"?"+c.Util.Xhr.urlEncode(t)},t.prototype.getAccessToken=function(t){var e,r;return e=this.oauth.accessTokenParams(this.driver.url()),r=new c.Util.Xhr("POST",this.urls.token).setParams(e).addOauthParams(this.oauth),this.dispatchXhr(r,function(e,r){return e&&e.status===c.ApiError.INVALID_PARAM&&e.response&&e.response.error&&(e=new c.AuthError(e.response)),t(e,r)})},t.prototype.dispatchXhr=function(t,e){var r;return t.setCallback(e),t.onError=this.xhrOnErrorHandler,t.prepare(),r=t.xhr,this.onXhr.dispatch(t)&&t.send(),r},t.prototype.handleXhrError=function(t,e){var n=this;return t.status===c.ApiError.INVALID_TOKEN&&this.authStep===r.DONE&&(this.authError=t,this.authStep=r.ERROR,this.onAuthStepChange.dispatch(this),this.driver&&this.driver.onAuthStepChange)?(this.driver.onAuthStepChange(this,function(){return n.onError.dispatch(t),e(t)}),null):(this.onError.dispatch(t),e(t),void 0)},t.prototype.defaultServerRoot=function(){return"https://api$.dropbox.com"},t.prototype.defaultAuthServer=function(){return this.serverRoot.replace("api$","www")},t.prototype.defaultFileServer=function(){return this.serverRoot.replace("api$","api-content")},t.prototype.defaultDownloadServer=function(){return"https://dl.dropboxusercontent.com"},t.prototype.defaultMaxApiServer=function(){return 30},t.prototype.computeCredentials=function(){var t;t=this.oauth.credentials(),this.uid&&(t.uid=this.uid),this.serverRoot!==this.defaultServerRoot()&&(t.server=this.serverRoot),this.maxApiServer!==this.defaultMaxApiServer()&&(t.maxApiServer=this.maxApiServer),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},t}(),r=c.Client,c.File.ShareUrl=function(){function t(t,e){this.url=t.url,this.expiresAt=c.Util.parseDate(t.expires),this.isDirect=e===!0?!0:e===!1?!1:"direct"in t?t.direct:Date.now()-this.expiresAt<=864e5,this.isPreview=!this.isDirect,this._json=null}return t.parse=function(t,e){return t&&"object"==typeof t?new c.File.ShareUrl(t,e):t},t.prototype.url=null,t.prototype.expiresAt=null,t.prototype.isDirect=null,t.prototype.isPreview=null,t.prototype.json=function(){return this._json||(this._json={url:this.url,expires:this.expiresAt.toUTCString(),direct:this.isDirect})},t}(),c.File.CopyReference=function(){function t(t){"object"==typeof t?(this.tag=t.copy_ref,this.expiresAt=c.Util.parseDate(t.expires),this._json=t):(this.tag=t,this.expiresAt=new Date(1e3*Math.ceil(Date.now()/1e3)),this._json=null)}return t.parse=function(t){return!t||"object"!=typeof t&&"string"!=typeof t?t:new c.File.CopyReference(t)},t.prototype.tag=null,t.prototype.expiresAt=null,t.prototype.json=function(){return this._json||(this._json={copy_ref:this.tag,expires:this.expiresAt.toUTCString()})},t}(),c.File.Stat=function(){function t(t){var e,r,n,i;switch(this._json=t,this.path=t.path,"/"!==this.path.substring(0,1)&&(this.path="/"+this.path),e=this.path.length-1,e>=0&&"/"===this.path.substring(e)&&(this.path=this.path.substring(0,e)),r=this.path.lastIndexOf("/"),this.name=this.path.substring(r+1),this.isFolder=t.is_dir||!1,this.isFile=!this.isFolder,this.isRemoved=t.is_deleted||!1,this.typeIcon=t.icon,this.modifiedAt=(null!=(n=t.modified)?n.length:void 0)?c.Util.parseDate(t.modified):null,this.clientModifiedAt=(null!=(i=t.client_mtime)?i.length:void 0)?c.Util.parseDate(t.client_mtime):null,t.root){case"dropbox":this.inAppFolder=!1;break;case"app_folder":this.inAppFolder=!0;break;default:this.inAppFolder=null}this.size=t.bytes||0,this.humanSize=t.size||"",this.hasThumbnail=t.thumb_exists||!1,this.versionTag=t.rev,this.contentHash=t.hash||null,this.mimeType=this.isFolder?t.mime_type||"inode/directory":t.mime_type||"application/octet-stream"}return t.parse=function(t){return t&&"object"==typeof t?new c.File.Stat(t):t},t.prototype.path=null,t.prototype.name=null,t.prototype.inAppFolder=null,t.prototype.isFolder=null,t.prototype.isFile=null,t.prototype.isRemoved=null,t.prototype.typeIcon=null,t.prototype.versionTag=null,t.prototype.contentHash=null,t.prototype.mimeType=null,t.prototype.size=null,t.prototype.humanSize=null,t.prototype.hasThumbnail=null,t.prototype.modifiedAt=null,t.prototype.clientModifiedAt=null,t.prototype.json=function(){return this._json},t}(),c.Http.AppInfo=function(){function t(t,e){var r;this.name=t.name,this._icons=t.icons,r=t.permissions||{},this.canUseDatastores=!!r.datastores,this.canUseFiles=!!r.files,this.canUseFullDropbox="full_dropbox"===r.files,this.hasAppFolder="app_folder"===r.files,this.key=e?e:t.key||null}return t.parse=function(t,e){return t?new c.Http.AppInfo(t,e):t},t.prototype.name=void 0,t.prototype.key=void 0,t.prototype.canUseDatastores=void 0,t.prototype.canUseFiles=void 0,t.prototype.hasAppFolder=void 0,t.prototype.canUseFullDropbox=void 0,t.prototype.icon=function(t,e){return e||(e=t),this._icons[""+t+"x"+e]||null},t.ICON_SMALL=64,t.ICON_LARGE=256,t}(),c.Http.PulledChanges=function(){function t(t){var e;this.blankSlate=t.reset||!1,this.cursorTag=t.cursor,this.shouldPullAgain=t.has_more,this.shouldBackOff=!this.shouldPullAgain,this.changes=t.cursor&&t.cursor.length?function(){var r,n,i,o;for(i=t.entries,o=[],r=0,n=i.length;n>r;r++)e=i[r],o.push(c.Http.PulledChange.parse(e));return o}():[]}return t.parse=function(t){return t&&"object"==typeof t?new c.Http.PulledChanges(t):t},t.prototype.blankSlate=void 0,t.prototype.cursorTag=void 0,t.prototype.changes=void 0,t.prototype.shouldPullAgain=void 0,t.prototype.shouldBackOff=void 0,t.prototype.cursor=function(){return this.cursorTag},t}(),c.Http.PulledChange=function(){function t(t){this.path=t[0],this.stat=c.File.Stat.parse(t[1]),this.stat?this.wasRemoved=!1:(this.stat=null,this.wasRemoved=!0)}return t.parse=function(t){return t&&"object"==typeof t?new c.Http.PulledChange(t):t},t.prototype.path=void 0,t.prototype.wasRemoved=void 0,t.prototype.stat=void 0,t}(),c.Http.RangeInfo=function(){function t(t){var e;(e=/^bytes (\d*)-(\d*)\/(.*)$/.exec(t))?(this.start=parseInt(e[1]),this.end=parseInt(e[2]),this.size="*"===e[3]?null:parseInt(e[3])):(this.start=0,this.end=0,this.size=null)}return t.parse=function(t){return"string"==typeof t?new c.Http.RangeInfo(t):t},t.prototype.start=null,t.prototype.size=null,t.prototype.end=null,t}(),c.Http.UploadCursor=function(){function t(t){this.replace(t)}return t.parse=function(t){return!t||"object"!=typeof t&&"string"!=typeof t?t:new c.Http.UploadCursor(t)},t.prototype.tag=null,t.prototype.offset=null,t.prototype.expiresAt=null,t.prototype.json=function(){return this._json||(this._json={upload_id:this.tag,offset:this.offset,expires:this.expiresAt.toUTCString()})},t.prototype.replace=function(t){return"object"==typeof t?(this.tag=t.upload_id||null,this.offset=t.offset||0,this.expiresAt=c.Util.parseDate(t.expires)||Date.now(),this._json=t):(this.tag=t||null,this.offset=0,this.expiresAt=new Date(1e3*Math.floor(Date.now()/1e3)),this._json=null),this},t}(),"function"==typeof c.Env.global.atob&&"function"==typeof c.Env.global.btoa?(c.Util.atob=function(t){return c.Env.global.atob(t)},c.Util.btoa=function(t){return c.Env.global.btoa(t)}):c.Env.global.require&&c.Env.global.Buffer?(c.Util.atob=function(t){var e,r;return e=new Buffer(t,"base64"),function(){var t,n,i;for(i=[],r=t=0,n=e.length;n>=0?n>t:t>n;r=n>=0?++t:--t)i.push(String.fromCharCode(e[r]));return i}().join("")},c.Util.btoa=function(t){var e,r;return e=new Buffer(function(){var e,n,i;for(i=[],r=e=0,n=t.length;n>=0?n>e:e>n;r=n>=0?++e:--e)i.push(t.charCodeAt(r));return i}()),e.toString("base64")}):function(){var t,e,r;return e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=function(t,r,n){var i,o;for(o=3-r,t<<=8*o,i=3;i>=o;)n.push(e.charAt(63&t>>6*i)),i-=1;for(i=r;3>i;)n.push("="),i+=1;return null},t=function(t,e,r){var n,i;for(i=4-e,t<<=6*i,n=2;n>=i;)r.push(String.fromCharCode(255&t>>8*n)),n-=1;return null},c.Util.btoa=function(t){var e,n,i,o,s,a;for(o=[],e=0,n=0,i=s=0,a=t.length;a>=0?a>s:s>a;i=a>=0?++s:--s)e=e<<8|t.charCodeAt(i),n+=1,3===n&&(r(e,n,o),e=n=0);return n>0&&r(e,n,o),o.join("")},c.Util.atob=function(r){var n,i,o,s,a,u,h;for(a=[],n=0,o=0,s=u=0,h=r.length;(h>=0?h>u:u>h)&&(i=r.charAt(s),"="!==i);s=h>=0?++u:--u)n=n<<6|e.indexOf(i),o+=1,4===o&&(t(n,o,a),n=o=0);return o>0&&t(n,o,a),a.join("")}}(),function(){var t,e,r,n,i,o,s,a,u;if(c.Util.hmac=function(t,r){return e(n(a(t),a(r),t.length,r.length))},c.Util.sha1=function(t){return e(s(a(t),t.length))},"undefined"!=typeof require)try{r=require("crypto"),r.createHmac&&r.createHash&&(c.Util.hmac=function(t,e){var n;return n=r.createHmac("sha1",e),n.update(t),n.digest("base64")},c.Util.sha1=function(t){var e;return e=r.createHash("sha1"),e.update(t),e.digest("base64")})}catch(h){i=h}return n=function(t,e,r,n){var i,o,a,u;return e.length>16&&(e=s(e,n)),a=function(){var t,r;for(r=[],o=t=0;16>t;o=++t)r.push(909522486^e[o]);return r}(),u=function(){var t,r;for(r=[],o=t=0;16>t;o=++t)r.push(1549556828^e[o]);return r}(),i=s(a.concat(t),64+r),s(u.concat(i),84)},s=function(e,r){var n,i,s,a,u,h,l,p,c,d,f,y,v,m,_,g,w,b;for(e[r>>2]|=1<<31-((3&r)<<3),e[(r+8>>6<<4)+15]=r<<3,g=Array(80),n=1732584193,s=-271733879,u=-1732584194,l=271733878,c=-1009589776,y=0,_=e.length;_>y;){for(i=n,a=s,h=u,p=l,d=c,v=b=0;80>b;v=++b)g[v]=16>v?e[y+v]:o(g[v-3]^g[v-8]^g[v-14]^g[v-16],1),20>v?(f=s&u|~s&l,m=1518500249):40>v?(f=s^u^l,m=1859775393):60>v?(f=s&u|s&l|u&l,m=-1894007588):(f=s^u^l,m=-899497514),w=t(t(o(n,5),f),t(t(c,g[v]),m)),c=l,l=u,u=o(s,30),s=n,n=w;n=t(n,i),s=t(s,a),u=t(u,h),l=t(l,p),c=t(c,d),y+=16}return[n,s,u,l,c]},o=function(t,e){return t<>>32-e},t=function(t,e){var r,n;return n=(65535&t)+(65535&e),r=(t>>16)+(e>>16)+(n>>16),r<<16|65535&n},e=function(t){var e,r,n,i,o;for(i="",e=0,n=4*t.length;n>e;)r=e,o=(255&t[r>>2]>>(3-(3&r)<<3))<<16,r+=1,o|=(255&t[r>>2]>>(3-(3&r)<<3))<<8,r+=1,o|=255&t[r>>2]>>(3-(3&r)<<3),i+=u[63&o>>18],i+=u[63&o>>12],e+=1,i+=e>=n?"=":u[63&o>>6],e+=1,i+=e>=n?"=":u[63&o],e+=1;return i},u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=function(t){var e,r,n,i,o;for(e=[],n=255,r=i=0,o=t.length;o>=0?o>i:i>o;r=o>=0?++i:--i)e[r>>2]|=(t.charCodeAt(r)&n)<<(3-(3&r)<<3);return e}}(),c.Util.Oauth=function(){function t(t){this._id=null,this._secret=null,this._stateParam=null,this._authCode=null,this._token=null,this._tokenKey=null,this._tokenKid=null,this._error=null,this._appHash=null,this._loaded=null,this.setCredentials(t)}return t.prototype.setCredentials=function(t){if(t.key)this._id=t.key;else{if(!t.token)throw new Error("No API key supplied");this._id=null}return this._secret=t.secret||null,this._appHash=null,this._error=null,this._loaded=!0,this.reset(),t.token?(this._token=t.token,t.tokenKey&&(this._tokenKey=t.tokenKey,this._tokenKid=t.tokenKid)):t.oauthCode?this._authCode=t.oauthCode:t.oauthStateParam&&(this._stateParam=t.oauthStateParam),this},t.prototype.credentials=function(){var t;return t={},this._id&&(t.key=this._id),this._secret&&(t.secret=this._secret),null!==this._token?(t.token=this._token,this._tokenKey&&(t.tokenKey=this._tokenKey,t.tokenKid=this._tokenKid)):null!==this._authCode?t.oauthCode=this._authCode:null!==this._stateParam&&(t.oauthStateParam=this._stateParam),t},t.prototype.step=function(){return null!==this._token?c.Client.DONE:null!==this._authCode?c.Client.AUTHORIZED:null!==this._stateParam?this._loaded?c.Client.PARAM_LOADED:c.Client.PARAM_SET:null!==this._error?c.Client.ERROR:c.Client.RESET},t.prototype.setAuthStateParam=function(t){if(null===this._id)throw new Error("No API key supplied, cannot do authorization");return this.reset(),this._loaded=!1,this._stateParam=t,this},t.prototype.checkAuthStateParam=function(t){return this._stateParam===t&&null!==this._stateParam},t.prototype.authStateParam=function(){return this._stateParam},t.prototype.error=function(){return this._error},t.prototype.processRedirectParams=function(t){var e;if(t.error){if(null===this._id)throw new Error("No API key supplied, cannot process errors");return this.reset(),this._error=new c.AuthError(t),!0}if(t.code){if(null===this._id)throw new Error("No API key supplied, cannot do Authorization Codes");return this.reset(),this._loaded=!1,this._authCode=t.code,!0}if(e=t.token_type){if(e=e.toLowerCase(),"bearer"!==e&&"mac"!==e)throw new Error("Unimplemented token type "+e);if(this.reset(),this._loaded=!1,"mac"===e){if("hmac-sha-1"!==t.mac_algorithm)throw new Error("Unimplemented MAC algorithms "+t.mac_algorithm);this._tokenKey=t.mac_key,this._tokenKid=t.kid}return this._token=t.access_token,!0}return!1},t.prototype.authHeader=function(t,e,r){var n,i;return null===this._token?(i=null===this._secret?c.Util.btoa(""+this._id+":"):c.Util.btoa(""+this._id+":"+this._secret),"Basic "+i):null===this._tokenKey?"Bearer "+this._token:(n=this.macParams(t,e,r),"MAC kid="+n.kid+" ts="+n.ts+" "+("access_token="+this._token+" mac="+n.mac))},t.prototype.addAuthParams=function(t,e,r){var n;return null===this._token?(r.client_id=this._id,null!==this._secret&&(r.client_secret=this._secret)):(null!==this._tokenKey&&(n=this.macParams(t,e,r),r.kid=n.kid,r.ts=n.ts,r.mac=n.mac),r.access_token=this._token),r},t.prototype.authorizeUrlParams=function(t,e){var r;if("token"!==t&&"code"!==t)throw new Error("Unimplemented /authorize response type "+t);return r={client_id:this._id,state:this._stateParam,response_type:t},e&&(r.redirect_uri=e),r},t.prototype.accessTokenParams=function(t){var e;return e={grant_type:"authorization_code",code:this._authCode},t&&(e.redirect_uri=t),e},t.queryParamsFromUrl=function(t){var e,r,n,i,o,s,a,u,h,l;if(i=/^[^?#]+(\?([^\#]*))?(\#(.*))?$/.exec(t),!i)return{};for(a=i[2]||"","/"===a.substring(0,1)&&(a=a.substring(1)),e=i[4]||"",r=e.indexOf("?"),-1!==r&&(e=e.substring(r+1)),"/"===e.substring(0,1)&&(e=e.substring(1)),s={},l=a.split("&").concat(e.split("&")),u=0,h=l.length;h>u;u++)n=l[u],o=n.indexOf("="),-1!==o&&(s[decodeURIComponent(n.substring(0,o))]=decodeURIComponent(n.substring(o+1)));return s},t.prototype.macParams=function(t,e,r){var n,i;return n={kid:this._tokenKid,ts:c.Util.Oauth.timestamp()},i=t.toUpperCase()+"&"+c.Util.Xhr.urlEncodeValue(e)+"&"+c.Util.Xhr.urlEncodeValue(c.Util.Xhr.urlEncode(r)),n.mac=c.Util.hmac(i,this._tokenKey),n},t.prototype.appHash=function(){return this._appHash?this._appHash:this._appHash=c.Util.sha1("oauth2-"+this._id).replace(/[\/+=]/g,"")},t.prototype.reset=function(){return this._stateParam=null,this._authCode=null,this._token=null,this._tokenKey=null,this._tokenKid=null,this},t.timestamp=function(){return Math.floor(Date.now()/1e3)},t.randomAuthStateParam=function(){return["oas",Date.now().toString(36),Math.random().toString(36)].join("_")},t}(),null==Date.now&&(c.Util.Oauth.timestamp=function(){return Math.floor((new Date).getTime()/1e3)}),2274814865e3===new Date("Fri, 31 Jan 2042 21:01:05 +0000").valueOf()?c.Util.parseDate=function(t){return new Date(t)}:2274814865e3===Date.parse("Fri, 31 Jan 2042 21:01:05 +0000")?c.Util.parseDate=function(t){return new Date(Date.parse(t))}:function(){var t,e;return e=/^\w+\, (\d+) (\w+) (\d+) (\d+)\:(\d+)\:(\d+) (\+\d+|UTC|GMT)$/,t={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11},c.Util.parseDate=function(r){var n;return(n=e.exec(r))?new Date(Date.UTC(parseInt(n[3]),t[n[2]],parseInt(n[1]),parseInt(n[4]),parseInt(n[5]),parseInt(n[6]),0)):0/0}}(),c.Env.global.XMLHttpRequest?(!c.Env.global.XDomainRequest||"withCredentials"in new XMLHttpRequest?(h=XMLHttpRequest,u=!1,s="undefined"!=typeof FormData&&-1===navigator.userAgent.indexOf("Firefox")):(h=XDomainRequest,u=!0,s=!1),a=!0):(h=c.Env.require("xhr2"),u=!1,s=!1,a=!1),c.Env.global.Uint8Array)if(Object.getPrototypeOf?o=Object.getPrototypeOf(Object.getPrototypeOf(new Uint8Array(0))).constructor:Object.__proto__&&(o=new Uint8Array(0).__proto__.__proto__.constructor),c.Env.global.Blob){try{!function(){return 2===new Blob([new Uint8Array(2)]).size?(p=!0,l=!0):(l=!1,p=2===new Blob([new ArrayBuffer(2)]).size)}()}catch(v){l=!1,p=!1,c.Env.global.WebKitBlobBuilder&&-1!==navigator.userAgent.indexOf("Android")&&(s=!1)}o===Object&&(l=!1)}else p=!1,l=!0;else o=null,p=!1,l=!1;c.Util.Xhr=function(){function t(t,e){this.method=t,this.isGet="GET"===this.method,this.url=e,this.wantHeaders=!1,this.headers={},this.params=null,this.body=null,this.preflight=!(this.isGet||"POST"===this.method),this.signed=!1,this.completed=!1,this.responseType=null,this.callback=null,this.xhr=null,this.onError=null}return t.Request=h,t.ieXdr=u,t.canSendForms=s,t.doesPreflight=a,t.ArrayBufferView=o,t.sendArrayBufferView=l,t.wrapBlob=p,t.prototype.xhr=null,t.prototype.onError=null,t.prototype.setParams=function(t){if(this.signed)throw new Error("setParams called after addOauthParams or addOauthHeader");if(this.params)throw new Error("setParams cannot be called twice");return this.params=t,this},t.prototype.setCallback=function(t){return this.callback=t,this},t.prototype.signWithOauth=function(t,e){return c.Util.Xhr.ieXdr?this.addOauthParams(t):this.preflight||!c.Util.Xhr.doesPreflight?this.addOauthHeader(t):this.isGet&&e?this.addOauthHeader(t):this.addOauthParams(t)},t.prototype.addOauthParams=function(t){if(this.signed)throw new Error("Request already has an OAuth signature");return this.params||(this.params={}),t.addAuthParams(this.method,this.url,this.params),this.signed=!0,this},t.prototype.addOauthHeader=function(t){if(this.signed)throw new Error("Request already has an OAuth signature");return this.params||(this.params={}),this.signed=!0,this.setHeader("Authorization",t.authHeader(this.method,this.url,this.params))},t.prototype.setBody=function(t){if(this.isGet)throw new Error("setBody cannot be called on GET requests");if(null!==this.body)throw new Error("Request already has a body");return"string"==typeof t||"undefined"!=typeof FormData&&t instanceof FormData||(this.headers["Content-Type"]="application/octet-stream",this.preflight=!0),this.body=t,this},t.prototype.setResponseType=function(t){return this.responseType=t,this},t.prototype.setHeader=function(t,e){var r;if(this.headers[t])throw r=this.headers[t],new Error("HTTP header "+t+" already set to "+r);if("Content-Type"===t)throw new Error("Content-Type is automatically computed based on setBody");return this.preflight=!0,this.headers[t]=e,this},t.prototype.reportResponseHeaders=function(){return this.wantHeaders=!0},t.prototype.setFileField=function(t,e,r,n){var i,o,s,a,u;if(null!==this.body)throw new Error("Request already has a body");if(this.isGet)throw new Error("setFileField cannot be called on GET requests");if("object"==typeof r){"undefined"!=typeof ArrayBuffer&&(r instanceof ArrayBuffer?c.Util.Xhr.sendArrayBufferView&&(r=new Uint8Array(r)):!c.Util.Xhr.sendArrayBufferView&&0===r.byteOffset&&r.buffer instanceof ArrayBuffer&&(r=r.buffer)),n||(n="application/octet-stream");try{r=new Blob([r],{type:n})}catch(h){o=h,window.WebKitBlobBuilder&&(a=new WebKitBlobBuilder,a.append(r),(i=a.getBlob(n))&&(r=i))}"undefined"!=typeof File&&r instanceof File&&(r=new Blob([r],{type:r.type})),u=r instanceof Blob}else u=!1;return u?(this.body=new FormData,this.body.append(t,r,e)):(n||(n="application/octet-stream"),s=this.multipartBoundary(),this.headers["Content-Type"]="multipart/form-data; boundary="+s,this.body=["--",s,"\r\n",'Content-Disposition: form-data; name="',t,'"; filename="',e,'"\r\n',"Content-Type: ",n,"\r\n","Content-Transfer-Encoding: binary\r\n\r\n",r,"\r\n","--",s,"--","\r\n"].join(""))},t.prototype.multipartBoundary=function(){return[Date.now().toString(36),Math.random().toString(36)].join("----")},t.prototype.paramsToUrl=function(){var t;return this.params&&(t=c.Util.Xhr.urlEncode(this.params),0!==t.length&&(this.url=[this.url,"?",t].join("")),this.params=null),this},t.prototype.paramsToBody=function(){if(this.params){if(null!==this.body)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=c.Util.Xhr.urlEncode(this.params),this.params=null}return this},t.prototype.prepare=function(){var t,e,r,n,i=this;if(e=c.Util.Xhr.ieXdr,this.isGet||null!==this.body||e?(this.paramsToUrl(),null!==this.body&&"string"==typeof this.body&&(this.headers["Content-Type"]="text/plain; charset=utf8")):this.paramsToBody(),this.xhr=new c.Util.Xhr.Request,e?(this.xhr.onload=function(){return i.onXdrLoad()},this.xhr.onerror=function(){return i.onXdrError()},this.xhr.ontimeout=function(){return i.onXdrError()},this.xhr.onprogress=function(){}):this.xhr.onreadystatechange=function(){return i.onReadyStateChange()},this.xhr.open(this.method,this.url,!0),!e){n=this.headers;for(t in n)d.call(n,t)&&(r=n[t],this.xhr.setRequestHeader(t,r))}return this.responseType&&("b"===this.responseType?this.xhr.overrideMimeType&&this.xhr.overrideMimeType("text/plain; charset=x-user-defined"):this.xhr.responseType=this.responseType),this},t.prototype.send=function(t){var e,r;if(this.callback=t||this.callback,null!==this.body){e=this.body,c.Util.Xhr.sendArrayBufferView?e instanceof ArrayBuffer&&(e=new Uint8Array(e)):0===e.byteOffset&&e.buffer instanceof ArrayBuffer&&(e=e.buffer);try{this.xhr.send(e)}catch(n){if(r=n,c.Util.Xhr.sendArrayBufferView||!c.Util.Xhr.wrapBlob)throw r;e=new Blob([e],{type:"application/octet-stream"}),this.xhr.send(e)}}else this.xhr.send();return this},t.urlEncode=function(t){var e,r,n;e=[];for(r in t)n=t[r],e.push(this.urlEncodeValue(r)+"="+this.urlEncodeValue(n));return e.sort().join("&")},t.urlEncodeValue=function(t){return encodeURIComponent(t.toString()).replace(/\!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")},t.urlDecode=function(t){var e,r,n,i,o,s;for(r={},s=t.split("&"),i=0,o=s.length;o>i;i++)n=s[i],e=n.split("="),r[decodeURIComponent(e[0])]=decodeURIComponent(e[1]);return r},t.prototype.onReadyStateChange=function(){var t,e,r,n,i,o,s,a,u,h,l,p,d,f,y;if(4!==this.xhr.readyState)return!0;if(this.completed)return!0;if(this.completed=!0,this.xhr.status<200||this.xhr.status>=300)return e=new c.ApiError(this.xhr,this.method,this.url),this.onError?this.onError(e,this.callback):this.callback(e),!0;if(this.wantHeaders?(t=this.xhr.getAllResponseHeaders(),s=t?c.Util.Xhr.parseResponseHeaders(t):this.guessResponseHeaders(),l=s["x-dropbox-metadata"]):(s=void 0,l=this.xhr.getResponseHeader("x-dropbox-metadata")),null!=l?l.length:void 0)try{h=JSON.parse(l)}catch(v){if(u=v,o=l.search(/\}\,\s*\{/),-1!==o)try{l=l.substring(0,o+1),h=JSON.parse(l)}catch(v){u=v,h=void 0}else h=void 0}else h=void 0;if(this.responseType){if("b"===this.responseType){for(i=null!=this.xhr.responseText?this.xhr.responseText:this.xhr.response,r=[],a=f=0,y=i.length;y>=0?y>f:f>y;a=y>=0?++f:--f)r.push(String.fromCharCode(255&i.charCodeAt(a)));d=r.join(""),this.callback(null,d,h,s)}else this.callback(null,this.xhr.response,h,s);return!0}switch(d=null!=this.xhr.responseText?this.xhr.responseText:this.xhr.response,n=this.xhr.getResponseHeader("Content-Type"),n&&(p=n.indexOf(";"),-1!==p&&(n=n.substring(0,p))),n){case"application/x-www-form-urlencoded":this.callback(null,c.Util.Xhr.urlDecode(d),h,s);break;case"application/json":case"text/javascript":this.callback(null,JSON.parse(d),h,s);break;default:this.callback(null,d,h,s)}return!0},t.parseResponseHeaders=function(t){var e,r,n,i,o,s,a,u;for(n={},r=t.split("\n"),a=0,u=r.length;u>a;a++)i=r[a],e=i.indexOf(":"),o=i.substring(0,e).trim().toLowerCase(),s=i.substring(e+1).trim(),n[o]=s;return n},t.prototype.guessResponseHeaders=function(){var t,e,r,n,i,o;for(t={},o=["cache-control","content-language","content-range","content-type","expires","last-modified","pragma","x-dropbox-metadata"],n=0,i=o.length;i>n;n++)e=o[n],r=this.xhr.getResponseHeader(e),r&&(t[e]=r);return t},t.prototype.onXdrLoad=function(){var t,e,r;if(this.completed)return!0;if(this.completed=!0,r=this.xhr.responseText,t=this.wantHeaders?{"content-type":this.xhr.contentType}:void 0,e=void 0,this.responseType)return this.callback(null,r,e,t),!0;switch(this.xhr.contentType){case"application/x-www-form-urlencoded":this.callback(null,c.Util.Xhr.urlDecode(r),e,t);break;case"application/json":case"text/javascript":this.callback(null,JSON.parse(r),e,t);break;default:this.callback(null,r,e,t)}return!0},t.prototype.onXdrError=function(){var t;return this.completed?!0:(this.completed=!0,t=new c.ApiError(this.xhr,this.method,this.url),this.onError?this.onError(t,this.callback):this.callback(t),!0)},t}()}.call(this); //# sourceMappingURL=dropbox.min.map