-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropbox.js
More file actions
1 lines (1 loc) · 31.1 KB
/
dropbox.js
File metadata and controls
1 lines (1 loc) · 31.1 KB
1
(function(){var t,e,r,n,o,i,u,s,a,l,h,p,c,d,f,v,y,m,S,g,w,T,b,R={}.hasOwnProperty;if(t=function(){function t(t){this.client=new e(t)}return t}(),t.ApiError=function(){function t(t,e,r){var n;if(this.method=e,this.url=r,this.status=t.status,n=t.responseType?t.response||t.responseText:t.responseText)try{this.responseText=n+"",this.response=JSON.parse(n)}catch(o){this.response=null}else this.responseText="(no response)",this.response=null}return t.prototype.toString=function(){return"Dropbox API error "+this.status+" from "+this.method+" "+this.url+" :: "+this.responseText},t.prototype.inspect=function(){return this+""},t}(),typeof window!="undefined"&&window!==null?window.atob&&window.btoa?(l=function(t){return window.atob(t)},f=function(t){return window.btoa(t)}):(p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",v=function(t,e,r){var n,o;o=3-e,t<<=o*8,n=3;while(n>=o)r.push(p.charAt(t>>n*6&63)),n-=1;n=e;while(3>n)r.push("="),n+=1;return null},h=function(t,e,r){var n,o;o=4-e,t<<=o*6,n=2;while(n>=o)r.push(String.fromCharCode(t>>8*n&255)),n-=1;return null},f=function(t){var e,r,n,o,i,u;for(o=[],e=0,r=0,n=i=0,u=t.length;0>u?i>u:u>i;n=0>u?--i:++i)e=e<<8|t.charCodeAt(n),r+=1,r===3&&(v(e,r,o),e=r=0);return r>0&&v(e,r,o),o.join("")},l=function(t){var e,r,n,o,i,u,s;for(i=[],e=0,n=0,o=u=0,s=t.length;0>s?u>s:s>u;o=0>s?--u:++u){if(r=t.charAt(o),r==="=")break;e=e<<6|p.indexOf(r),n+=1,n===4&&(h(e,n,i),e=n=0)}return n>0&&h(e,n,i),i.join("")}):(l=function(t){var e,r;return e=new Buffer(t,"base64"),function(){var t,n,o;for(o=[],r=t=0,n=e.length;0>n?t>n:n>t;r=0>n?--t:++t)o.push(String.fromCharCode(e[r]));return o}().join("")},f=function(t){var e,r;return e=new Buffer(function(){var e,n,o;for(o=[],r=e=0,n=t.length;0>n?e>n:n>e;r=0>n?--e:++e)o.push(t.charCodeAt(r));return o}()),e.toString("base64")}),t.Client=function(){function n(t){this.sandbox=t.sandbox||!1,this.apiServer=t.server||this.defaultApiServer(),this.authServer=t.authServer||this.defaultAuthServer(),this.fileServer=t.fileServer||this.defaultFileServer(),this.oauth=new r(t),this.uid=null,this.authState=null,this.authError=null,this._credentials=null,this.setCredentials(t),this.setupUrls()}return n.prototype.authDriver=function(t){return this.driver=t,this},n.prototype.dropboxUid=function(){return this.uid},n.prototype.credentials=function(){return this._credentials||this.computeCredentials(),this._credentials},n.prototype.authenticate=function(r){var n,o,i=this;return n=null,o=function(){var u;if(n!==i.authState&&(n=i.authState,i.driver.onAuthStateChange))return i.driver.onAuthStateChange(i,o);switch(i.authState){case e.RESET:return i.requestToken(function(t,r){var n,u;return t?(i.authError=t,i.authState=e.ERROR):(n=r.oauth_token,u=r.oauth_token_secret,i.oauth.setToken(n,u),i.authState=e.REQUEST),i._credentials=null,o()});case e.REQUEST:return u=i.authorizeUrl(i.oauth.token),i.driver.doAuthorize(u,i.oauth.token,i.oauth.tokenSecret,function(){return i.authState=e.AUTHORIZED,i._credentials=null,o()});case e.AUTHORIZED:return i.getAccessToken(function(t,r){return t?(i.authError=t,i.authState=e.ERROR):(i.oauth.setToken(r.oauth_token,r.oauth_token_secret),i.uid=r.uid,i.authState=e.DONE),i._credentials=null,o()});case e.DONE:return r(null,i);case t.SIGNED_OFF:return i.reset(),o();case e.ERROR:return r(i.authError)}},o(),this},n.prototype.signOut=function(r){var n,o,i=this;return o=this.urls.signOut,n=this.oauth.addAuthParams("POST",o,{}),t.Xhr.request("POST",o,n,null,function(t){return t?r(t):(i.reset(),i.authState=e.SIGNED_OFF,i.driver.onAuthStateChange?i.driver.onAuthStateChange(i,function(){return r(t)}):r(t))})},n.prototype.signOff=function(t){return this.signOut(t)},n.prototype.getUserInfo=function(e){var r,n;return n=this.urls.accountInfo,r=this.oauth.addAuthParams("GET",n,{}),t.Xhr.request("GET",n,r,null,function(r,n){return e(r,t.UserInfo.parse(n),n)})},n.prototype.readFile=function(e,r,n){var o,i,u;return n||typeof r!="function"||(n=r,r=null),u=""+this.urls.getFile+"/"+this.urlEncodePath(e),o={},i=null,r&&(r.versionTag?o.rev=r.versionTag:r.rev&&(o.rev=r.rev),r.blob&&(i="blob"),r.binary&&(i="b")),this.oauth.addAuthParams("GET",u,o),t.Xhr.request2("GET",u,o,null,null,i,function(e,r,o){return n(e,r,t.Stat.parse(o))})},n.prototype.writeFile=function(e,r,n,o){var i;return o||typeof n!="function"||(o=n,n=null),i=t.Xhr.canSendForms&&typeof r=="object",i?this.writeFileUsingForm(e,r,n,o):this.writeFileUsingPut(e,r,n,o)},n.prototype.writeFileUsingForm=function(e,r,n,o){var i,u,s,a,l;return a=e.lastIndexOf("/"),a===-1?(u=e,e=""):(u=e.substring(a),e=e.substring(0,a)),l=""+this.urls.postFile+"/"+this.urlEncodePath(e),s={file:u},n&&(n.noOverwrite&&(s.overwrite="false"),n.lastVersionTag?s.parent_rev=n.lastVersionTag:(n.parentRev||n.parent_rev)&&(s.parent_rev=n.parentRev||n.parent_rev)),this.oauth.addAuthParams("POST",l,s),delete s.file,i={name:"file",value:r,fileName:u,contentType:"application/octet-stream"},t.Xhr.multipartRequest(l,i,s,null,function(e,r){return o(e,t.Stat.parse(r))})},n.prototype.writeFileUsingPut=function(e,r,n,o){var i,u;return u=""+this.urls.putFile+"/"+this.urlEncodePath(e),i={},n&&(n.noOverwrite&&(i.overwrite="false"),n.lastVersionTag?i.parent_rev=n.lastVersionTag:(n.parentRev||n.parent_rev)&&(i.parent_rev=n.parentRev||n.parent_rev)),this.oauth.addAuthParams("POST",u,i),t.Xhr.request2("POST",u,i,null,r,null,function(e,r){return o(e,t.Stat.parse(r))})},n.prototype.stat=function(e,r,n){var o,i;return n||typeof r!="function"||(n=r,r=null),i=""+this.urls.metadata+"/"+this.urlEncodePath(e),o={},r&&(r.version!=null&&(o.rev=r.version),(r.removed||r.deleted)&&(o.include_deleted="true"),r.readDir&&(o.list="true",r.readDir!==!0&&(o.file_limit=r.readDir+"")),r.cacheHash&&(o.hash=r.cacheHash)),o.include_deleted||(o.include_deleted="false"),o.list||(o.list="false"),this.oauth.addAuthParams("GET",i,o),t.Xhr.request("GET",i,o,null,function(e,r){var o,i,u;return u=t.Stat.parse(r),o=(r!=null?r.contents:void 0)?function(){var e,n,o,u;for(o=r.contents,u=[],e=0,n=o.length;n>e;e++)i=o[e],u.push(t.Stat.parse(i));return u}():void 0,n(e,u,o)})},n.prototype.readdir=function(t,e,r){var n;return r||typeof e!="function"||(r=e,e=null),n={readDir:!0},e&&(e.limit!=null&&(n.readDir=e.limit),e.versionTag&&(n.versionTag=e.versionTag)),this.stat(t,n,function(t,e,n){var o,i;return o=n?function(){var t,e,r;for(r=[],t=0,e=n.length;e>t;t++)i=n[t],r.push(i.name);return r}():null,r(t,o,e,n)})},n.prototype.metadata=function(t,e,r){return this.stat(t,e,r)},n.prototype.makeUrl=function(e,r,n){var o,i,u;return n||typeof r!="function"||(n=r,r=null),e=this.urlEncodePath(e),r&&r.download?(o=!0,u=""+this.urls.media+"/"+e):(o=!1,u=""+this.urls.shares+"/"+e),i=r&&r.long?{short_url:"false"}:{},this.oauth.addAuthParams("POST",u,i),t.Xhr.request("POST",u,i,null,function(e,r){return n(e,t.PublicUrl.parse(r,o))})},n.prototype.history=function(e,r,n){var o,i;return n||typeof r!="function"||(n=r,r=null),i=""+this.urls.revisions+"/"+this.urlEncodePath(e),o={},r&&r.limit!=null&&(o.rev_limit=r.limit),this.oauth.addAuthParams("GET",i,o),t.Xhr.request("GET",i,o,null,function(e,r){var o,i;return i=r?function(){var e,n,i;for(i=[],e=0,n=r.length;n>e;e++)o=r[e],i.push(t.Stat.parse(o));return i}():void 0,n(e,i)})},n.prototype.revisions=function(t,e,r){return this.history(t,e,r)},n.prototype.thumbnailUrl=function(e,r){var n,o;return o=""+this.urls.thumbnails+"/"+this.urlEncodePath(e),n={},r&&(r.format?n.format=r.format:r.png&&(n.format="png"),r.size&&(n.size=r.size)),this.oauth.addAuthParams("GET",o,n),""+o+"?"+t.Xhr.urlEncode(n)},n.prototype.readThumbnail=function(e,r,n){var o,i;return n||typeof r!="function"||(n=r,r=null),i=this.thumbnailUrl(e,r),o="b",r&&r.blob&&(o="blob"),t.Xhr.request2("GET",i,{},null,null,o,function(e,r,o){return n(e,r,t.Stat.parse(o))})},n.prototype.revertFile=function(e,r,n){var o,i;return i=""+this.urls.restore+"/"+this.urlEncodePath(e),o={rev:r},this.oauth.addAuthParams("POST",i,o),t.Xhr.request("POST",i,o,null,function(e,r){return n(e,t.Stat.parse(r))})},n.prototype.restore=function(t,e,r){return this.revertFile(t,e,r)},n.prototype.findByName=function(e,r,n,o){var i,u;return o||typeof n!="function"||(o=n,n=null),u=""+this.urls.search+"/"+this.urlEncodePath(e),i={query:r},n&&(n.limit!=null&&(i.file_limit=n.limit),(n.removed||n.deleted)&&(i.include_deleted=!0)),this.oauth.addAuthParams("GET",u,i),t.Xhr.request("GET",u,i,null,function(e,r){var n,i;return i=r?function(){var e,o,i;for(i=[],e=0,o=r.length;o>e;e++)n=r[e],i.push(t.Stat.parse(n));return i}():void 0,o(e,i)})},n.prototype.search=function(t,e,r,n){return this.findByName(t,e,r,n)},n.prototype.makeCopyReference=function(e,r){var n,o;return o=""+this.urls.copyRef+"/"+this.urlEncodePath(e),n=this.oauth.addAuthParams("GET",o,{}),t.Xhr.request("GET",o,n,null,function(e,n){return r(e,t.CopyReference.parse(n))})},n.prototype.copyRef=function(t,e){return this.makeCopyReference(t,e)},n.prototype.pullChanges=function(e,r){var n,o;return r||typeof e!="function"||(r=e,e=null),o=this.urls.delta,n={},n=e?e.cursorTag?{cursor:e.cursorTag}:{cursor:e}:{},this.oauth.addAuthParams("POST",o,n),t.Xhr.request("POST",o,n,null,function(e,n){return r(e,t.PulledChanges.parse(n))})},n.prototype.delta=function(t,e){return this.pullChanges(t,e)},n.prototype.mkdir=function(e,r){var n,o;return o=this.urls.fileopsCreateFolder,n={root:this.fileRoot,path:this.normalizePath(e)},this.oauth.addAuthParams("POST",o,n),t.Xhr.request("POST",o,n,null,function(e,n){return r(e,t.Stat.parse(n))})},n.prototype.remove=function(e,r){var n,o;return o=this.urls.fileopsDelete,n={root:this.fileRoot,path:this.normalizePath(e)},this.oauth.addAuthParams("POST",o,n),t.Xhr.request("POST",o,n,null,function(e,n){return r(e,t.Stat.parse(n))})},n.prototype.unlink=function(t,e){return this.remove(t,e)},n.prototype["delete"]=function(t,e){return this.remove(t,e)},n.prototype.copy=function(e,r,n){var o,i,u;return n||typeof o!="function"||(n=o,o=null),i={root:this.fileRoot,to_path:this.normalizePath(r)},e instanceof t.CopyReference?i.from_copy_ref=e.tag:i.from_path=this.normalizePath(e),u=this.urls.fileopsCopy,this.oauth.addAuthParams("POST",u,i),t.Xhr.request("POST",u,i,null,function(e,r){return n(e,t.Stat.parse(r))})},n.prototype.move=function(e,r,n){var o,i,u;return n||typeof o!="function"||(n=o,o=null),e=this.normalizePath(e),r=this.normalizePath(r),u=this.urls.fileopsMove,i={root:this.fileRoot,from_path:e,to_path:r},this.oauth.addAuthParams("POST",u,i),t.Xhr.request("POST",u,i,null,function(e,r){return n(e,t.Stat.parse(r))})},n.prototype.reset=function(){return this.uid=null,this.oauth.setToken(null,""),this.authState=e.RESET,this.authError=null,this._credentials=null,this},n.prototype.setCredentials=function(t){return this.oauth.reset(t),this.uid=t.uid||null,this.authState=t.authState?t.authState:t.token?e.DONE:e.RESET,this.authError=null,this._credentials=null,this},n.prototype.appHash=function(){return this.oauth.appHash()},n.prototype.setupUrls=function(){return this.fileRoot=this.sandbox?"sandbox":"dropbox",this.urls={requestToken:""+this.apiServer+"/1/oauth/request_token",authorize:""+this.authServer+"/1/oauth/authorize",accessToken:""+this.apiServer+"/1/oauth/access_token",signOut:""+this.apiServer+"/1/unlink_access_token",accountInfo:""+this.apiServer+"/1/account/info",getFile:""+this.fileServer+"/1/files/"+this.fileRoot,postFile:""+this.fileServer+"/1/files/"+this.fileRoot,putFile:""+this.fileServer+"/1/files_put/"+this.fileRoot,metadata:""+this.apiServer+"/1/metadata/"+this.fileRoot,delta:""+this.apiServer+"/1/delta",revisions:""+this.apiServer+"/1/revisions/"+this.fileRoot,restore:""+this.apiServer+"/1/restore/"+this.fileRoot,search:""+this.apiServer+"/1/search/"+this.fileRoot,shares:""+this.apiServer+"/1/shares/"+this.fileRoot,media:""+this.apiServer+"/1/media/"+this.fileRoot,copyRef:""+this.apiServer+"/1/copy_ref/"+this.fileRoot,thumbnails:""+this.fileServer+"/1/thumbnails/"+this.fileRoot,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"}},n.ERROR=0,n.RESET=1,n.REQUEST=2,n.AUTHORIZED=3,n.DONE=4,n.SIGNED_OFF=5,n.prototype.urlEncodePath=function(e){return t.Xhr.urlEncodeValue(this.normalizePath(e)).replace(/%2F/gi,"/")},n.prototype.normalizePath=function(t){var e;if(t.substring(0,1)==="/"){e=1;while(t.substring(e,e+1)==="/")e+=1;return t.substring(e)}return t},n.prototype.requestToken=function(e){var r;return r=this.oauth.addAuthParams("POST",this.urls.requestToken,{}),t.Xhr.request("POST",this.urls.requestToken,r,null,e)},n.prototype.authorizeUrl=function(e){var r;return r={oauth_token:e,oauth_callback:this.driver.url()},""+this.urls.authorize+"?"+t.Xhr.urlEncode(r)},n.prototype.getAccessToken=function(e){var r;return r=this.oauth.addAuthParams("POST",this.urls.accessToken,{}),t.Xhr.request("POST",this.urls.accessToken,r,null,e)},n.prototype.defaultApiServer=function(){return"https://api.dropbox.com"},n.prototype.defaultAuthServer=function(){return this.apiServer.replace("api.","www.")},n.prototype.defaultFileServer=function(){return this.apiServer.replace("api.","api-content.")},n.prototype.computeCredentials=function(){var t;return t={key:this.oauth.key,sandbox:this.sandbox},this.oauth.secret&&(t.secret=this.oauth.secret),this.oauth.token&&(t.token=this.oauth.token,t.tokenSecret=this.oauth.tokenSecret),this.uid&&(t.uid=this.uid),this.authState!==e.ERROR&&this.authState!==e.RESET&&this.authState!==e.DONE&&this.authState!==e.SIGNED_OFF&&(t.authState=this.authState),this.apiServer!==this.defaultApiServer()&&(t.server=this.apiServer),this.authServer!==this.defaultAuthServer()&&(t.authServer=this.authServer),this.fileServer!==this.defaultFileServer()&&(t.fileServer=this.fileServer),this._credentials=t},n}(),e=t.Client,t.AuthDriver=function(){function t(){}return t.prototype.url=function(){return"https://some.url"},t.prototype.doAuthorize=function(t,e,r,n){return n("oauth-token")},t.prototype.onAuthStateChange=function(t,e){return e()},t}(),t.Drivers={},t.Drivers.Redirect=function(){function r(t){this.rememberUser=(t!=null?t.rememberUser:void 0)||!1,this.scope=(t!=null?t.scope:void 0)||"default",this.useQuery=(t!=null?t.useQuery:void 0)||!1,this.receiverUrl=this.computeUrl(t),this.tokenRe=RegExp("(#|\\?|&)oauth_token=([^&#]+)(&|#|$)")}return r.prototype.url=function(){return this.receiverUrl},r.prototype.doAuthorize=function(t){return window.location.assign(t)},r.prototype.onAuthStateChange=function(t,r){var n,o=this;switch(this.storageKey="dropbox-auth:"+this.scope+":"+t.appHash(),t.authState){case e.RESET:return(n=this.loadCredentials())?n.authState?(n.token===this.locationToken()&&(n.authState===e.REQUEST&&(this.forgetCredentials(),n.authState=e.AUTHORIZED),t.setCredentials(n)),r()):this.rememberUser?(t.setCredentials(n),t.getUserInfo(function(e){return e&&(t.reset(),o.forgetCredentials()),r()})):(this.forgetCredentials(),r()):r();case e.REQUEST:return this.storeCredentials(t.credentials()),r();case e.DONE:return this.rememberUser&&this.storeCredentials(t.credentials()),r();case e.SIGNED_OFF:return this.forgetCredentials(),r();case e.ERROR:return this.forgetCredentials(),r();default:return r()}},r.prototype.computeUrl=function(){var e,r,n,o;return o="_dropboxjs_scope="+encodeURIComponent(this.scope),r=t.Drivers.Redirect.currentLocation(),r.indexOf("#")===-1?e=null:(n=r.split("#",2),r=n[0],e=n[1]),this.useQuery?r+=r.indexOf("?")===-1?"?"+o:"&"+o:e="?"+o,e?r+"#"+e:r},r.prototype.locationToken=function(){var e,r,n;return e=t.Drivers.Redirect.currentLocation(),n="_dropboxjs_scope="+encodeURIComponent(this.scope)+"&",(typeof e.indexOf=="function"?e.indexOf(n):void 0)===-1?null:(r=this.tokenRe.exec(e),r?decodeURIComponent(r[2]):null)},r.currentLocation=function(){return window.location.href},r.prototype.storeCredentials=function(t){return localStorage.setItem(this.storageKey,JSON.stringify(t))},r.prototype.loadCredentials=function(){var t;if(t=localStorage.getItem(this.storageKey),!t)return null;try{return JSON.parse(t)}catch(e){return null}},r.prototype.forgetCredentials=function(){return localStorage.removeItem(this.storageKey)},r}(),t.Drivers.Popup=function(){function e(t){this.receiverUrl=this.computeUrl(t),this.tokenRe=RegExp("(#|\\?|&)oauth_token=([^&#]+)(&|#|$)")}return e.prototype.doAuthorize=function(t,e,r,n){return this.listenForMessage(e,n),this.openWindow(t)},e.prototype.url=function(){return this.receiverUrl},e.prototype.computeUrl=function(e){var r;if(e){if(e.receiverUrl)return e.noFragment||e.receiverUrl.indexOf("#")!==-1?e.receiverUrl:e.receiverUrl+"#";if(e.receiverFile)return r=t.Drivers.Popup.currentLocation().split("/"),r[r.length-1]=e.receiverFile,e.noFragment?r.join("/"):r.join("/")+"#"}return t.Drivers.Popup.currentLocation()},e.currentLocation=function(){return window.location.href},e.prototype.openWindow=function(t){return window.open(t,"_dropboxOauthSigninWindow",this.popupWindowSpec(980,980))},e.prototype.popupWindowSpec=function(t,e){var r,n,o,i,u,s,a,l,h,p;return u=(a=window.screenX)!=null?a:window.screenLeft,s=(l=window.screenY)!=null?l:window.screenTop,i=(h=window.outerWidth)!=null?h:document.documentElement.clientWidth,r=(p=window.outerHeight)!=null?p:document.documentElement.clientHeight,n=Math.round(u+(i-t)/2),o=Math.round(s+(r-e)/2.5),"width="+t+",height="+e+","+("left="+n+",top="+o)+"dialog=yes,dependent=yes,scrollbars=yes,location=yes"},e.prototype.listenForMessage=function(t,e){var r,n;return n=this.tokenRe,r=function(o){var i;return i=n.exec(o.data+""),i&&decodeURIComponent(i[2])===t?(window.removeEventListener("message",r),e()):void 0},window.addEventListener("message",r,!1)},e}(),t.Drivers.NodeServer=function(){function t(t){this.port=(t!=null?t.port:void 0)||8912,this.faviconFile=(t!=null?t.favicon:void 0)||null,this.fs=require("fs"),this.http=require("http"),this.open=require("open"),this.callbacks={},this.urlRe=RegExp("^/oauth_callback\\?"),this.tokenRe=RegExp("(\\?|&)oauth_token=([^&]+)(&|$)"),this.createApp()}return t.prototype.url=function(){return"http://localhost:"+this.port+"/oauth_callback"},t.prototype.doAuthorize=function(t,e,r,n){return this.callbacks[e]=n,this.openBrowser(t)},t.prototype.openBrowser=function(t){if(!t.match(/^https?:\/\//))throw Error("Not a http/https URL: "+t);return this.open(t)},t.prototype.createApp=function(){var t=this;return this.app=this.http.createServer(function(e,r){return t.doRequest(e,r)}),this.app.listen(this.port)},t.prototype.closeServer=function(){return this.app.close()},t.prototype.doRequest=function(t,e){var r,n,o,i=this;return this.urlRe.exec(t.url)&&(n=this.tokenRe.exec(t.url),n&&(o=decodeURIComponent(n[2]),this.callbacks[o]&&(this.callbacks[o](),delete this.callbacks[o]))),r="",t.on("data",function(t){return r+=t}),t.on("end",function(){return i.faviconFile&&t.url==="/favicon.ico"?i.sendFavicon(e):i.closeBrowser(e)})},t.prototype.closeBrowser=function(t){var e;return e='<!doctype html>\n<script type="text/javascript">window.close();</script>\n<p>Please close this window.</p>',t.writeHead(200,{"Content-Length":e.length,"Content-Type":"text/html"}),t.write(e),t.end},t.prototype.sendFavicon=function(t){return this.fs.readFile(this.faviconFile,function(e,r){return t.writeHead(200,{"Content-Length":r.length,"Content-Type":"image/x-icon"}),t.write(r),t.end})},t}(),c=function(t,e){return a(S(T(t),T(e),t.length,e.length))},d=function(t){return a(w(T(t),t.length))},(typeof window=="undefined"||window===null)&&(y=require("crypto"),c=function(t,e){var r;return r=y.createHmac("sha1",e),r.update(t),r.digest("base64")},d=function(t){var e;return e=y.createHash("sha1"),e.update(t),e.digest("base64")}),S=function(t,e,r,n){var o,i,u,s;return e.length>16&&(e=w(e,n)),u=function(){var t,r;for(r=[],i=t=0;16>t;i=++t)r.push(e[i]^909522486);return r}(),s=function(){var t,r;for(r=[],i=t=0;16>t;i=++t)r.push(e[i]^1549556828);return r}(),o=w(u.concat(t),64+r),w(s.concat(o),84)},w=function(t,e){var r,n,o,i,u,a,l,h,p,c,d,f,v,y,m,S,w,T;t[e>>2]|=1<<31-((e&3)<<3),t[(e+8>>6<<4)+15]=e<<3,S=Array(80),r=1732584193,o=-271733879,u=-1732584194,l=271733878,p=-1009589776,f=0,m=t.length;while(m>f){for(n=r,i=o,a=u,h=l,c=p,v=T=0;80>T;v=++T)S[v]=16>v?t[f+v]:g(S[v-3]^S[v-8]^S[v-14]^S[v-16],1),20>v?(d=o&u|~o&l,y=1518500249):40>v?(d=o^u^l,y=1859775393):60>v?(d=o&u|o&l|u&l,y=-1894007588):(d=o^u^l,y=-899497514),w=s(s(g(r,5),d),s(s(p,S[v]),y)),p=l,l=u,u=g(o,30),o=r,r=w;r=s(r,n),o=s(o,i),u=s(u,a),l=s(l,h),p=s(p,c),f+=16}return[r,o,u,l,p]},g=function(t,e){return t<<e|t>>>32-e},s=function(t,e){var r,n;return n=(t&65535)+(e&65535),r=(t>>16)+(e>>16)+(n>>16),r<<16|n&65535},a=function(t){var e,r,n,o,i;o="",e=0,n=t.length*4;while(n>e)r=e,i=(t[r>>2]>>(3-(r&3)<<3)&255)<<16,r+=1,i|=(t[r>>2]>>(3-(r&3)<<3)&255)<<8,r+=1,i|=t[r>>2]>>(3-(r&3)<<3)&255,o+=b[i>>18&63],o+=b[i>>12&63],e+=1,o+=n>e?b[i>>6&63]:"=",e+=1,o+=n>e?b[i&63]:"=",e+=1;return o},b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",T=function(t){var e,r,n,o,i;for(e=[],n=255,r=o=0,i=t.length;0>i?o>i:i>o;r=0>i?--o:++o)e[r>>2]|=(t.charCodeAt(r)&n)<<(3-(r&3)<<3);return e},t.Oauth=function(){function t(t){this.key=this.k=null,this.secret=this.s=null,this.token=null,this.tokenSecret=null,this._appHash=null,this.reset(t)}return t.prototype.reset=function(t){var e,r,n,o;if(t.secret)this.k=this.key=t.key,this.s=this.secret=t.secret,this._appHash=null;else if(t.key)this.key=t.key,this.secret=null,n=l(m(this.key).split("|",2)[1]),o=n.split("?",2),e=o[0],r=o[1],this.k=decodeURIComponent(e),this.s=decodeURIComponent(r),this._appHash=null;else if(!this.k)throw Error("No API key supplied");return t.token?this.setToken(t.token,t.tokenSecret):this.setToken(null,"")},t.prototype.setToken=function(t,e){if(t&&!e)throw Error("No secret supplied with the user token");return this.token=t,this.tokenSecret=e||"",this.hmacKey=n.urlEncodeValue(this.s)+"&"+n.urlEncodeValue(e),null},t.prototype.authHeader=function(t,e,r){var o,i,u,s,a,l;this.addAuthParams(t,e,r),i=[];for(u in r)s=r[u],u.substring(0,6)==="oauth_"&&i.push(u);for(i.sort(),o=[],a=0,l=i.length;l>a;a++)u=i[a],o.push(n.urlEncodeValue(u)+'="'+n.urlEncodeValue(r[u])+'"'),delete r[u];return"OAuth "+o.join(",")},t.prototype.addAuthParams=function(t,e,r){return this.boilerplateParams(r),r.oauth_signature=this.signature(t,e,r),r},t.prototype.boilerplateParams=function(t){return t.oauth_consumer_key=this.k,t.oauth_nonce=this.nonce(),t.oauth_signature_method="HMAC-SHA1",this.token&&(t.oauth_token=this.token),t.oauth_timestamp=Math.floor(Date.now()/1e3),t.oauth_version="1.0",t},t.prototype.nonce=function(){return Date.now().toString(36)+Math.random().toString(36)},t.prototype.signature=function(t,e,r){var o;return o=t.toUpperCase()+"&"+n.urlEncodeValue(e)+"&"+n.urlEncodeValue(n.urlEncode(r)),c(o,this.hmacKey)},t.prototype.appHash=function(){return this._appHash?this._appHash:this._appHash=d(this.k).replace(/\=/g,"")},t}(),Date.now==null&&(Date.now=function(){return(new Date).getTime()}),r=t.Oauth,m=function(t,e){var r,n,o,i,u,s,a,h,p,c,d,v;for(e?(e=[encodeURIComponent(t),encodeURIComponent(e)].join("?"),t=function(){var e,n,o;for(o=[],r=e=0,n=t.length/2;0>n?e>n:n>e;r=0>n?--e:++e)o.push((t.charCodeAt(r*2)&15)*16+(t.charCodeAt(r*2+1)&15));return o}()):(c=t.split("|",2),t=c[0],e=c[1],t=l(t),t=function(){var e,n,o;for(o=[],r=e=0,n=t.length;0>n?e>n:n>e;r=0>n?--e:++e)o.push(t.charCodeAt(r));return o}(),e=l(e)),i=function(){for(v=[],h=0;256>h;h++)v.push(h);return v}.apply(this),s=0,u=p=0;256>p;u=++p)s=(s+i[r]+t[u%t.length])%256,d=[i[s],i[u]],i[u]=d[0],i[s]=d[1];return u=s=0,o=function(){var t,r,o,l;for(l=[],a=t=0,r=e.length;0>r?t>r:r>t;a=0>r?--t:++t)u=(u+1)%256,s=(s+i[u])%256,o=[i[s],i[u]],i[u]=o[0],i[s]=o[1],n=i[(i[u]+i[s])%256],l.push(String.fromCharCode((n^e.charCodeAt(a))%256));return l}(),t=function(){var e,n,o;for(o=[],r=e=0,n=t.length;0>n?e>n:n>e;r=0>n?--e:++e)o.push(String.fromCharCode(t[r]));return o}(),[f(t.join("")),f(o.join(""))].join("|")},t.PulledChanges=function(){function e(e){var r;this.blankSlate=e.reset||!1,this.cursorTag=e.cursor,this.shouldPullAgain=e.has_more,this.shouldBackOff=!this.shouldPullAgain,this.changes=e.cursor&&e.cursor.length?function(){var n,o,i,u;for(i=e.entries,u=[],n=0,o=i.length;o>n;n++)r=i[n],u.push(t.PullChange.parse(r));return u}():[]}return e.parse=function(e){return e&&typeof e=="object"?new t.PulledChanges(e):e},e.prototype.blankSlate=void 0,e.prototype.cursorTag=void 0,e.prototype.changes=void 0,e.prototype.shouldPullAgain=void 0,e.prototype.shouldBackOff=void 0,e}(),t.PullChange=function(){function e(e){this.path=e[0],this.stat=t.Stat.parse(e[1]),this.stat?this.wasRemoved=!1:(this.stat=null,this.wasRemoved=!0)}return e.parse=function(e){return e&&typeof e=="object"?new t.PullChange(e):e},e.prototype.path=void 0,e.prototype.wasRemoved=void 0,e.prototype.stat=void 0,e}(),t.PublicUrl=function(){function e(t,e){this.url=t.url,this.expiresAt=new Date(Date.parse(t.expires)),this.isDirect=e===!0?!0:e===!1?!1:864e5>=Date.now()-this.expiresAt,this.isPreview=!this.isDirect}return e.parse=function(e,r){return e&&typeof e=="object"?new t.PublicUrl(e,r):e},e.prototype.url=void 0,e.prototype.expiresAt=void 0,e.prototype.isDirect=void 0,e.prototype.isPreview=void 0,e}(),t.CopyReference=function(){function e(t){typeof t=="object"?(this.tag=t.copy_ref,this.expiresAt=new Date(Date.parse(t.expires))):(this.tag=t,this.expiresAt=new Date)}return e.parse=function(e){return!e||typeof e!="object"&&typeof e!="string"?e:new t.CopyReference(e)},e.prototype.tag=void 0,e.prototype.expiresAt=void 0,e}(),t.Stat=function(){function e(t){var e,r,n,o;switch(this.path=t.path,this.path.substring(0,1)!=="/"&&(this.path="/"+this.path),e=this.path.length-1,0>e||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=((n=t.modified)!=null?n.length:void 0)?new Date(Date.parse(t.modified)):null,this.clientModifiedAt=((o=t.client_mtime)!=null?o.length:void 0)?new Date(Date.parse(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.isFolder?(this.versionTag=t.hash,this.mimeType=t.mime_type||"inode/directory"):(this.versionTag=t.rev,this.mimeType=t.mime_type||"application/octet-stream")}return e.parse=function(e){return e&&typeof e=="object"?new t.Stat(e):e},e.prototype.path=null,e.prototype.name=null,e.prototype.inAppFolder=null,e.prototype.isFolder=null,e.prototype.isFile=null,e.prototype.isRemoved=null,e.prototype.typeIcon=null,e.prototype.versionTag=null,e.prototype.mimeType=null,e.prototype.size=null,e.prototype.humanSize=null,e.prototype.hasThumbnail=null,e.prototype.modifiedAt=null,e.prototype.clientModifiedAt=null,e}(),t.UserInfo=function(){function e(t){var e;this.name=t.display_name,this.email=t.email,this.countryCode=t.country||null,this.uid=t.uid+"",t.public_app_url?(this.publicAppUrl=t.public_app_url,e=this.publicAppUrl.length-1,0>e||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 e.parse=function(e){return e&&typeof e=="object"?new t.UserInfo(e):e},e.prototype.name=null,e.prototype.email=null,e.prototype.countryCode=null,e.prototype.uid=null,e.prototype.referralUrl=null,e.prototype.publicAppUrl=null,e.prototype.quota=null,e.prototype.usedQuota=null,e.prototype.privateBytes=null,e.prototype.sharedBytes=null,e}(),typeof window!="undefined"&&window!==null?!window.XDomainRequest||"withCredentials"in new XMLHttpRequest?(u=window.XMLHttpRequest,i=!1,o=window.navigator.userAgent.indexOf("Firefox")===-1):(u=window.XDomainRequest,i=!0,o=!1):(u=require("xmlhttprequest").XMLHttpRequest,i=!1,o=!1),t.Xhr=function(){function e(){}return e.Request=u,e.ieMode=i,e.canSendForms=o,e.request=function(t,e,r,n,o){return this.request2(t,e,r,n,null,null,o)},e.request2=function(t,e,r,o,i,u,s){var a,l,h;return l=t==="GET"||i!=null||this.ieMode,l&&(h=n.urlEncode(r),h.length!==0&&(e=[e,"?",n.urlEncode(r)].join(""))),a={},o&&(a.Authorization=o),i!=null?typeof i=="string"&&(a["Content-Type"]="text/plain; charset=utf8"):l||(a["Content-Type"]="application/x-www-form-urlencoded",i=n.urlEncode(r)),n.xhrRequest(t,e,a,i,u,s)},e.multipartRequest=function(t,e,r,o,i){var u,s,a,l,h,p;return t=[t,"?",n.urlEncode(r)].join(""),a=e.value,p=typeof a=="object"&&(typeof Blob!="undefined"&&Blob!==null&&e.value instanceof Blob||typeof File!="undefined"&&File!==null&&e.value instanceof File),p?(h={},u=new FormData,u.append(e.name,a,e.fileName)):(l=e.contentType||"application/octet-stream",s=this.multipartBoundary(),h={"Content-Type":"multipart/form-data; boundary="+s},u=["--",s,"\r\n",'Content-Disposition: form-data; name="',e.name,'"; filename="',e.fileName,'"\r\n',"Content-Type: ",l,"\r\n","Content-Transfer-Encoding: binary\r\n\r\n",a,"\r\n","--",s,"--","\r\n"].join("")),o&&(h.Authorization=o),n.xhrRequest("POST",t,h,u,null,i)},e.multipartBoundary=function(){return[Date.now().toString(36),Math.random().toString(36)].join("----")},e.xhrRequest=function(t,e,r,o,i,u){var s,a,l;if(l=new this.Request,this.ieMode?(l.onload=function(){return n.onLoad(l,t,e,u)},l.onerror=function(){return n.onError(l,t,e,u)}):l.onreadystatechange=function(){return n.onReadyStateChange(l,t,e,i,u)},l.open(t,e,!0),i&&(i==="b"?l.overrideMimeType&&l.overrideMimeType("text/plain; charset=x-user-defined"):l.responseType=i),!this.ieMode)for(s in r)R.call(r,s)&&(a=r[s],l.setRequestHeader(s,a));return o!=null?l.send(o):l.send(),l},e.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("&")},e.urlEncodeValue=function(t){return encodeURIComponent(t+"").replace(/\!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")},e.urlDecode=function(t){var e,r,n,o,i,u;for(r={},u=t.split("&"),o=0,i=u.length;i>o;o++)n=u[o],e=n.split("="),r[decodeURIComponent(e[0])]=decodeURIComponent(e[1]);return r},e.onReadyStateChange=function(e,r,o,i,u){var s,a,l,h,p,c,d,f,v;if(e.readyState!==4)return!0;if(200>e.status||e.status>=300)return s=new t.ApiError(e,r,o),u(s),!0;if(c=e.getResponseHeader("x-dropbox-metadata"),c!=null?c.length:void 0)try{p=JSON.parse(c)}catch(y){p=void 0}else p=void 0;if(i){if(i==="b"){for(l=e.responseText!=null?e.responseText:e.response,a=[],h=f=0,v=l.length;0>v?f>v:v>f;h=0>v?--f:++f)a.push(String.fromCharCode(l.charCodeAt(h)&255));d=a.join(""),u(null,d,p)}else u(null,e.response,p);return!0}switch(d=e.responseText!=null?e.responseText:e.response,e.getResponseHeader("Content-Type")){case"application/x-www-form-urlencoded":u(null,n.urlDecode(d),p);break;case"application/json":case"text/javascript":u(null,JSON.parse(d),p);break;default:u(null,d,p)}return!0},e.onLoad=function(t,e,r,o){var i;switch(i=t.responseText,t.contentType){case"application/x-www-form-urlencoded":o(null,n.urlDecode(i),void 0);break;case"application/json":case"text/javascript":o(null,JSON.parse(i),void 0);break;default:o(null,i,void 0)}return!0},e.onError=function(e,r,n,o){var i;return i=new t.ApiError(e,r,n),o(i),!0},e}(),n=t.Xhr,(typeof module!="undefined"&&module!==null?module.exports:void 0)!=null)module.exports=t;else{if(typeof window=="undefined"||window===null)throw Error("This library only supports node.js and modern browsers.");window.Dropbox=t}t.atob=l,t.btoa=f,t.hmac=c,t.sha1=d,t.encodeKey=m}).call(this)