diff --git a/README.md b/README.md index 30b40ef..5081fb5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Titanium Appcelerator Javascript Dropbox API v2 -[![gitTio](http://img.shields.io/badge/on-gittio-00B4CC.svg)](http://gitt.io/component/ti.dropbox) + +# Titanium Appcelerator Javascript Dropbox API v2 I needed a library that would use the new Dropbox API v2. Not finding any, I decided to create this **module/document**, which uses the [Dropbox API v2 HTTP] . @@ -10,13 +10,15 @@ For each API method, it is available the complete documentation and a test. You Enjoy -Vittorio Sorbera, astrovicApps - -www.facebook.com/astrovicApps +Vittorio Sorbera, AstrovicApps +http://www.astrovicapps.com ## Table of contents -- [Get started](#get-started) +- [Download](#download) +- [Requirements](#requirements) +- [tiapp.xml](#tiapp.xml) +- [Methods](#methods) - [Example of use](#example-of-use) - [Screenshots](#screenshots) - [Todos](#todos) @@ -25,23 +27,143 @@ www.facebook.com/astrovicApps --- -# Get started [![gitTio](http://gitt.io/badge.svg)](http://gitt.io/component/ti.dropbox) -Download the [latest release ZIP-file](https://github.com/Astrovic/TiDropboxAPIv2/releases) and consult the [Titanium Documentation](http://docs.appcelerator.com/titanium/latest/#!/guide/Using_a_Module) on how install it, or simply use the [gitTio CLI](http://gitt.io/cli): +## Download +Download the [latest release ZIP-file](https://github.com/Astrovic/TiDropboxAPIv2/releases) and consult the [Titanium Documentation](https://titaniumsdk.com/guide/Titanium_SDK/Titanium_SDK_How-tos/Using_Modules/Using_a_Module.html) on how install it. + +## Requirements +- The `ti.webdialog` module +- The [`ti.deeply`](https://github.com/miniman42/ti.deeply) module (Android only) +- Dropbox requires a redirect URI set to the Dropbox Console App, in order to get a valid token. This url is the same one you will use in the `redirectUri` parameter of the `TiDropbox.init()` method. +In this project I use the redirect URI https://astrovicapps.com/_apptest/tidropbox_cb.html. You will have to create your own and host it somewhere. +You can use the contents of my **tidropbox_cb.html** file. You just need to replace `const scheme = "dropbox";` with the one used in you **tiapp.xml**: +```html + + + + + + +
+ + + + +
+ + +``` -`$ gittio install ti.dropbox` +## tiapp.xml +The login flow to obtain the token requires the use of the system browser. In order to get back to the app, you need to add an activity to your android manifest, which will be used by the **ti.deeply** module, and a public.mime-type string on iOS. +iOS `public.mime-type` key string and Android `android:scheme` value must be the ones you use in the **tidropbox_cb.html** redirect URI file: + +|tidropbox_cb.html|tiapp.xml iOS|tiapp.xml Android| +|--|--|--| +|`scheme`|`public.mime-type` key string|`android:scheme` value| + +```xml + + true + true + + UTExportedTypeDeclarations + + + UTTypeTagSpecification + + public.mime-type + tidropbox + + + + + + + + + + + + + + + + + + + + + + + + ti.dropbox + ti.webdialog + ti.deeply + +``` -### Initialize module -You need a [Dropbox App key], and a `redirect_uri` which must be configured on **Redirect URIs** field of your Dropbox App Settings, on *OAuth 2* section. +## Methods +- [init(parameters)](#init)) +- [generateAuthUrl(callback)](#generateauthurl) +- [callMethod(parameters)](#callmethod) +- [revokeAccessToken(callback)](#revokeaccesstoken) + +### - init +**`TiDropbox.init(parameters)`** +|Parameters|Type|Required|Description | +|--|--|--|--| +| **APP_KEY** | *String* | ✅ | App key in Dropbox Console App| +| **APP_SECRET** | *String* | ✅ | App secret in Dropbox Console App| +| **redirectUri** | *String* | ✅ | One of your OAuth2 Redirect URIs set to Dropbox Console App | +| **response_type** | *String* | ✅ | `code` or `token`. Token flow expires after 4 hours | +| **app_mime_scheme** | *String* | ✅ | App mime scheme set to tiapp.xml (on Android) and used inside your `redirectUri` page to be able to get back to the app after login| + +You need a [Dropbox App key], and a `redirectUri` which must be configured on **Redirect URIs** field of your Dropbox App Settings, on *OAuth 2* section. ```js var TiDropbox = require("ti.dropbox").TiDropbox; -TiDropbox.init('', ''); +TiDropbox.init({ + APP_KEY: 'e9tribefg77q4wg', /**/ + APP_SECRET: 'dkrhmji4z14k2wf', /**/ + redirectUri: 'https://astrovicapps.com/_apptest/tidropbox_cb.html', /**/ + response_type: "code", // "token" or "code". Token flow expires after 4 hours! + app_mime_scheme: "tidropbox" // **/ +}); ``` -### OAauth 2 token flow -Generating a token to be able to invoke methods. -Callback return an object with these parameters: -- **success** (*boolean*): response result -- **access_token** (*string*): access token key -- **msg** (*string*): description of the response result +### - generateAuthUrl +**`TiDropbox.generateAuthUrl(callback)`** +| Callback parameters| Type |Description | +|--|--|--| +| **success** | *Boolean* | Response result| +| **access_token** | *String* | Access token key| +| **msg** | *String* | Description of the response result | + +This allows you to generate a token to be able to invoke methods. ```js TiDropbox.generateAuthUrl(function(e){ @@ -61,206 +183,271 @@ TiDropbox.generateAuthUrl(function(e){ }; }); ``` -### API call -After obtaining a valid token, you can call any method, simply use the function: +### - callMethod +**`TiDropbox.callMethod(parameters)`** +|Parameters|Type|Required|Description | +|--|--|--|--| +| **methodStr** | *String* | ✅ | represent API target. It contains Dropbox's namespace and method name. eg. `"files/upload"` or `"sharing/share_folder"` or more at [/lib/dropboxAPIv2.js]| +| **paramsObj** | *Object* | ✅ | Parameters object, depends on resource field| +| **fileBin** | *Blob/null* | ✅ | File to upload, depends on resource field | +| **onSuccessCallback** | *Function* | ✅ | Callback on succes | +| **onErrorCallback** | *Function* | ✅ | Callback on error | +| **callMethodXhrObjCallback** | *Function* | | return directly the *TiDropbox.xhr* object of the current *TiDropbox.callMethod*, so you can invoke all xhr methods you need: abort, onload, onsendstream, ecc.. | + +After obtaining a valid token, you can call any method: ```js -TiDropbox.callMethod (methodStr, paramsObj, fileBin, onSuccessCallback, onErrorCallback, callMethodXhrObjCallback) +// Upload the a.txt file to my app's Dropbox home +TiDropbox.callMethod({ + methodStr: "files/upload", + paramsObj: { + path: "/a.txt", + mode: "add", + autorename: true, + mute: false + }, + fileBin: Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "a.txt").read(), + onSuccessCallback: (xhr) => { + console.log("onSuccessCallback checkins response-> " + xhr.responseText); + }, + onErrorCallback: (e) => { + console.error("onErrorCallback checkins response-> " + JSON.stringify(e)); + if (JSON.stringify(e).indexOf("invalid_access_token") != -1) { + //The session has expired, I need a new token }; + // Do something... + } + }, + callMethodXhrObjCallback: (currentCallMethodXhr) => { + currentCallMethodXhr.onsendstream = function (e) { + if (e.progress) { + console.log(JSON.stringify('Upload progress --> ' + (e.progress * 100) + '%')); + } + } + } +}); ``` -- **methodStr** (*string*): represent API target. It contains Dropbox's namespace and method name. eg. `"files/upload"` or `"sharing/share_folder"` or more at [/lib/dropboxAPIv2.js] -- **paramsObj** (*object*): parameters, depends on resource field -- **fileBin** (*blob/null*): file to upload, depends on resource field -- **onSuccessCallback** (*function*): callback on succes -- **onErrorCallback** (*function*): callback on error -- **callMethodXhrObjCallback** (*function*): return directly the *TiDropbox.xhr* object of the current *TiDropbox.callMethod*, so you can invoke all xhr methods you need: abort, onload, onsendstream, ecc.. - -### Revoke AccessToken + +### - revokeAccessToken +**`TiDropbox.revokeAccessToken(callback)`** +| Callback parameters| Type |Description | +|--|--|--| +| **success** | *Boolean* | Response result| +| **access_token** | *String* | Access token key| +| **msg** | *String* | Description of the response result | Revoke the access token. -Callback return an object with these parameters: -- **success** (*boolean*): response result -- **access_token** (*string*): access token key -- **msg** (*string*): description of the response result ```js -TiDropbox.revokeAccessToken(function(e){ - if(e.success){ - // Logout, do something... - Titanium.UI.createAlertDialog({ - title: "REVOKE AUTH SUCCESS", - message: e.msg, - buttonNames: ['OK'] - }).show(); - }else{ - Titanium.UI.createAlertDialog({ - title: "REVOKE AUTH PROBLEM", - message: e.msg, - buttonNames: ['OK'] - }).show(); - }; +TiDropbox.revokeAccessToken(function (e) { + if (e.success) { + // Logout, do something... + Titanium.UI.createAlertDialog({ + title: "REVOKE AUTH SUCCESS", + message: e.msg, + buttonNames: ['OK'] + }).show(); + } else { + Titanium.UI.createAlertDialog({ + title: "REVOKE AUTH PROBLEM", + message: e.msg, + buttonNames: ['OK'] + }).show(); + }; }); ``` -That's all. Simple :) +That's all! :) # Example of use ### File upload ```js var TiDropbox = require("ti.dropbox").TiDropbox; -TiDropbox.init('', ''); +TiDropbox.init({ + APP_KEY: 'e9tribefg77q4wg', /**/ + APP_SECRET: 'dkrhmji4z14k2wf', /**/ + redirectUri: 'https://astrovicapps.com/_apptest/tidropbox_cb.html', /**/ + response_type: "code", // "token" or "code". Token flow expires after 4 hours! + app_mime_scheme: "tidropbox" // **/ +}); // Check if I have a token -if(Ti.App.Properties.getString('DROPBOX_TOKENS',null))){ +if (Ti.App.Properties.getString('DROPBOX_TOKENS', null)) { login(); - }else{ - TiDropbox.revokeAccessToken(function(){ +} else { + TiDropbox.revokeAccessToken(function () { // Logout, do something... }); }; -function login(){ - TiDropbox.generateAuthUrl(function(e){ - if(e.success){ - // I'm logged, now I can call any method (/lib/dropboxAPIv2.js) - // For example, if I want upload a.txt file on Dropbox App root folder - var methodStr = "files/upload"; - var paramsObj: { - path: "/a.txt", - mode: "add", - autorename: true, - mute: false +function login() { + TiDropbox.generateAuthUrl(function (e) { + if (e.success) { + // I'm logged, now I can call any method (/lib/dropboxAPIv2.js) + // For example, if I want upload a.txt file on Dropbox App root folder + fileUpload(); + } else { + Titanium.UI.createAlertDialog({ + title: "AUTH PROBLEM", + message: e.msg, + buttonNames: ['OK'] + }).show(); }; - var fileBin = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "a.txt").read(); - TiDropbox.callMethod(methodStr, paramsObj, fileBin, onSuccessCallback, onErrorCallback, callMethodXhrObjCallback) - }else{ - Titanium.UI.createAlertDialog({ - title: "AUTH PROBLEM", - message: e.msg, - buttonNames: ['OK'] - }).show(); - }; }); }; -// callback functions -function onSuccessCallback(xhr) { - Ti.API.info("onSuccessCallback checkins response-> " + xhr.responseText); - Titanium.UI.createAlertDialog({ - title: "METHOD SUCCESS", - message: xhr.responseText, - buttonNames: ['OK'] - }).show(); -}; +function fileUpload() { + + TiDropbox.callMethod({ + methodStr: "files/upload", + paramsObj: { + path: "/a.txt", + mode: "add", + autorename: true, + mute: false + }, + fileBin: Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "a.txt").read(), + onSuccessCallback: onSuccessCallback, + onErrorCallback: onErrorCallback, + callMethodXhrObjCallback: callMethodXhrObjCallback + }); -function onErrorCallback(e) { - Ti.API.info("onErrorCallback checkins response-> " + JSON.stringify(e)); - Titanium.UI.createAlertDialog({ - title: "METHOD FAILED", - message: JSON.stringify(e), - buttonNames: ['OK'] - }).show(); - if(JSON.stringify(e).indexOf("invalid_access_token")!=-1){ - //The session has expired, I need a new token - Ti.App.Properties.setString('DROPBOX_TOKENS',null); - login(); + // callback functions + function onSuccessCallback(xhr) { + Ti.API.info("onSuccessCallback checkins response-> " + xhr.responseText); + Titanium.UI.createAlertDialog({ + title: "METHOD SUCCESS", + message: xhr.responseText, + buttonNames: ['OK'] + }).show(); + }; + + function onErrorCallback(e) { + Ti.API.info("onErrorCallback checkins response-> " + JSON.stringify(e)); + Titanium.UI.createAlertDialog({ + title: "METHOD FAILED", + message: JSON.stringify(e), + buttonNames: ['OK'] + }).show(); + if (JSON.stringify(e).indexOf("invalid_access_token") != -1) { + //The session has expired, I need a new token + Ti.App.Properties.setString('DROPBOX_TOKENS', null); + login(); + }; }; -}; -function callMethodXhrObjCallback(currentCallMethodXhr){ - currentCallMethodXhr.onsendstream = function(e) { - Ti.API.debug(JSON.stringify(e)); - if(e.progress){ - Ti.API.debug(JSON.stringify('Upload progress --> ' + (e.progress*100) + '%')); - } + function callMethodXhrObjCallback(currentCallMethodXhr) { + currentCallMethodXhr.onsendstream = function (e) { + Ti.API.debug(JSON.stringify(e)); + if (e.progress) { + Ti.API.debug(JSON.stringify('Upload progress --> ' + (e.progress * 100) + '%')); + } + }; }; - }; }; ``` ### File download ```js var TiDropbox = require("ti.dropbox").TiDropbox; -TiDropbox.init('', ''); +TiDropbox.init({ + APP_KEY: 'e9tribefg77q4wg', /**/ + APP_SECRET: 'dkrhmji4z14k2wf', /**/ + redirectUri: 'https://astrovicapps.com/_apptest/tidropbox_cb.html', /**/ + response_type: "code", // "token" or "code". Token flow expires after 4 hours! + app_mime_scheme: "tidropbox" // **/ +}); // Check if I have a token -if(Ti.App.Properties.getString('DROPBOX_TOKENS',null))){ +if (Ti.App.Properties.getString('DROPBOX_TOKENS', null)) { login(); - }else{ - TiDropbox.revokeAccessToken(function(){ +} else { + TiDropbox.revokeAccessToken(function () { // Logout, do something... }); }; -function login(){ - TiDropbox.generateAuthUrl(function(){ - if(e.success){ - // I'm logged, now I can call any method (/lib/dropboxAPIv2.js) - // For example, if I want download Prime_Numbers.txt file from Dropbox App - var methodStr = "files/download"; - var paramsObj: { - path: "/Homework/math/Prime_Numbers.txt" - }; - TiDropbox.callMethod(methodStr, paramsObj, null, onSuccessCallback, onErrorCallback) - }else{ - Titanium.UI.createAlertDialog({ - title: "AUTH PROBLEM", - message: e.msg, - buttonNames: ['OK'] - }).show(); - }; +function login() { + TiDropbox.generateAuthUrl(function () { + if (e.success) { + // I'm logged, now I can call any method (/lib/dropboxAPIv2.js) + // For example, if I want download Prime_Numbers.txt file from Dropbox App + downloadFile(); + } else { + Titanium.UI.createAlertDialog({ + title: "AUTH PROBLEM", + message: e.msg, + buttonNames: ['OK'] + }).show(); + }; }); }; -// callback functions -function onSuccessCallback(xhr) { - Ti.API.debug("onSuccessCallback checkins response-> " + xhr.responseText); - - // Write downloaded data in a file - if(xhr.responseData){ - var filePath = Titanium.Filesystem.applicationDataDirectory + "myDownloadedFile.txt"; - var f = Titanium.Filesystem.getFile(filePath); - f.write(xhr.responseData); - - // I check if I saved the file properly - setTimeout(function(){ - Ti.API.debug(filePath + " exists? ---> " + file.exists()); - if(f.exists()){ - if(OS_IOS){ - Ti.UI.iOS.createDocumentViewer({url:filePath}).show(); +function downloadFile() { + + TiDropbox.callMethod({ + methodStr: "files/download", + paramsObj: { + path: "/Homework/math/Prime_Numbers.txt" + }, + fileBin: null, + onSuccessCallback: onSuccessCallback, + onErrorCallback: onErrorCallback, + callMethodXhrObjCallback: callMethodXhrObjCallback + }); + + // callback functions + function onSuccessCallback(xhr) { + Ti.API.debug("onSuccessCallback checkins response-> " + xhr.responseText); + + // Write downloaded data in a file + if (xhr.responseData) { + var filePath = Titanium.Filesystem.applicationDataDirectory + "myDownloadedFile.txt"; + var f = Titanium.Filesystem.getFile(filePath); + f.write(xhr.responseData); + + // I check if I saved the file properly + setTimeout(function () { + Ti.API.debug(filePath + " exists? ---> " + file.exists()); + if (f.exists()) { + if (OS_IOS) { + Ti.UI.iOS.createDocumentViewer({ + url: filePath + }).show(); + }; + } else { + Titanium.UI.createAlertDialog({ + title: "DOWNLOAD FAILED", + message: "Something went wrong in the file writing...", + buttonNames: ['OK'] + }).show(); + }; + }, 1000); }; - }else{ + }; + + function onErrorCallback(e) { + Ti.API.debug("onErrorCallback checkins response-> " + JSON.stringify(e)); Titanium.UI.createAlertDialog({ - title: "DOWNLOAD FAILED", - message: "Something went wrong in the file writing...", + title: "METHOD FAILED", + message: JSON.stringify(e), buttonNames: ['OK'] }).show(); - }; - },1000); - }; -}; - -function onErrorCallback(e) { - Ti.API.debug("onErrorCallback checkins response-> " + JSON.stringify(e)); - Titanium.UI.createAlertDialog({ - title: "METHOD FAILED", - message: JSON.stringify(e), - buttonNames: ['OK'] - }).show(); - if(JSON.stringify(e).indexOf("invalid_access_token")!=-1){ - //The session has expired, I need a new token - Ti.App.Properties.setString('DROPBOX_TOKENS',null); - login(); + if (JSON.stringify(e).indexOf("invalid_access_token") != -1) { + //The session has expired, I need a new token + Ti.App.Properties.setString('DROPBOX_TOKENS', null); + login(); + }; }; -}; -function callMethodXhrObjCallback(currentCallMethodXhr){ - currentCallMethodXhr.ondatastream = function(e) { - Ti.API.debug(JSON.stringify(e)); - if(e.progress){ - Ti.API.debug(JSON.stringify('Download progress --> ' + (e.progress*100) + '%')); - } - }; - }; -}; + function callMethodXhrObjCallback(currentCallMethodXhr) { + currentCallMethodXhr.onsendstream = function (e) { + if (e.progress) { + console.log(JSON.stringify('Upload progress --> ' + (e.progress * 100) + '%')); + } + } + } +} ``` +Download and build this project to test other methods + # Screenshots @@ -281,7 +468,7 @@ function callMethodXhrObjCallback(currentCallMethodXhr){ ### Todos - - OAauth 2 code flow + - OAauth 2 code flow ✅ DONE! # Guidelines for pull requests @@ -297,15 +484,13 @@ After making your changes, to create a new version of the module you have to fol - Uses [Titaniumifier](https://github.com/smclab/titaniumifier) to generate the zip module, with the command: `$ titaniumifier --in . --out ./dist` - - ⚠️ **Titaniumifier** requires **node 8**. It does not work correctly with node version > 8. - Import your new **ti.dropbox-commonjs-x.x.x.zip** module in the project. This will create the [**`modules/commonjs`**](https://github.com/Astrovic/TiDropboxAPIv2/tree/master/modules/commonjs) folder you had removed earlier, with the new version of the module. All done :) Now you can send your pull request. License ---- -**Copyright (c) 2016 Vittorio Sorbera, astrovicApps** +**Copyright (c) 2016-23 Vittorio Sorbera, AstrovicApps** Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/app/README.md b/app/README.md index 362c7de..5081fb5 100644 --- a/app/README.md +++ b/app/README.md @@ -1,6 +1,6 @@ -# Titanium Appcelerator Javascript Dropbox API v2 -[![gitTio](http://img.shields.io/badge/on-gittio-00B4CC.svg)](http://gitt.io/component/ti.dropbox) + +# Titanium Appcelerator Javascript Dropbox API v2 I needed a library that would use the new Dropbox API v2. Not finding any, I decided to create this **module/document**, which uses the [Dropbox API v2 HTTP] . @@ -10,13 +10,15 @@ For each API method, it is available the complete documentation and a test. You Enjoy -Vittorio Sorbera, astrovicApps - -www.facebook.com/astrovicApps +Vittorio Sorbera, AstrovicApps +http://www.astrovicapps.com ## Table of contents -- [Get started](#get-started) +- [Download](#download) +- [Requirements](#requirements) +- [tiapp.xml](#tiapp.xml) +- [Methods](#methods) - [Example of use](#example-of-use) - [Screenshots](#screenshots) - [Todos](#todos) @@ -25,23 +27,143 @@ www.facebook.com/astrovicApps --- -# Get started [![gitTio](http://gitt.io/badge.svg)](http://gitt.io/component/ti.dropbox) -Download the [latest release ZIP-file](https://github.com/Astrovic/TiDropboxAPIv2/releases) and consult the [Titanium Documentation](http://docs.appcelerator.com/titanium/latest/#!/guide/Using_a_Module) on how install it, or simply use the [gitTio CLI](http://gitt.io/cli): +## Download +Download the [latest release ZIP-file](https://github.com/Astrovic/TiDropboxAPIv2/releases) and consult the [Titanium Documentation](https://titaniumsdk.com/guide/Titanium_SDK/Titanium_SDK_How-tos/Using_Modules/Using_a_Module.html) on how install it. + +## Requirements +- The `ti.webdialog` module +- The [`ti.deeply`](https://github.com/miniman42/ti.deeply) module (Android only) +- Dropbox requires a redirect URI set to the Dropbox Console App, in order to get a valid token. This url is the same one you will use in the `redirectUri` parameter of the `TiDropbox.init()` method. +In this project I use the redirect URI https://astrovicapps.com/_apptest/tidropbox_cb.html. You will have to create your own and host it somewhere. +You can use the contents of my **tidropbox_cb.html** file. You just need to replace `const scheme = "dropbox";` with the one used in you **tiapp.xml**: +```html + + + + + + + + + +``` -`$ gittio install ti.dropbox` +## tiapp.xml +The login flow to obtain the token requires the use of the system browser. In order to get back to the app, you need to add an activity to your android manifest, which will be used by the **ti.deeply** module, and a public.mime-type string on iOS. +iOS `public.mime-type` key string and Android `android:scheme` value must be the ones you use in the **tidropbox_cb.html** redirect URI file: + +|tidropbox_cb.html|tiapp.xml iOS|tiapp.xml Android| +|--|--|--| +|`scheme`|`public.mime-type` key string|`android:scheme` value| + +```xml + + true + true + + UTExportedTypeDeclarations + + + UTTypeTagSpecification + + public.mime-type + tidropbox + + + + + + + + + + + + + + + + + + + + + + + + ti.dropbox + ti.webdialog + ti.deeply + +``` -### Initialize module -You need a [Dropbox App key], and a `redirect_uri` which must be configured on **Redirect URIs** field of your Dropbox App Settings, on *OAuth 2* section. +## Methods +- [init(parameters)](#init)) +- [generateAuthUrl(callback)](#generateauthurl) +- [callMethod(parameters)](#callmethod) +- [revokeAccessToken(callback)](#revokeaccesstoken) + +### - init +**`TiDropbox.init(parameters)`** +|Parameters|Type|Required|Description | +|--|--|--|--| +| **APP_KEY** | *String* | ✅ | App key in Dropbox Console App| +| **APP_SECRET** | *String* | ✅ | App secret in Dropbox Console App| +| **redirectUri** | *String* | ✅ | One of your OAuth2 Redirect URIs set to Dropbox Console App | +| **response_type** | *String* | ✅ | `code` or `token`. Token flow expires after 4 hours | +| **app_mime_scheme** | *String* | ✅ | App mime scheme set to tiapp.xml (on Android) and used inside your `redirectUri` page to be able to get back to the app after login| + +You need a [Dropbox App key], and a `redirectUri` which must be configured on **Redirect URIs** field of your Dropbox App Settings, on *OAuth 2* section. ```js var TiDropbox = require("ti.dropbox").TiDropbox; -TiDropbox.init('', ''); +TiDropbox.init({ + APP_KEY: 'e9tribefg77q4wg', /**/ + APP_SECRET: 'dkrhmji4z14k2wf', /**/ + redirectUri: 'https://astrovicapps.com/_apptest/tidropbox_cb.html', /**/ + response_type: "code", // "token" or "code". Token flow expires after 4 hours! + app_mime_scheme: "tidropbox" // **/ +}); ``` -### OAauth 2 token flow -Generating a token to be able to invoke methods. -Callback return an object with these parameters: -- **success** (*boolean*): response result -- **access_token** (*string*): access token key -- **msg** (*string*): description of the response result +### - generateAuthUrl +**`TiDropbox.generateAuthUrl(callback)`** +| Callback parameters| Type |Description | +|--|--|--| +| **success** | *Boolean* | Response result| +| **access_token** | *String* | Access token key| +| **msg** | *String* | Description of the response result | + +This allows you to generate a token to be able to invoke methods. ```js TiDropbox.generateAuthUrl(function(e){ @@ -61,104 +183,162 @@ TiDropbox.generateAuthUrl(function(e){ }; }); ``` -### API call -After obtaining a valid token, you can call any method, simply use the function: +### - callMethod +**`TiDropbox.callMethod(parameters)`** +|Parameters|Type|Required|Description | +|--|--|--|--| +| **methodStr** | *String* | ✅ | represent API target. It contains Dropbox's namespace and method name. eg. `"files/upload"` or `"sharing/share_folder"` or more at [/lib/dropboxAPIv2.js]| +| **paramsObj** | *Object* | ✅ | Parameters object, depends on resource field| +| **fileBin** | *Blob/null* | ✅ | File to upload, depends on resource field | +| **onSuccessCallback** | *Function* | ✅ | Callback on succes | +| **onErrorCallback** | *Function* | ✅ | Callback on error | +| **callMethodXhrObjCallback** | *Function* | | return directly the *TiDropbox.xhr* object of the current *TiDropbox.callMethod*, so you can invoke all xhr methods you need: abort, onload, onsendstream, ecc.. | + +After obtaining a valid token, you can call any method: ```js -TiDropbox.callMethod (methodStr, paramsObj, fileBin, onSuccessCallback, onErrorCallback) +// Upload the a.txt file to my app's Dropbox home +TiDropbox.callMethod({ + methodStr: "files/upload", + paramsObj: { + path: "/a.txt", + mode: "add", + autorename: true, + mute: false + }, + fileBin: Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "a.txt").read(), + onSuccessCallback: (xhr) => { + console.log("onSuccessCallback checkins response-> " + xhr.responseText); + }, + onErrorCallback: (e) => { + console.error("onErrorCallback checkins response-> " + JSON.stringify(e)); + if (JSON.stringify(e).indexOf("invalid_access_token") != -1) { + //The session has expired, I need a new token }; + // Do something... + } + }, + callMethodXhrObjCallback: (currentCallMethodXhr) => { + currentCallMethodXhr.onsendstream = function (e) { + if (e.progress) { + console.log(JSON.stringify('Upload progress --> ' + (e.progress * 100) + '%')); + } + } + } +}); ``` -- **methodStr** (*string*): represent API target. It contains Dropbox's namespace and method name. eg. `"files/upload"` or `"sharing/share_folder"` or more at [/lib/dropboxAPIv2.js] -- **paramsObj** (*object*): parameters, depends on resource field -- **fileBin** (*blob/null*): file to upload, depends on resource field -- **onSuccessCallback** (*function*): callback on succes -- **onErrorCallback** (*function*): callback on error -### Revoke AccessToken +### - revokeAccessToken +**`TiDropbox.revokeAccessToken(callback)`** +| Callback parameters| Type |Description | +|--|--|--| +| **success** | *Boolean* | Response result| +| **access_token** | *String* | Access token key| +| **msg** | *String* | Description of the response result | Revoke the access token. -Callback return an object with these parameters: -- **success** (*boolean*): response result -- **access_token** (*string*): access token key -- **msg** (*string*): description of the response result ```js -TiDropbox.revokeAccessToken(function(e){ - if(e.success){ - // Logout, do something... - Titanium.UI.createAlertDialog({ - title: "REVOKE AUTH SUCCESS", - message: e.msg, - buttonNames: ['OK'] - }).show(); - }else{ - Titanium.UI.createAlertDialog({ - title: "REVOKE AUTH PROBLEM", - message: e.msg, - buttonNames: ['OK'] - }).show(); - }; +TiDropbox.revokeAccessToken(function (e) { + if (e.success) { + // Logout, do something... + Titanium.UI.createAlertDialog({ + title: "REVOKE AUTH SUCCESS", + message: e.msg, + buttonNames: ['OK'] + }).show(); + } else { + Titanium.UI.createAlertDialog({ + title: "REVOKE AUTH PROBLEM", + message: e.msg, + buttonNames: ['OK'] + }).show(); + }; }); ``` -That's all. Simple :) +That's all! :) # Example of use ### File upload ```js var TiDropbox = require("ti.dropbox").TiDropbox; -TiDropbox.init('', ''); +TiDropbox.init({ + APP_KEY: 'e9tribefg77q4wg', /**/ + APP_SECRET: 'dkrhmji4z14k2wf', /**/ + redirectUri: 'https://astrovicapps.com/_apptest/tidropbox_cb.html', /**/ + response_type: "code", // "token" or "code". Token flow expires after 4 hours! + app_mime_scheme: "tidropbox" // **/ +}); // Check if I have a token -if(Ti.App.Properties.getString('DROPBOX_TOKENS',null))){ +if (Ti.App.Properties.getString('DROPBOX_TOKENS', null)) { login(); - }else{ - TiDropbox.revokeAccessToken(function(){ +} else { + TiDropbox.revokeAccessToken(function () { // Logout, do something... }); }; -function login(){ - TiDropbox.generateAuthUrl(function(e){ - if(e.success){ - // I'm logged, now I can call any method (/lib/dropboxAPIv2.js) - // For example, if I want upload a.txt file on Dropbox App root folder - var methodStr = "files/upload"; - var paramsObj: { - path: "/a.txt", - mode: "add", - autorename: true, - mute: false +function login() { + TiDropbox.generateAuthUrl(function (e) { + if (e.success) { + // I'm logged, now I can call any method (/lib/dropboxAPIv2.js) + // For example, if I want upload a.txt file on Dropbox App root folder + fileUpload(); + } else { + Titanium.UI.createAlertDialog({ + title: "AUTH PROBLEM", + message: e.msg, + buttonNames: ['OK'] + }).show(); }; - var fileBin = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "a.txt").read(); - TiDropbox.callMethod(methodStr, paramsObj, fileBin, onSuccessCallback, onErrorCallback) - }else{ + }); +}; + +function fileUpload() { + + TiDropbox.callMethod({ + methodStr: "files/upload", + paramsObj: { + path: "/a.txt", + mode: "add", + autorename: true, + mute: false + }, + fileBin: Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "a.txt").read(), + onSuccessCallback: onSuccessCallback, + onErrorCallback: onErrorCallback, + callMethodXhrObjCallback: callMethodXhrObjCallback + }); + + // callback functions + function onSuccessCallback(xhr) { + Ti.API.info("onSuccessCallback checkins response-> " + xhr.responseText); Titanium.UI.createAlertDialog({ - title: "AUTH PROBLEM", - message: e.msg, + title: "METHOD SUCCESS", + message: xhr.responseText, buttonNames: ['OK'] }).show(); - }; - }); -}; + }; -// callback functions -function onSuccessCallback(xhr) { - Ti.API.info("onSuccessCallback checkins response-> " + xhr.responseText); - Titanium.UI.createAlertDialog({ - title: "METHOD SUCCESS", - message: xhr.responseText, - buttonNames: ['OK'] - }).show(); -}; + function onErrorCallback(e) { + Ti.API.info("onErrorCallback checkins response-> " + JSON.stringify(e)); + Titanium.UI.createAlertDialog({ + title: "METHOD FAILED", + message: JSON.stringify(e), + buttonNames: ['OK'] + }).show(); + if (JSON.stringify(e).indexOf("invalid_access_token") != -1) { + //The session has expired, I need a new token + Ti.App.Properties.setString('DROPBOX_TOKENS', null); + login(); + }; + }; -function onErrorCallback(e) { - Ti.API.info("onErrorCallback checkins response-> " + JSON.stringify(e)); - Titanium.UI.createAlertDialog({ - title: "METHOD FAILED", - message: JSON.stringify(e), - buttonNames: ['OK'] - }).show(); - if(JSON.stringify(e).indexOf("invalid_access_token")!=-1){ - //The session has expired, I need a new token - Ti.App.Properties.setString('DROPBOX_TOKENS',null); - login(); + function callMethodXhrObjCallback(currentCallMethodXhr) { + currentCallMethodXhr.onsendstream = function (e) { + Ti.API.debug(JSON.stringify(e)); + if (e.progress) { + Ti.API.debug(JSON.stringify('Upload progress --> ' + (e.progress * 100) + '%')); + } + }; }; }; ``` @@ -166,80 +346,108 @@ function onErrorCallback(e) { ### File download ```js var TiDropbox = require("ti.dropbox").TiDropbox; -TiDropbox.init('', ''); +TiDropbox.init({ + APP_KEY: 'e9tribefg77q4wg', /**/ + APP_SECRET: 'dkrhmji4z14k2wf', /**/ + redirectUri: 'https://astrovicapps.com/_apptest/tidropbox_cb.html', /**/ + response_type: "code", // "token" or "code". Token flow expires after 4 hours! + app_mime_scheme: "tidropbox" // **/ +}); // Check if I have a token -if(Ti.App.Properties.getString('DROPBOX_TOKENS',null))){ +if (Ti.App.Properties.getString('DROPBOX_TOKENS', null)) { login(); - }else{ - TiDropbox.revokeAccessToken(function(){ +} else { + TiDropbox.revokeAccessToken(function () { // Logout, do something... }); }; -function login(){ - TiDropbox.generateAuthUrl(function(){ - if(e.success){ - // I'm logged, now I can call any method (/lib/dropboxAPIv2.js) - // For example, if I want download Prime_Numbers.txt file from Dropbox App - var methodStr = "files/download"; - var paramsObj: { - path: "/Homework/math/Prime_Numbers.txt" - }; - TiDropbox.callMethod(methodStr, paramsObj, null, onSuccessCallback, onErrorCallback) - }else{ - Titanium.UI.createAlertDialog({ - title: "AUTH PROBLEM", - message: e.msg, - buttonNames: ['OK'] - }).show(); - }; +function login() { + TiDropbox.generateAuthUrl(function () { + if (e.success) { + // I'm logged, now I can call any method (/lib/dropboxAPIv2.js) + // For example, if I want download Prime_Numbers.txt file from Dropbox App + downloadFile(); + } else { + Titanium.UI.createAlertDialog({ + title: "AUTH PROBLEM", + message: e.msg, + buttonNames: ['OK'] + }).show(); + }; }); }; -// callback functions -function onSuccessCallback(xhr) { - Ti.API.debug("onSuccessCallback checkins response-> " + xhr.responseText); - - // Write downloaded data in a file - if(xhr.responseData){ - var filePath = Titanium.Filesystem.applicationDataDirectory + "myDownloadedFile.txt"; - var f = Titanium.Filesystem.getFile(filePath); - f.write(xhr.responseData); - - // I check if I saved the file properly - setTimeout(function(){ - Ti.API.debug(filePath + " exists? ---> " + file.exists()); - if(f.exists()){ - if(OS_IOS){ - Ti.UI.iOS.createDocumentViewer({url:filePath}).show(); +function downloadFile() { + + TiDropbox.callMethod({ + methodStr: "files/download", + paramsObj: { + path: "/Homework/math/Prime_Numbers.txt" + }, + fileBin: null, + onSuccessCallback: onSuccessCallback, + onErrorCallback: onErrorCallback, + callMethodXhrObjCallback: callMethodXhrObjCallback + }); + + // callback functions + function onSuccessCallback(xhr) { + Ti.API.debug("onSuccessCallback checkins response-> " + xhr.responseText); + + // Write downloaded data in a file + if (xhr.responseData) { + var filePath = Titanium.Filesystem.applicationDataDirectory + "myDownloadedFile.txt"; + var f = Titanium.Filesystem.getFile(filePath); + f.write(xhr.responseData); + + // I check if I saved the file properly + setTimeout(function () { + Ti.API.debug(filePath + " exists? ---> " + file.exists()); + if (f.exists()) { + if (OS_IOS) { + Ti.UI.iOS.createDocumentViewer({ + url: filePath + }).show(); + }; + } else { + Titanium.UI.createAlertDialog({ + title: "DOWNLOAD FAILED", + message: "Something went wrong in the file writing...", + buttonNames: ['OK'] + }).show(); + }; + }, 1000); }; - }else{ + }; + + function onErrorCallback(e) { + Ti.API.debug("onErrorCallback checkins response-> " + JSON.stringify(e)); Titanium.UI.createAlertDialog({ - title: "DOWNLOAD FAILED", - message: "Something went wrong in the file writing...", + title: "METHOD FAILED", + message: JSON.stringify(e), buttonNames: ['OK'] }).show(); - }; - },1000); - }; -}; - -function onErrorCallback(e) { - Ti.API.debug("onErrorCallback checkins response-> " + JSON.stringify(e)); - Titanium.UI.createAlertDialog({ - title: "METHOD FAILED", - message: JSON.stringify(e), - buttonNames: ['OK'] - }).show(); - if(JSON.stringify(e).indexOf("invalid_access_token")!=-1){ - //The session has expired, I need a new token - Ti.App.Properties.setString('DROPBOX_TOKENS',null); - login(); + if (JSON.stringify(e).indexOf("invalid_access_token") != -1) { + //The session has expired, I need a new token + Ti.App.Properties.setString('DROPBOX_TOKENS', null); + login(); + }; }; -}; + + function callMethodXhrObjCallback(currentCallMethodXhr) { + currentCallMethodXhr.onsendstream = function (e) { + if (e.progress) { + console.log(JSON.stringify('Upload progress --> ' + (e.progress * 100) + '%')); + } + } + } +} ``` +Download and build this project to test other methods + # Screenshots @@ -260,7 +468,7 @@ function onErrorCallback(e) { ### Todos - - OAauth 2 code flow + - OAauth 2 code flow ✅ DONE! # Guidelines for pull requests @@ -282,7 +490,7 @@ All done :) Now you can send your pull request. License ---- -**Copyright (c) 2016 Vittorio Sorbera, astrovicApps** +**Copyright (c) 2016-23 Vittorio Sorbera, AstrovicApps** Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/app/controllers/index.js b/app/controllers/index.js index 72ed1cc..5e95bc4 100644 --- a/app/controllers/index.js +++ b/app/controllers/index.js @@ -1,5 +1,12 @@ var TiDropbox = require("ti.dropbox").TiDropbox; -TiDropbox.init('e9tribefg77q4wg'/**/, 'https://astrovicapps.com/'/**/); + +TiDropbox.init({ + APP_KEY: 'e9tribefg77q4wg', /**/ + APP_SECRET: 'dkrhmji4z14k2wf', /**/ + redirectUri: 'https://astrovicapps.com/_apptest/tidropbox_cb.html', /**/ + response_type: "code", // "token" or "code". Token flow expires after 4 hours! + app_mime_scheme: "tidropbox" // **/ +}); var dropboxAPIv2 = require("dropboxAPIv2").dropboxAPIv2; var selectedMethod = ""; @@ -66,7 +73,7 @@ function checkToken(){ $.apiListTV.show(); }else{ $.loginBtn.logged = false; - $.loginBtntitle = "Dropbox Login"; + $.loginBtn.title = "Dropbox Login"; $.apiListTV.hide(); }; $.activityBgView.hide(); @@ -176,7 +183,18 @@ function callMethod(e){ }else{ var blob = null; }; - TiDropbox.callMethod(selectedMethod, params, blob, onSuccessCallback, onErrorCallback); + TiDropbox.callMethod({ + methodStr: selectedMethod, + paramsObj: params, + fileBin: blob, + onSuccessCallback: onSuccessCallback, + onErrorCallback: onErrorCallback, + callMethodXhrObjCallback: function(e) { + console.log("/////// current TiDropbox.xhr object //////////"); + console.log(e); + console.log("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"); + } + }); }else if(e.source.text === "Info"){ Alloy.createController('infoWin',{method : dropboxAPIv2[selectedMethod], selectedMethod : selectedMethod}).getView().open(); }; @@ -309,7 +327,13 @@ function createTest(){ i++; if(testFiles[i]){ $.activityLbl.text = testFiles[i].methodStr + "\n" + testFiles[i].testParams.path; - TiDropbox.callMethod(testFiles[i].methodStr, testFiles[i].testParams, testFiles[i].blob, onSuccess, onError); + TiDropbox.callMethod({ + methodStr: testFiles[i].methodStr, + paramsObj: testFiles[i].testParams, + fileBin: testFiles[i].blob, + onSuccessCallback: onSuccess, + onErrorCallback: onError + }); }else{ $.activityLbl.text = "DONE :)"; setTimeout(function(){ diff --git a/app/controllers/infoWin.js b/app/controllers/infoWin.js index c8dd990..886d072 100644 --- a/app/controllers/infoWin.js +++ b/app/controllers/infoWin.js @@ -93,5 +93,5 @@ function closeWin(e){ } function onLoad(e){ - $.wv.setScalesPageToFit(true); + $.wv.scalesPageToFit = true; } diff --git a/app/lib/tidropbox.js b/app/lib/tidropbox.js index bf6cec8..5774f05 100644 --- a/app/lib/tidropbox.js +++ b/app/lib/tidropbox.js @@ -21,29 +21,48 @@ var TiDropbox = {}; (function() { - var window; + var webView, Deeply; var dropboxAPIv2 = require("../lib/dropboxAPIv2").dropboxAPIv2; var OS_IOS = (Ti.Platform.osname != "android"); var OS_ANDROID = !OS_IOS; - - TiDropbox.init = function(clientId, redirectUri) { - TiDropbox.clientId = clientId; - TiDropbox.redirectUri = redirectUri; + if (OS_ANDROID) { + Deeply = require('ti.deeply'); + Deeply.setCallback(function (e) { + Ti.API.debug('Deep link called'); + androidDeepLink(e); + }); + } + + TiDropbox.init = function(params) { + TiDropbox.APP_KEY = params.APP_KEY; + TiDropbox.APP_SECRET = params.APP_SECRET; + TiDropbox.redirectUri = params.redirectUri; + TiDropbox.response_type = params.response_type || "code"; // "token" or "code" + TiDropbox.app_mime_scheme = params.app_mime_scheme; TiDropbox.ACCESS_TOKEN = Ti.App.Properties.getString('DROPBOX_TOKENS',null); + TiDropbox.ACCESS_REFRESH_TOKEN = Ti.App.Properties.getString('DROPBOX_REFRESH_TOKENS', null); TiDropbox.xhr = null; TiDropbox.API_URL = "https://api.dropboxapi.com/2/"; }; TiDropbox.revokeAccessToken = function(revokeAuth_callback) { - TiDropbox.callMethod("auth/token/revoke", null, null, onSuccess_self, onFailed_self); + TiDropbox.callMethod({ + methodStr: "auth/token/revoke", + paramsObj: null, + fileBin: null, + onSuccessCallback: onSuccess_self, + onErrorCallback: onFailed_self + }); + + Ti.App.Properties.setString('DROPBOX_TOKENS', null); + Ti.App.Properties.setString('DROPBOX_REFRESH_TOKENS', null); function onSuccess_self() { /*Titanium.UI.createAlertDialog({ title: "auth/token/revoke", message: "LOGOUT SUCCESS", buttonNames: ['OK'] - }).show();*/ - Ti.App.Properties.setString('DROPBOX_TOKENS',null); + }).show();*/ revokeAuth_callback({ access_token: null, success : true, @@ -56,10 +75,7 @@ var TiDropbox = {}; title: "auth/token/revoke", message: JSON.stringify(e), buttonNames: ['OK'] - }).show();*/ - //if(JSON.stringify(e).indexOf("invalid_access_token")!=-1){ - Ti.App.Properties.setString('DROPBOX_TOKENS',null); - //}; + }).show();*/ revokeAuth_callback({ access_token: null, success : false, @@ -73,13 +89,14 @@ var TiDropbox = {}; var searchKey = path.search('Documents'); path = path.substring(0, searchKey); path = path + 'Library/Cookies/'; + //path = path + 'SystemData/com.apple.SafariViewService/Library/Cookies';// + Ti.App.id; var f = Ti.Filesystem.getFile(path); Ti.API.debug("cookie path ---> " + path); Ti.API.debug("cookie path exists() ---> " + f.exists()); if(f.exists()){ f.deleteDirectory(true); }; - f=null; + f=null; }else if(OS_ANDROID){ Ti.Network.removeAllSystemCookies(); }; @@ -107,17 +124,32 @@ var TiDropbox = {}; return; }; + var url; + if (TiDropbox.response_type === "code") { + url = 'https://www.dropbox.com/oauth2/authorize?response_type=code&token_access_type=offline&client_id=%s&redirect_uri=%s&force_reauthentication=true'; + } else { + url = 'https://www.dropbox.com/oauth2/authorize?response_type=token&client_id=%s&redirect_uri=%s&force_reauthentication=true'; + } showAuthorizeUI( - String.format('https://www.dropbox.com/oauth2/authorize?response_type=token&client_id=%s&redirect_uri=%s', - TiDropbox.clientId, + String.format( + url, + TiDropbox.APP_KEY, TiDropbox.redirectUri) ); return; }; - TiDropbox.callMethod = function(methodStr, paramsObj, fileBin, onSuccess_callback, onError_callback, callMethodXhrObj_callback) { + TiDropbox.callMethod = function(params) { + var methodStr, paramsObj, fileBin, onSuccess_callback, onError_callback, callMethodXhrObj_callback; + methodStr = params.methodStr; + paramsObj = params.paramsObj; + fileBin = params.fileBin; + onSuccess_callback = params.onSuccessCallback; + onError_callback = params.onErrorCallback; + callMethodXhrObj_callback = params.callMethodXhrObjCallback; + var urlEndpoint = dropboxAPIv2[methodStr].uri + "?reject_cors_preflight=true"; //&authorization=Bearer%20"+TiDropbox.ACCESS_TOKEN; //urlEndpoint = "https://api.dropboxapi.com/2/files/list_folder?authorization=Bearer%20"+TiDropbox.ACCESS_TOKEN+"&args=%7B%0A%20%20%22path%22%3A%20%22%22%2C%0A%20%20%22recursive%22%3A%20false%2C%0A%20%20%22include_media_info%22%3A%20false%2C%0A%20%20%22include_deleted%22%3A%20false%2C%0A%20%20%22include_has_explicit_shared_members%22%3A%20false%0A%7D&reject_cors_preflight=true"; Ti.API.debug("\n\n******\ncallMethod: methodStr--> " + methodStr); @@ -137,15 +169,42 @@ var TiDropbox = {}; Ti.API.error(JSON.stringify(TiDropbox.xhr.responseText)); Ti.API.error(JSON.stringify(TiDropbox.xhr.responseData)); var errorMsg = TiDropbox.xhr.statusText + "\n" + e; - if(TiDropbox.xhr.responseText){ - errorMsg = TiDropbox.xhr.responseText.replace(/\"/g,"'").replace(/\\/g,"'"); - //errorMsg = TiDropbox.xhr.statusText + "\n" + errorMsg; - }else if(TiDropbox.xhr.responseData){ - errorMsg = TiDropbox.xhr.responseData; - }; - if (onError_callback) { - onError_callback(errorMsg); - } + + if (e.code === 401) { + Ti.API.error("TiDropbox ERROR: token expired, try refresh it"); + TiDropbox.refreshOauth2Token(function(e){ + if (e.success) { + TiDropbox.callMethod({ + methodStr: "auth/token/revoke", + paramsObj: null, + fileBin: null, + onSuccessCallback: onSuccess_self, + onErrorCallback: onFailed_self, + callMethodXhrObjCallback: callMethodXhrObj_callback + }); + } else { + if (TiDropbox.xhr.responseText) { + errorMsg = TiDropbox.xhr.responseText.replace(/\"/g, "'").replace(/\\/g, "'"); + //errorMsg = TiDropbox.xhr.statusText + "\n" + errorMsg; + } else if (TiDropbox.xhr.responseData) { + errorMsg = TiDropbox.xhr.responseData; + }; + if (onError_callback) { + onError_callback(errorMsg); + } + } + }) + } else { + if (TiDropbox.xhr.responseText) { + errorMsg = TiDropbox.xhr.responseText.replace(/\"/g, "'").replace(/\\/g, "'"); + //errorMsg = TiDropbox.xhr.statusText + "\n" + errorMsg; + } else if (TiDropbox.xhr.responseData) { + errorMsg = TiDropbox.xhr.responseData; + }; + if (onError_callback) { + onError_callback(errorMsg); + } + } }; TiDropbox.xhr.onload = function(_xhr) { @@ -233,12 +292,132 @@ var TiDropbox = {}; } }; + TiDropbox.generateOauth2Token = function (code,generateOauth2Token_callback) { + console.log("TiDropbox.generateOauth2Token!!!"); + var xhr = Titanium.Network.createHTTPClient(); + var urlEndpoint = "https://api.dropbox.com/oauth2/token?code=" + code + + "&grant_type=authorization_code&redirect_uri=" + TiDropbox.redirectUri + + "&client_id=" + TiDropbox.APP_KEY + "&client_secret=" + TiDropbox.APP_SECRET; + xhr.timeout = 10000; + + xhr.onload = function (e) { + Ti.API.debug("TiDropbox.generateOauth2Token: " + xhr.responseText); + var response = JSON.parse(xhr.responseText); + var token = response.access_token; + var refresh_token = response.refresh_token; + + TiDropbox.ACCESS_TOKEN = token; + Ti.App.Properties.setString('DROPBOX_TOKENS', TiDropbox.ACCESS_TOKEN); + Ti.App.Properties.setString('DROPBOX_REFRESH_TOKENS', refresh_token); + Ti.API.debug('tidropbox_token: ' + token); + Ti.API.debug('tidropbox_refresh_token: ' + refresh_token); + console.log(response) + if (TiDropbox.auth_callback != undefined) { + TiDropbox.auth_callback({ + access_token: token, + success: true, + msg: "Ok, you have an access token" + }); + } + + destroyAuthorizeUI(); + }; + + xhr.onerror = function (e) { + console.log(e); + Ti.API.error("TiDropbox.generateOauth2Token: " + xhr.responseText); + generateOauth2Token_callback({ + access_token: null, + success: false, + msg: "Invalid or expired access token" + }); + }; + + console.log(urlEndpoint); + xhr.open("POST", urlEndpoint); + + var base64encodeString = Ti.Utils.base64encode(TiDropbox.APP_KEY + ":" + TiDropbox.APP_SECRET).toString(); + console.log(base64encodeString); + /*xhr.setRequestHeader( + "Authorization", + "Basic " + base64encodeString + );*/ + xhr.setRequestHeader("Content-Type", "application/json"); + + xhr.send(); + }; + + TiDropbox.refreshOauth2Token = function (refreshOauth2Token_callback) { + console.log("TiDropbox.refreshOauth2Token!!!"); + var refresh_token = Ti.App.Properties.getString('DROPBOX_REFRESH_TOKENS',""); + var xhr = Titanium.Network.createHTTPClient(); + var urlEndpoint = "https://api.dropbox.com/oauth2/token?" + + "grant_type=refresh_token&refresh_token=" + refresh_token + + "&client_id=" + TiDropbox.APP_KEY + "&client_secret=" + TiDropbox.APP_SECRET; + xhr.timeout = 10000; + + xhr.onload = function (e) { + Ti.API.debug("TiDropbox.refreshOauth2Token: " + xhr.responseText); + var response = JSON.parse(xhr.responseText); + var token = response.access_token; + + TiDropbox.ACCESS_TOKEN = token; + Ti.App.Properties.setString('DROPBOX_TOKENS', TiDropbox.ACCESS_TOKEN); + Ti.API.debug('tidropbox_token: ' + token); + refreshOauth2Token_callback({ + success: true, + msg: "Ok, you have an access token" + }); + if (TiDropbox.auth_callback != undefined) { + TiDropbox.auth_callback({ + access_token: token, + success: true, + msg: "Ok, you have an access token" + }); + } + }; + + xhr.onerror = function (e) { + console.log(e); + Ti.API.error("TiDropbox.refreshOauth2Token: " + xhr.responseText); + + // Can't refresh token, so try login again + TiDropbox.generateAuthUrl(function (e) { + Ti.API.debug("generateAuthUrl checkins response-> " + JSON.stringify(e)); + if (e.success) { + refreshOauth2Token_callback({ + success: true, + msg: "Ok, you have an access token" + }); + } else { + Ti.App.Properties.setString('DROPBOX_TOKENS', null); + Ti.App.Properties.setString('DROPBOX_REFRESH_TOKENS', null); + refreshOauth2Token_callback({ + success: false, + msg: "Invalid or expired access token" + }); + } + }); + }; + + console.log(urlEndpoint); + xhr.open("POST", urlEndpoint); + + /*xhr.setRequestHeader( + "Authorization", + "Basic " + Ti.Utils.base64encode(TiDropbox.APP_KEY + ":" + TiDropbox.APP_SECRET) + );*/ + xhr.setRequestHeader("Content-Type", "application/json"); + + xhr.send(); + }; + /** * code to display the familiar web login dialog we all know and love */ function showAuthorizeUI(pUrl) { - window = Ti.UI.createWindow({ + /*window = Ti.UI.createWindow({ top: (OS_IOS) ? "20dp" : "0dp", //modal: true, //fullscreen: true, @@ -288,6 +467,7 @@ var TiDropbox = {}; autoDetect: [Ti.UI.AUTODETECT_NONE], ignoreSslError : true }); + Ti.API.debug('Setting:[' + Ti.UI.AUTODETECT_NONE + ']'); webView.addEventListener('beforeload', function(e) { @@ -297,19 +477,15 @@ var TiDropbox = {}; webView.stopLoading = true; } }); - webView.addEventListener('load', authorizeUICallback); - view.add(webView); - - closeLabel.addEventListener('click', function(){ - if (TiDropbox.auth_callback != undefined) { - TiDropbox.auth_callback({ - access_token: null, - success : false, - msg : "No access token... try again" - }); - } - destroyAuthorizeUI(); - }); + if (OS_IOS) { + webView.addEventListener('load', authorizeUICallback); + } else { + webView.addEventListener('open', authorizeUICallback); + } + webView.addEventListener('close', closeAuthorizeUI); + view.add(webView); + + closeLabel.addEventListener('click', closeAuthorizeUI); window.add(closeLabel); window.add(view); @@ -319,28 +495,199 @@ var TiDropbox = {}; animation.duration = 500; setTimeout(function(){ view.animate(animation); - },OS_IOS ? 10 : 1000); + },OS_IOS ? 10 : 1000);*/ + + webView = require('ti.webdialog'); + if (OS_IOS) { + + webView.open({ + url: pUrl + "&callbackURL=" + TiDropbox.app_mime_scheme + "://", //'https://example.com/oauth?callbackURL=myapp://' + }); + + Ti.App.iOS.addEventListener('handleurl', handleurl); + webView.addEventListener('close', iOSwebViewOnCloseCallback); + return; + + var authSession = webView.createAuthenticationSession({ + url: pUrl + "&callbackURL=" + TiDropbox.app_mime_scheme + "://", //'https://example.com/oauth?callbackURL=myapp://', + scheme: TiDropbox.app_mime_scheme + }); + + authSession.addEventListener('callback', function (e) { + console.log("authSession callback"); + console.log(e); + if (!e.success) { + Ti.API.error('Error authenticating: ' + e.error); + closeAuthorizeUI(); + return; + } + Ti.API.info('Callback URL: ' + e.callbackURL); + + if (TiDropbox.response_type === "code") { + var code = e.callbackURL.match(/dropbox_token\?([^&]*)/)[1]; + // Adesso dovrei richiedere il token con l'api /oauth2/token + TiDropbox.generateOauth2Token(code, function (e) { + console.log("TiDropbox.generateOauth2Token callback"); + console.log(e); + if (!e.success) { + Ti.API.error('Error authenticating: ' + e.error); + closeAuthorizeUI(); + return; + } else { + authorizeUICallback({ + url: e.callbackURL + }) + } + }) + } else { + authorizeUICallback({ + url: e.callbackURL + }) + } + }); + + authSession.start(); // Or cancel() to cancel it manually. + } else { + webView.open({ + url: pUrl + "&callbackURL=" + TiDropbox.app_mime_scheme + }); + + //Ti.App.addEventListener("resumed", androidDeepLink); + webView.addEventListener('close', androidWebViewOnCloseCallback); + } + }; + + function iOSwebViewOnCloseCallback() { + Ti.API.debug("TiDropbox iOSwebViewOnCloseCallback"); + Ti.App.iOS.fireEvent('handleurl'); }; + function androidWebViewOnCloseCallback() { + Ti.API.debug("TiDropbox androidWebViewOnCloseCallback"); + //Ti.App.addEventListener("resumed", resumed); + }; + var handleurlCalled = false; + function handleurl(e) { + // check if it's alredy trigged to avoid double call + if (handleurlCalled) { + console.warn("TiDropbox: handleurl already trigged!") + return; + } + handleurlCalled = true; + setTimeout(() => { + handleurlCalled = false; + }, 1000); + + Ti.API.debug('handleurl'); + console.log(e); + + if (webView.isOpen()) { + webView.close(); + } + + var callbackURL; + try { + callbackURL = e.launchOptions.url; + } catch (error) { + callbackURL = null; + } + + if (!callbackURL) { + Ti.API.error('Error handleurl: no callbackURL'); + closeAuthorizeUI(); + return; + } + Ti.API.info('Callback URL: ' + callbackURL); + useCallbackURL(callbackURL); + } + + function useCallbackURL(callbackURL) { + if (TiDropbox.response_type === "code") { + var code = callbackURL.match(/dropbox_token\?([^&]*)/)[1]; + // Adesso dovrei richiedere il token con l'api /oauth2/token + TiDropbox.generateOauth2Token(code, function (e) { + console.log("TiDropbox.generateOauth2Token callback"); + console.log(e); + if (!e.success) { + Ti.API.error('Error authenticating: ' + e.error); + closeAuthorizeUI(); + return; + } else { + authorizeUICallback({ + url: callbackURL + }) + } + }) + } else { + authorizeUICallback({ + url: callbackURL + }) + } + } + + function closeAuthorizeUI() { + if (TiDropbox.auth_callback != undefined) { + TiDropbox.auth_callback({ + access_token: null, + success: false, + msg: "No access token... try again" + }); + } + destroyAuthorizeUI(); + } + + function androidDeepLink(e) { + console.log("androidDeepLink intent data --->"); + console.log(e); + console.log("<--- androidDeepLink intent data"); + var callbackURL = e.data; + + + + if (callbackURL && callbackURL.indexOf(TiDropbox.app_mime_scheme) > -1) { + useCallbackURL(callbackURL); + return; + var currIntent = Titanium.Android.currentActivity.intent; + if (currIntent.hasExtra("dropbox_token")) { + console.log('currIntent.hasExtras("data")'); + //var notifData = currIntent.getStringExtra("fcm_data"); + currIntent.putExtra("data", null); + } else { + console.log('currIntent has NOT Extras ("data")'); + } + Titanium.Android.currentActivity.intent.data = null; + } else { + Ti.API.error('Error androidDeepLink: no callbackURL'); + closeAuthorizeUI(); + return; + } + } /** * unloads the UI used to have the user authorize the application */ function destroyAuthorizeUI() { - Ti.API.debug('destroyAuthorizeUI'); - // if the window doesn't exist, exit - if (window == null) { - return; - } - + Ti.API.debug('destroyAuthorizeUI'); // remove the UI try { - Ti.API.debug('destroyAuthorizeUI:webView.removeEventListener'); - webView.removeEventListener('load', authorizeUICallback); - Ti.API.debug('destroyAuthorizeUI:window.close()'); - window.close(); + Ti.API.debug('destroyAuthorizeUI: webView.removeEventListener'); + if (OS_IOS) { + Ti.API.debug('destroyAuthorizeUI: Ti.App.iOS.handleurl.removeEventListener'); + Ti.App.iOS.removeEventListener('handleurl', handleurl); + webView.removeEventListener('close', iOSwebViewOnCloseCallback); + } else { + Ti.API.debug('destroyAuthorizeUI: Ti.App.removeEventListener resumed'); + //Ti.App.removeEventListener("resumed", androidDeepLink); + webView.removeEventListener('close', androidWebViewOnCloseCallback); + } + //Ti.API.debug('destroyAuthorizeUI: window.close()'); + //window.close(); + if (webView.isOpen()) { + webView.close(); + } } catch (ex) { + console.error(ex); Ti.API.debug('Cannot destroy the authorize UI. Ignoring.'); } }; @@ -409,4 +756,4 @@ var TiDropbox = {}; })(); -exports.TiDropbox = TiDropbox; +exports.TiDropbox = TiDropbox; \ No newline at end of file diff --git a/app/styles/index.tss b/app/styles/index.tss index be210ec..0f20d81 100644 --- a/app/styles/index.tss +++ b/app/styles/index.tss @@ -1,5 +1,6 @@ ".container": { - backgroundColor:"white" + backgroundColor:"white", + extendSafeArea: false } "Button": { diff --git a/app/styles/infoWin.tss b/app/styles/infoWin.tss index f58a6e2..64545e3 100644 --- a/app/styles/infoWin.tss +++ b/app/styles/infoWin.tss @@ -1,7 +1,8 @@ ".container": { top: "0dp", width: '100%', - backgroundColor: "rgb(255,255,255,0.5)" + backgroundColor: "rgb(255,255,255,0.5)", + extendSafeArea: false } ".container[platform=ios]": { diff --git a/dist/ti.dropbox-commonjs-5.0.0.zip b/dist/ti.dropbox-commonjs-5.0.0.zip new file mode 100644 index 0000000..ce7c982 Binary files /dev/null and b/dist/ti.dropbox-commonjs-5.0.0.zip differ diff --git a/dist/ti.dropbox-commonjs-6.0.0.zip b/dist/ti.dropbox-commonjs-6.0.0.zip new file mode 100644 index 0000000..9070966 Binary files /dev/null and b/dist/ti.dropbox-commonjs-6.0.0.zip differ diff --git a/modules/android/ti.deeply/3.0.0/LICENSE b/modules/android/ti.deeply/3.0.0/LICENSE new file mode 100644 index 0000000..ace85e0 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/LICENSE @@ -0,0 +1,7 @@ +Copyright 2018 Andrea Jonus + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/Ti.Deeply.json b/modules/android/ti.deeply/3.0.0/Ti.Deeply.json new file mode 100644 index 0000000..0633099 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/Ti.Deeply.json @@ -0,0 +1 @@ +{"proxies":{"ti.deeply.TiDeeplyModule":{"superPackageName":"org.appcelerator.kroll","methods":{"setCallback":{"runOnUiThread":false,"hasInvocation":false,"args":[{"converter":"org.appcelerator.kroll.KrollConverter","defaultValueProvider":"org.appcelerator.kroll.KrollConverter","name":"_callback","sourceName":"_callback","type":"org.appcelerator.kroll.KrollFunction"}],"apiName":"setCallback","converter":"org.appcelerator.kroll.KrollConverter","defaultValueProvider":"org.appcelerator.kroll.KrollConverter","name":"__default_name__","returnType":"void"}},"dynamicProperties":{"callback":{"set":true,"nativeConverter":"org.appcelerator.kroll.KrollConverter","setMethodName":"setCallback","setMethodArgs":[{"converter":"org.appcelerator.kroll.KrollConverter","defaultValueProvider":"org.appcelerator.kroll.KrollConverter","name":"_callback","sourceName":"_callback","type":"org.appcelerator.kroll.KrollFunction"}],"setDefaultProviders":["org.appcelerator.kroll.KrollConverter"],"converter":"org.appcelerator.kroll.KrollConverter","defaultValueProvider":"org.appcelerator.kroll.KrollConverter","retain":true,"javascriptConverter":"org.appcelerator.kroll.KrollConverter","getHasInvocation":false,"runOnUiThread":false,"setReturnType":"void","get":false,"name":"callback","setHasInvocation":false}},"superProxyBindingClassName":"org.appcelerator.kroll.KrollModuleBindingGen","proxyClassName":"TiDeeplyModule","proxyAttrs":{"propertyAccessors":[],"fullAPIName":"TiDeeply","name":"TiDeeply","proxyClassName":"ti.deeply.TiDeeplyModule","isTopLevel":false,"id":"ti.deeply"},"packageName":"ti.deeply","sourceName":"ti.deeply.TiDeeplyModuleBindingGen","isTitaniumSdk":false,"superProxyClassName":"KrollModule","isModule":true,"genClassName":"TiDeeplyModuleBindingGen"}},"modules":{"ti.deeply.TiDeeplyModule":{"apiName":"TiDeeply"}}} \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/documentation/index.html b/modules/android/ti.deeply/3.0.0/documentation/index.html new file mode 100644 index 0000000..db64aa8 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/documentation/index.html @@ -0,0 +1,39 @@ +

Ti.Deeply Module

+ +

Description

+ +

TODO: Enter your module description here

+ +

Accessing the Ti.Deeply Module

+ +

To access this module from JavaScript, you would do the following:

+ +
var ti_deeply = require("ti.deeply");
+ +

The ti_deeply variable is a reference to the Module object.

+ +

Reference

+ +

TODO: If your module has an API, you should document +the reference here.

+ +

ti_deeply.function

+ +

TODO: This is an example of a module function.

+ +

ti_deeply.property

+ +

TODO: This is an example of a module property.

+ +

Usage

+ +

TODO: Enter your usage example here

+ +

Author

+ +

TODO: Enter your author name, email and other contact +details you want to share here.

+ +

License

+ +

TODO: Enter your license/legal information here.

\ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/example/app.js b/modules/android/ti.deeply/3.0.0/example/app.js new file mode 100644 index 0000000..242da9d --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/example/app.js @@ -0,0 +1,12 @@ +var Deeply = require('ti.deeply'); + +var win = Ti.UI.createWindow({ backgroundColor: 'white' }); + +Deeply.setCallback(function (e) { + Ti.API.debug('Deep link called with:'); + Ti.API.debug('\tdata:', e.data); + Ti.API.debug('\taction:', e.action); + Ti.API.debug('\textras', e.extras); +}); + +win.open(); \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar new file mode 100644 index 0000000..ddecf29 Binary files /dev/null and b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar differ diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.md5 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.md5 new file mode 100644 index 0000000..73934f2 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.md5 @@ -0,0 +1 @@ +f2f028935feae86c431519677a99dd31 \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.sha1 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.sha1 new file mode 100644 index 0000000..dcd7180 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.sha1 @@ -0,0 +1 @@ +fd1e1b890e86086d5706156c9da809a9a1dc33f9 \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.sha256 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.sha256 new file mode 100644 index 0000000..98cb8f4 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.sha256 @@ -0,0 +1 @@ +34e1ada684eb457b51dfa2d360168a76f02bc3fc4dd0f71c73c1010dddd53b23 \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.sha512 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.sha512 new file mode 100644 index 0000000..01c33f7 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.aar.sha512 @@ -0,0 +1 @@ +ead7a58ce89b1f0c04092025d5c611919983d0d5d10294b435f18bfd38b6b83db72f71b3731c217c9753ef9e8a7725fdbf8b702d5b08f1862d050de308edfb5d \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom new file mode 100644 index 0000000..5340ef2 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom @@ -0,0 +1,20 @@ + + + 4.0.0 + ti + deeply + 3.0.0 + aar + + + org.appcelerator + titanium + 10.2.0 + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + 1.6.21 + + + diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.md5 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.md5 new file mode 100644 index 0000000..0360359 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.md5 @@ -0,0 +1 @@ +5311f5c9554b089aaa316077a53887d6 \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.sha1 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.sha1 new file mode 100644 index 0000000..821dcc1 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.sha1 @@ -0,0 +1 @@ +b88e8589447ef62c8896a937e661daace3ff4b9d \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.sha256 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.sha256 new file mode 100644 index 0000000..853049c --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.sha256 @@ -0,0 +1 @@ +a299472cabde29efd7d78b2c67ed68ba5f7a18099fa4681d46007236be446206 \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.sha512 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.sha512 new file mode 100644 index 0000000..423a6f4 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/3.0.0/deeply-3.0.0.pom.sha512 @@ -0,0 +1 @@ +7cbfe90e9ed37c79b574f277a8cd43f3b68d45fcb92ebb3082ee8458b3257c43c8ad3c30fe663b13894f7e76d7f43b94ec15160c391717e2874d662328b3a0c1 \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml new file mode 100644 index 0000000..1dcc8a6 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml @@ -0,0 +1,13 @@ + + + ti + deeply + + 3.0.0 + 3.0.0 + + 3.0.0 + + 20230317093026 + + diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.md5 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.md5 new file mode 100644 index 0000000..4d9a931 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.md5 @@ -0,0 +1 @@ +80e9a8acb8331f06708a4d9d0be96ab1 \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.sha1 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.sha1 new file mode 100644 index 0000000..c6463d0 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.sha1 @@ -0,0 +1 @@ +b33911cbba120a13c460e9383c26585739fd3f6b \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.sha256 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.sha256 new file mode 100644 index 0000000..9b5d68d --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.sha256 @@ -0,0 +1 @@ +15b8c9e15871ec022882ab6dcc20f06cc3df074fe27c542215446264b1a5d308 \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.sha512 b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.sha512 new file mode 100644 index 0000000..d69149a --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/m2repository/ti/deeply/maven-metadata.xml.sha512 @@ -0,0 +1 @@ +bf07035ec3b5f8c28f5b5dc4ba34ef0925920ea648289754a8be74d322a4f424900b16a7380043e02bb30e4b5020f4fcec48bb4337c1ccb9fb8fda1c2b5e66e2 \ No newline at end of file diff --git a/modules/android/ti.deeply/3.0.0/manifest b/modules/android/ti.deeply/3.0.0/manifest new file mode 100644 index 0000000..1c07549 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/manifest @@ -0,0 +1,18 @@ +# +# this is your module manifest and used by Titanium +# during compilation, packaging, distribution, etc. +# +version: 3.0.0 +apiversion: 4 +architectures: arm64-v8a armeabi-v7a x86 x86_64 +description: Ti.Deeply +author: Andrea Jonus +license: MIT +copyright: Copyright (c) 2018 by Andrea Jonus + +# these should not be edited +name: Ti.Deeply +moduleid: ti.deeply +guid: 7b8608cb-4877-4490-9c93-b6273a76059d +platform: android +minsdk: 10.2.0 diff --git a/modules/android/ti.deeply/3.0.0/timodule.xml b/modules/android/ti.deeply/3.0.0/timodule.xml new file mode 100644 index 0000000..2076cf2 --- /dev/null +++ b/modules/android/ti.deeply/3.0.0/timodule.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/modules/commonjs/ti.dropbox/4.1.0/LICENSE b/modules/commonjs/ti.dropbox/6.0.0/LICENSE similarity index 100% rename from modules/commonjs/ti.dropbox/4.1.0/LICENSE rename to modules/commonjs/ti.dropbox/6.0.0/LICENSE diff --git a/modules/commonjs/ti.dropbox/4.1.0/manifest b/modules/commonjs/ti.dropbox/6.0.0/manifest similarity index 57% rename from modules/commonjs/ti.dropbox/4.1.0/manifest rename to modules/commonjs/ti.dropbox/6.0.0/manifest index 55519f6..90e15b3 100644 --- a/modules/commonjs/ti.dropbox/4.1.0/manifest +++ b/modules/commonjs/ti.dropbox/6.0.0/manifest @@ -1,8 +1,8 @@ -version: 4.1.0 +version: 6.0.0 description: Titanium Appcelerator Javascript Dropbox API v2 -author: Vittorio Sorbera, astrovicApps +author: Vittorio Sorbera, AstrovicApps license: ISC -copyright: Copyright © 2022 Vittorio Sorbera, astrovicApps +copyright: Copyright © 2023 Vittorio Sorbera, AstrovicApps name: ti.dropbox moduleid: ti.dropbox guid: 3e89fe63-2de2-415e-9777-a63ed2c102a1 diff --git a/modules/commonjs/ti.dropbox/4.1.0/package.json b/modules/commonjs/ti.dropbox/6.0.0/package.json similarity index 97% rename from modules/commonjs/ti.dropbox/4.1.0/package.json rename to modules/commonjs/ti.dropbox/6.0.0/package.json index 4c37fbc..320babd 100644 --- a/modules/commonjs/ti.dropbox/4.1.0/package.json +++ b/modules/commonjs/ti.dropbox/6.0.0/package.json @@ -1,6 +1,6 @@ { "name": "ti.dropbox", - "version": "4.1.0", + "version": "6.0.0", "description": "Titanium Appcelerator Javascript Dropbox API v2", "titaniumManifest": { "guid": "3e89fe63-2de2-415e-9777-a63ed2c102a1" diff --git a/modules/commonjs/ti.dropbox/4.1.0/ti.dropbox.js b/modules/commonjs/ti.dropbox/6.0.0/ti.dropbox.js similarity index 80% rename from modules/commonjs/ti.dropbox/4.1.0/ti.dropbox.js rename to modules/commonjs/ti.dropbox/6.0.0/ti.dropbox.js index d4d7ae3..cfe42f7 100644 --- a/modules/commonjs/ti.dropbox/4.1.0/ti.dropbox.js +++ b/modules/commonjs/ti.dropbox/6.0.0/ti.dropbox.js @@ -5,6 +5,51 @@ module.exports = (function () { return this; })(); module.exports.location = {}; },{}],2:[function(require,module,exports){ +(function (setTimeout){ +/* global Ti:true, Titanium:true */ + +var process = module.exports = {}; + +process.nextTick = function nextTick(fn) { + setTimeout(fn, 0); +}; + +process.title = 'titanium'; +process.titanium = true; +process.env = {}; +process.argv = []; + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { + return '/'; +}; + +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; + +process.stdout = {}; +process.stderr = {}; + +process.stdout.write = function (msg) { + Ti.API.info(msg); +}; + +process.stderr.write = function (msg) { + Ti.API.error(msg); +}; + +'addEventListener removeEventListener removeListener hasEventListener fireEvent emit on off'.split(' ').forEach(function (name) { + process[ name ] = noop; +}); + +function noop() {} + +}).call(this,require("--timers--").setTimeout) +},{"--timers--":3}],3:[function(require,module,exports){ (function (global){ module.exports.clearInterval = clearInterval; @@ -57,7 +102,1057 @@ function setTimeout(func, delay) { } }).call(this,require("--global--")) -},{"--global--":1}],3:[function(require,module,exports){ +},{"--global--":1}],4:[function(require,module,exports){ +// http://wiki.commonjs.org/wiki/Unit_Testing/1.0 +// +// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! +// +// Originally from narwhal.js (http://narwhaljs.org) +// Copyright (c) 2009 Thomas Robinson <280north.com> +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the 'Software'), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +// when used in node, this will actually load the util module we depend on +// versus loading the builtin util module as happens otherwise +// this is a bug in node module loading as far as I am concerned +var util = require('util/'); + +var pSlice = Array.prototype.slice; +var hasOwn = Object.prototype.hasOwnProperty; + +// 1. The assert module provides functions that throw +// AssertionError's when particular conditions are not met. The +// assert module must conform to the following interface. + +var assert = module.exports = ok; + +// 2. The AssertionError is defined in assert. +// new assert.AssertionError({ message: message, +// actual: actual, +// expected: expected }) + +assert.AssertionError = function AssertionError(options) { + this.name = 'AssertionError'; + this.actual = options.actual; + this.expected = options.expected; + this.operator = options.operator; + if (options.message) { + this.message = options.message; + this.generatedMessage = false; + } else { + this.message = getMessage(this); + this.generatedMessage = true; + } + var stackStartFunction = options.stackStartFunction || fail; + + if (Error.captureStackTrace) { + Error.captureStackTrace(this, stackStartFunction); + } + else { + // non v8 browsers so we can have a stacktrace + var err = new Error(); + if (err.stack) { + var out = err.stack; + + // try to strip useless frames + var fn_name = stackStartFunction.name; + var idx = out.indexOf('\n' + fn_name); + if (idx >= 0) { + // once we have located the function frame + // we need to strip out everything before it (and its line) + var next_line = out.indexOf('\n', idx + 1); + out = out.substring(next_line + 1); + } + + this.stack = out; + } + } +}; + +// assert.AssertionError instanceof Error +util.inherits(assert.AssertionError, Error); + +function replacer(key, value) { + if (util.isUndefined(value)) { + return '' + value; + } + if (util.isNumber(value) && !isFinite(value)) { + return value.toString(); + } + if (util.isFunction(value) || util.isRegExp(value)) { + return value.toString(); + } + return value; +} + +function truncate(s, n) { + if (util.isString(s)) { + return s.length < n ? s : s.slice(0, n); + } else { + return s; + } +} + +function getMessage(self) { + return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' + + self.operator + ' ' + + truncate(JSON.stringify(self.expected, replacer), 128); +} + +// At present only the three keys mentioned above are used and +// understood by the spec. Implementations or sub modules can pass +// other keys to the AssertionError's constructor - they will be +// ignored. + +// 3. All of the following functions must throw an AssertionError +// when a corresponding condition is not met, with a message that +// may be undefined if not provided. All assertion methods provide +// both the actual and expected values to the assertion error for +// display purposes. + +function fail(actual, expected, message, operator, stackStartFunction) { + throw new assert.AssertionError({ + message: message, + actual: actual, + expected: expected, + operator: operator, + stackStartFunction: stackStartFunction + }); +} + +// EXTENSION! allows for well behaved errors defined elsewhere. +assert.fail = fail; + +// 4. Pure assertion tests whether a value is truthy, as determined +// by !!guard. +// assert.ok(guard, message_opt); +// This statement is equivalent to assert.equal(true, !!guard, +// message_opt);. To test strictly for the value true, use +// assert.strictEqual(true, guard, message_opt);. + +function ok(value, message) { + if (!value) fail(value, true, message, '==', assert.ok); +} +assert.ok = ok; + +// 5. The equality assertion tests shallow, coercive equality with +// ==. +// assert.equal(actual, expected, message_opt); + +assert.equal = function equal(actual, expected, message) { + if (actual != expected) fail(actual, expected, message, '==', assert.equal); +}; + +// 6. The non-equality assertion tests for whether two objects are not equal +// with != assert.notEqual(actual, expected, message_opt); + +assert.notEqual = function notEqual(actual, expected, message) { + if (actual == expected) { + fail(actual, expected, message, '!=', assert.notEqual); + } +}; + +// 7. The equivalence assertion tests a deep equality relation. +// assert.deepEqual(actual, expected, message_opt); + +assert.deepEqual = function deepEqual(actual, expected, message) { + if (!_deepEqual(actual, expected)) { + fail(actual, expected, message, 'deepEqual', assert.deepEqual); + } +}; + +function _deepEqual(actual, expected) { + // 7.1. All identical values are equivalent, as determined by ===. + if (actual === expected) { + return true; + + } else if (util.isBuffer(actual) && util.isBuffer(expected)) { + if (actual.length != expected.length) return false; + + for (var i = 0; i < actual.length; i++) { + if (actual[i] !== expected[i]) return false; + } + + return true; + + // 7.2. If the expected value is a Date object, the actual value is + // equivalent if it is also a Date object that refers to the same time. + } else if (util.isDate(actual) && util.isDate(expected)) { + return actual.getTime() === expected.getTime(); + + // 7.3 If the expected value is a RegExp object, the actual value is + // equivalent if it is also a RegExp object with the same source and + // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). + } else if (util.isRegExp(actual) && util.isRegExp(expected)) { + return actual.source === expected.source && + actual.global === expected.global && + actual.multiline === expected.multiline && + actual.lastIndex === expected.lastIndex && + actual.ignoreCase === expected.ignoreCase; + + // 7.4. Other pairs that do not both pass typeof value == 'object', + // equivalence is determined by ==. + } else if (!util.isObject(actual) && !util.isObject(expected)) { + return actual == expected; + + // 7.5 For all other Object pairs, including Array objects, equivalence is + // determined by having the same number of owned properties (as verified + // with Object.prototype.hasOwnProperty.call), the same set of keys + // (although not necessarily the same order), equivalent values for every + // corresponding key, and an identical 'prototype' property. Note: this + // accounts for both named and indexed properties on Arrays. + } else { + return objEquiv(actual, expected); + } +} + +function isArguments(object) { + return Object.prototype.toString.call(object) == '[object Arguments]'; +} + +function objEquiv(a, b) { + if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b)) + return false; + // an identical 'prototype' property. + if (a.prototype !== b.prototype) return false; + // if one is a primitive, the other must be same + if (util.isPrimitive(a) || util.isPrimitive(b)) { + return a === b; + } + var aIsArgs = isArguments(a), + bIsArgs = isArguments(b); + if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) + return false; + if (aIsArgs) { + a = pSlice.call(a); + b = pSlice.call(b); + return _deepEqual(a, b); + } + var ka = objectKeys(a), + kb = objectKeys(b), + key, i; + // having the same number of owned properties (keys incorporates + // hasOwnProperty) + if (ka.length != kb.length) + return false; + //the same set of keys (although not necessarily the same order), + ka.sort(); + kb.sort(); + //~~~cheap key test + for (i = ka.length - 1; i >= 0; i--) { + if (ka[i] != kb[i]) + return false; + } + //equivalent values for every corresponding key, and + //~~~possibly expensive deep test + for (i = ka.length - 1; i >= 0; i--) { + key = ka[i]; + if (!_deepEqual(a[key], b[key])) return false; + } + return true; +} + +// 8. The non-equivalence assertion tests for any deep inequality. +// assert.notDeepEqual(actual, expected, message_opt); + +assert.notDeepEqual = function notDeepEqual(actual, expected, message) { + if (_deepEqual(actual, expected)) { + fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); + } +}; + +// 9. The strict equality assertion tests strict equality, as determined by ===. +// assert.strictEqual(actual, expected, message_opt); + +assert.strictEqual = function strictEqual(actual, expected, message) { + if (actual !== expected) { + fail(actual, expected, message, '===', assert.strictEqual); + } +}; + +// 10. The strict non-equality assertion tests for strict inequality, as +// determined by !==. assert.notStrictEqual(actual, expected, message_opt); + +assert.notStrictEqual = function notStrictEqual(actual, expected, message) { + if (actual === expected) { + fail(actual, expected, message, '!==', assert.notStrictEqual); + } +}; + +function expectedException(actual, expected) { + if (!actual || !expected) { + return false; + } + + if (Object.prototype.toString.call(expected) == '[object RegExp]') { + return expected.test(actual); + } else if (actual instanceof expected) { + return true; + } else if (expected.call({}, actual) === true) { + return true; + } + + return false; +} + +function _throws(shouldThrow, block, expected, message) { + var actual; + + if (util.isString(expected)) { + message = expected; + expected = null; + } + + try { + block(); + } catch (e) { + actual = e; + } + + message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + + (message ? ' ' + message : '.'); + + if (shouldThrow && !actual) { + fail(actual, expected, 'Missing expected exception' + message); + } + + if (!shouldThrow && expectedException(actual, expected)) { + fail(actual, expected, 'Got unwanted exception' + message); + } + + if ((shouldThrow && actual && expected && + !expectedException(actual, expected)) || (!shouldThrow && actual)) { + throw actual; + } +} + +// 11. Expected to throw an error: +// assert.throws(block, Error_opt, message_opt); + +assert.throws = function(block, /*optional*/error, /*optional*/message) { + _throws.apply(this, [true].concat(pSlice.call(arguments))); +}; + +// EXTENSION! This is annoying to write outside this module. +assert.doesNotThrow = function(block, /*optional*/message) { + _throws.apply(this, [false].concat(pSlice.call(arguments))); +}; + +assert.ifError = function(err) { if (err) {throw err;}}; + +var objectKeys = Object.keys || function (obj) { + var keys = []; + for (var key in obj) { + if (hasOwn.call(obj, key)) keys.push(key); + } + return keys; +}; + +},{"util/":7}],5:[function(require,module,exports){ +if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + }; +} else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } +} + +},{}],6:[function(require,module,exports){ +module.exports = function isBuffer(arg) { + return arg && typeof arg === 'object' + && typeof arg.copy === 'function' + && typeof arg.fill === 'function' + && typeof arg.readUInt8 === 'function'; +} +},{}],7:[function(require,module,exports){ +(function (process,global,console){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var formatRegExp = /%[sdj%]/g; +exports.format = function(f) { + if (!isString(f)) { + var objects = []; + for (var i = 0; i < arguments.length; i++) { + objects.push(inspect(arguments[i])); + } + return objects.join(' '); + } + + var i = 1; + var args = arguments; + var len = args.length; + var str = String(f).replace(formatRegExp, function(x) { + if (x === '%%') return '%'; + if (i >= len) return x; + switch (x) { + case '%s': return String(args[i++]); + case '%d': return Number(args[i++]); + case '%j': + try { + return JSON.stringify(args[i++]); + } catch (_) { + return '[Circular]'; + } + default: + return x; + } + }); + for (var x = args[i]; i < len; x = args[++i]) { + if (isNull(x) || !isObject(x)) { + str += ' ' + x; + } else { + str += ' ' + inspect(x); + } + } + return str; +}; + + +// Mark that a method should not be used. +// Returns a modified function which warns once by default. +// If --no-deprecation is set, then it is a no-op. +exports.deprecate = function(fn, msg) { + // Allow for deprecating things in the process of starting up. + if (isUndefined(global.process)) { + return function() { + return exports.deprecate(fn, msg).apply(this, arguments); + }; + } + + if (process.noDeprecation === true) { + return fn; + } + + var warned = false; + function deprecated() { + if (!warned) { + if (process.throwDeprecation) { + throw new Error(msg); + } else if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; + } + return fn.apply(this, arguments); + } + + return deprecated; +}; + + +var debugs = {}; +var debugEnviron; +exports.debuglog = function(set) { + if (isUndefined(debugEnviron)) + debugEnviron = process.env.NODE_DEBUG || ''; + set = set.toUpperCase(); + if (!debugs[set]) { + if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { + var pid = process.pid; + debugs[set] = function() { + var msg = exports.format.apply(exports, arguments); + console.error('%s %d: %s', set, pid, msg); + }; + } else { + debugs[set] = function() {}; + } + } + return debugs[set]; +}; + + +/** + * Echos the value of a value. Trys to print the value out + * in the best way possible given the different types. + * + * @param {Object} obj The object to print out. + * @param {Object} opts Optional options object that alters the output. + */ +/* legacy: obj, showHidden, depth, colors*/ +function inspect(obj, opts) { + // default options + var ctx = { + seen: [], + stylize: stylizeNoColor + }; + // legacy... + if (arguments.length >= 3) ctx.depth = arguments[2]; + if (arguments.length >= 4) ctx.colors = arguments[3]; + if (isBoolean(opts)) { + // legacy... + ctx.showHidden = opts; + } else if (opts) { + // got an "options" object + exports._extend(ctx, opts); + } + // set default options + if (isUndefined(ctx.showHidden)) ctx.showHidden = false; + if (isUndefined(ctx.depth)) ctx.depth = 2; + if (isUndefined(ctx.colors)) ctx.colors = false; + if (isUndefined(ctx.customInspect)) ctx.customInspect = true; + if (ctx.colors) ctx.stylize = stylizeWithColor; + return formatValue(ctx, obj, ctx.depth); +} +exports.inspect = inspect; + + +// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics +inspect.colors = { + 'bold' : [1, 22], + 'italic' : [3, 23], + 'underline' : [4, 24], + 'inverse' : [7, 27], + 'white' : [37, 39], + 'grey' : [90, 39], + 'black' : [30, 39], + 'blue' : [34, 39], + 'cyan' : [36, 39], + 'green' : [32, 39], + 'magenta' : [35, 39], + 'red' : [31, 39], + 'yellow' : [33, 39] +}; + +// Don't use 'blue' not visible on cmd.exe +inspect.styles = { + 'special': 'cyan', + 'number': 'yellow', + 'boolean': 'yellow', + 'undefined': 'grey', + 'null': 'bold', + 'string': 'green', + 'date': 'magenta', + // "name": intentionally not styling + 'regexp': 'red' +}; + + +function stylizeWithColor(str, styleType) { + var style = inspect.styles[styleType]; + + if (style) { + return '\u001b[' + inspect.colors[style][0] + 'm' + str + + '\u001b[' + inspect.colors[style][1] + 'm'; + } else { + return str; + } +} + + +function stylizeNoColor(str, styleType) { + return str; +} + + +function arrayToHash(array) { + var hash = {}; + + array.forEach(function(val, idx) { + hash[val] = true; + }); + + return hash; +} + + +function formatValue(ctx, value, recurseTimes) { + // Provide a hook for user-specified inspect functions. + // Check that value is an object with an inspect function on it + if (ctx.customInspect && + value && + isFunction(value.inspect) && + // Filter out the util module, it's inspect function is special + value.inspect !== exports.inspect && + // Also filter out any prototype objects using the circular check. + !(value.constructor && value.constructor.prototype === value)) { + var ret = value.inspect(recurseTimes, ctx); + if (!isString(ret)) { + ret = formatValue(ctx, ret, recurseTimes); + } + return ret; + } + + // Primitive types cannot have properties + var primitive = formatPrimitive(ctx, value); + if (primitive) { + return primitive; + } + + // Look up the keys of the object. + var keys = Object.keys(value); + var visibleKeys = arrayToHash(keys); + + if (ctx.showHidden) { + keys = Object.getOwnPropertyNames(value); + } + + // IE doesn't make error fields non-enumerable + // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx + if (isError(value) + && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { + return formatError(value); + } + + // Some type of object without properties can be shortcutted. + if (keys.length === 0) { + if (isFunction(value)) { + var name = value.name ? ': ' + value.name : ''; + return ctx.stylize('[Function' + name + ']', 'special'); + } + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } + if (isDate(value)) { + return ctx.stylize(Date.prototype.toString.call(value), 'date'); + } + if (isError(value)) { + return formatError(value); + } + } + + var base = '', array = false, braces = ['{', '}']; + + // Make Array say that they are Array + if (isArray(value)) { + array = true; + braces = ['[', ']']; + } + + // Make functions say that they are functions + if (isFunction(value)) { + var n = value.name ? ': ' + value.name : ''; + base = ' [Function' + n + ']'; + } + + // Make RegExps say that they are RegExps + if (isRegExp(value)) { + base = ' ' + RegExp.prototype.toString.call(value); + } + + // Make dates with properties first say the date + if (isDate(value)) { + base = ' ' + Date.prototype.toUTCString.call(value); + } + + // Make error with message first say the error + if (isError(value)) { + base = ' ' + formatError(value); + } + + if (keys.length === 0 && (!array || value.length == 0)) { + return braces[0] + base + braces[1]; + } + + if (recurseTimes < 0) { + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } else { + return ctx.stylize('[Object]', 'special'); + } + } + + ctx.seen.push(value); + + var output; + if (array) { + output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); + } else { + output = keys.map(function(key) { + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); + }); + } + + ctx.seen.pop(); + + return reduceToSingleString(output, base, braces); +} + + +function formatPrimitive(ctx, value) { + if (isUndefined(value)) + return ctx.stylize('undefined', 'undefined'); + if (isString(value)) { + var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') + .replace(/'/g, "\\'") + .replace(/\\"/g, '"') + '\''; + return ctx.stylize(simple, 'string'); + } + if (isNumber(value)) + return ctx.stylize('' + value, 'number'); + if (isBoolean(value)) + return ctx.stylize('' + value, 'boolean'); + // For some reason typeof null is "object", so special case here. + if (isNull(value)) + return ctx.stylize('null', 'null'); +} + + +function formatError(value) { + return '[' + Error.prototype.toString.call(value) + ']'; +} + + +function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + for (var i = 0, l = value.length; i < l; ++i) { + if (hasOwnProperty(value, String(i))) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + String(i), true)); + } else { + output.push(''); + } + } + keys.forEach(function(key) { + if (!key.match(/^\d+$/)) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, true)); + } + }); + return output; +} + + +function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { + var name, str, desc; + desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; + if (desc.get) { + if (desc.set) { + str = ctx.stylize('[Getter/Setter]', 'special'); + } else { + str = ctx.stylize('[Getter]', 'special'); + } + } else { + if (desc.set) { + str = ctx.stylize('[Setter]', 'special'); + } + } + if (!hasOwnProperty(visibleKeys, key)) { + name = '[' + key + ']'; + } + if (!str) { + if (ctx.seen.indexOf(desc.value) < 0) { + if (isNull(recurseTimes)) { + str = formatValue(ctx, desc.value, null); + } else { + str = formatValue(ctx, desc.value, recurseTimes - 1); + } + if (str.indexOf('\n') > -1) { + if (array) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').substr(2); + } else { + str = '\n' + str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n'); + } + } + } else { + str = ctx.stylize('[Circular]', 'special'); + } + } + if (isUndefined(name)) { + if (array && key.match(/^\d+$/)) { + return str; + } + name = JSON.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.substr(1, name.length - 2); + name = ctx.stylize(name, 'name'); + } else { + name = name.replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"); + name = ctx.stylize(name, 'string'); + } + } + + return name + ': ' + str; +} + + +function reduceToSingleString(output, base, braces) { + var numLinesEst = 0; + var length = output.reduce(function(prev, cur) { + numLinesEst++; + if (cur.indexOf('\n') >= 0) numLinesEst++; + return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; + }, 0); + + if (length > 60) { + return braces[0] + + (base === '' ? '' : base + '\n ') + + ' ' + + output.join(',\n ') + + ' ' + + braces[1]; + } + + return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; +} + + +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. +function isArray(ar) { + return Array.isArray(ar); +} +exports.isArray = isArray; + +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; + +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; + +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; + +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; + +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; + +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; + +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; + +function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; + +function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; + +function isError(e) { + return isObject(e) && + (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; + +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; + +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; + +exports.isBuffer = require('./support/isBuffer'); + +function objectToString(o) { + return Object.prototype.toString.call(o); +} + + +function pad(n) { + return n < 10 ? '0' + n.toString(10) : n.toString(10); +} + + +var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', + 'Oct', 'Nov', 'Dec']; + +// 26 Feb 16:19:34 +function timestamp() { + var d = new Date(); + var time = [pad(d.getHours()), + pad(d.getMinutes()), + pad(d.getSeconds())].join(':'); + return [d.getDate(), months[d.getMonth()], time].join(' '); +} + + +// log is just a thin wrapper to console.log that prepends a timestamp +exports.log = function() { + console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); +}; + + +/** + * Inherit the prototype methods from one constructor into another. + * + * The Function.prototype.inherits from lang.js rewritten as a standalone + * function (not on Function.prototype). NOTE: If this file is to be loaded + * during bootstrapping this function needs to be rewritten using some native + * functions as prototype setup using normal JavaScript does not work as + * expected during bootstrapping (see mirror.js in r114903). + * + * @param {function} ctor Constructor function which needs to inherit the + * prototype. + * @param {function} superCtor Constructor function to inherit prototype from. + */ +exports.inherits = require('inherits'); + +exports._extend = function(origin, add) { + // Don't do anything if add isn't an object + if (!add || !isObject(add)) return origin; + + var keys = Object.keys(add); + var i = keys.length; + while (i--) { + origin[keys[i]] = add[keys[i]]; + } + return origin; +}; + +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + +}).call(this,require("--process--"),require("--global--"),require("--console--")) +},{"--console--":9,"--global--":1,"--process--":2,"./support/isBuffer":6,"inherits":5}],8:[function(require,module,exports){ +module.exports = now + +function now() { + return new Date().getTime() +} + +},{}],9:[function(require,module,exports){ +var util = require("util"); +var now = require("date-now"); + +var _console = {}; +var times = {}; + +var functions = [ + ['log','info'], + ['info','info'], + ['warn','warn'], + ['error','error'] +]; + +functions.forEach(function(tuple) { + _console[tuple[0]] = function() { + Ti.API[tuple[1]](util.format.apply(util, arguments)); + }; +}); + +_console.time = function(label) { + times[label] = now(); +}; + +_console.timeEnd = function(label) { + var time = times[label]; + if (!time) { + throw new Error("No such label: " + label); + } + + var duration = now() - time; + _console.log(label + ": " + duration + "ms"); +}; + +_console.trace = function() { + var err = new Error(); + err.name = "Trace"; + err.message = util.format.apply(null, arguments); + _console.error(err.stack); +}; + +_console.dir = function(object) { + _console.log(util.inspect(object) + "\n"); +}; + +_console.assert = function(expression) { + if (!expression) { + var arr = Array.prototype.slice.call(arguments, 1); + require("assert").ok(false, util.format.apply(null, arr)); + } +}; + +module.exports = _console; + +},{"assert":4,"date-now":8,"util":12}],10:[function(require,module,exports){ +arguments[4][5][0].apply(exports,arguments) +},{"dup":5}],11:[function(require,module,exports){ +arguments[4][6][0].apply(exports,arguments) +},{"dup":6}],12:[function(require,module,exports){ +arguments[4][7][0].apply(exports,arguments) +},{"--console--":9,"--global--":1,"--process--":2,"./support/isBuffer":11,"dup":7,"inherits":10}],13:[function(require,module,exports){ /** * this code was inspired by the work done by Adam Płócieniak * available at https://github.com/adasq/dropbox-v2-api/blob/master/dist/api.json @@ -4003,8 +5098,8 @@ exports.dropboxAPIv2 = { } } -},{}],4:[function(require,module,exports){ -(function (setTimeout){ +},{}],14:[function(require,module,exports){ +(function (console,setTimeout){ /** * * this code was inspired by the work done by David Riccitelli @@ -4028,29 +5123,48 @@ var TiDropbox = {}; (function() { - var window; + var webView, Deeply; var dropboxAPIv2 = require("../lib/dropboxAPIv2").dropboxAPIv2; var OS_IOS = (Ti.Platform.osname != "android"); var OS_ANDROID = !OS_IOS; + if (OS_ANDROID) { + Deeply = require('ti.deeply'); + Deeply.setCallback(function (e) { + Ti.API.debug('Deep link called'); + androidDeepLink(e); + }); + } - TiDropbox.init = function(clientId, redirectUri) { - TiDropbox.clientId = clientId; - TiDropbox.redirectUri = redirectUri; + TiDropbox.init = function(params) { + TiDropbox.APP_KEY = params.APP_KEY; + TiDropbox.APP_SECRET = params.APP_SECRET; + TiDropbox.redirectUri = params.redirectUri; + TiDropbox.response_type = params.response_type || "code"; // "token" or "code" + TiDropbox.app_mime_scheme = params.app_mime_scheme; TiDropbox.ACCESS_TOKEN = Ti.App.Properties.getString('DROPBOX_TOKENS',null); + TiDropbox.ACCESS_REFRESH_TOKEN = Ti.App.Properties.getString('DROPBOX_REFRESH_TOKENS', null); TiDropbox.xhr = null; TiDropbox.API_URL = "https://api.dropboxapi.com/2/"; }; TiDropbox.revokeAccessToken = function(revokeAuth_callback) { - TiDropbox.callMethod("auth/token/revoke", null, null, onSuccess_self, onFailed_self); + TiDropbox.callMethod({ + methodStr: "auth/token/revoke", + paramsObj: null, + fileBin: null, + onSuccessCallback: onSuccess_self, + onErrorCallback: onFailed_self + }); + + Ti.App.Properties.setString('DROPBOX_TOKENS', null); + Ti.App.Properties.setString('DROPBOX_REFRESH_TOKENS', null); function onSuccess_self() { /*Titanium.UI.createAlertDialog({ title: "auth/token/revoke", message: "LOGOUT SUCCESS", buttonNames: ['OK'] - }).show();*/ - Ti.App.Properties.setString('DROPBOX_TOKENS',null); + }).show();*/ revokeAuth_callback({ access_token: null, success : true, @@ -4063,10 +5177,7 @@ var TiDropbox = {}; title: "auth/token/revoke", message: JSON.stringify(e), buttonNames: ['OK'] - }).show();*/ - //if(JSON.stringify(e).indexOf("invalid_access_token")!=-1){ - Ti.App.Properties.setString('DROPBOX_TOKENS',null); - //}; + }).show();*/ revokeAuth_callback({ access_token: null, success : false, @@ -4080,13 +5191,14 @@ var TiDropbox = {}; var searchKey = path.search('Documents'); path = path.substring(0, searchKey); path = path + 'Library/Cookies/'; + //path = path + 'SystemData/com.apple.SafariViewService/Library/Cookies';// + Ti.App.id; var f = Ti.Filesystem.getFile(path); Ti.API.debug("cookie path ---> " + path); Ti.API.debug("cookie path exists() ---> " + f.exists()); if(f.exists()){ f.deleteDirectory(true); }; - f=null; + f=null; }else if(OS_ANDROID){ Ti.Network.removeAllSystemCookies(); }; @@ -4114,17 +5226,32 @@ var TiDropbox = {}; return; }; + var url; + if (TiDropbox.response_type === "code") { + url = 'https://www.dropbox.com/oauth2/authorize?response_type=code&token_access_type=offline&client_id=%s&redirect_uri=%s&force_reauthentication=true'; + } else { + url = 'https://www.dropbox.com/oauth2/authorize?response_type=token&client_id=%s&redirect_uri=%s&force_reauthentication=true'; + } showAuthorizeUI( - String.format('https://www.dropbox.com/oauth2/authorize?response_type=token&client_id=%s&redirect_uri=%s', - TiDropbox.clientId, + String.format( + url, + TiDropbox.APP_KEY, TiDropbox.redirectUri) ); return; }; - TiDropbox.callMethod = function(methodStr, paramsObj, fileBin, onSuccess_callback, onError_callback, callMethodXhrObj_callback) { + TiDropbox.callMethod = function(params) { + var methodStr, paramsObj, fileBin, onSuccess_callback, onError_callback, callMethodXhrObj_callback; + methodStr = params.methodStr; + paramsObj = params.paramsObj; + fileBin = params.fileBin; + onSuccess_callback = params.onSuccessCallback; + onError_callback = params.onErrorCallback; + callMethodXhrObj_callback = params.callMethodXhrObjCallback; + var urlEndpoint = dropboxAPIv2[methodStr].uri + "?reject_cors_preflight=true"; //&authorization=Bearer%20"+TiDropbox.ACCESS_TOKEN; //urlEndpoint = "https://api.dropboxapi.com/2/files/list_folder?authorization=Bearer%20"+TiDropbox.ACCESS_TOKEN+"&args=%7B%0A%20%20%22path%22%3A%20%22%22%2C%0A%20%20%22recursive%22%3A%20false%2C%0A%20%20%22include_media_info%22%3A%20false%2C%0A%20%20%22include_deleted%22%3A%20false%2C%0A%20%20%22include_has_explicit_shared_members%22%3A%20false%0A%7D&reject_cors_preflight=true"; Ti.API.debug("\n\n******\ncallMethod: methodStr--> " + methodStr); @@ -4144,15 +5271,42 @@ var TiDropbox = {}; Ti.API.error(JSON.stringify(TiDropbox.xhr.responseText)); Ti.API.error(JSON.stringify(TiDropbox.xhr.responseData)); var errorMsg = TiDropbox.xhr.statusText + "\n" + e; - if(TiDropbox.xhr.responseText){ - errorMsg = TiDropbox.xhr.responseText.replace(/\"/g,"'").replace(/\\/g,"'"); - //errorMsg = TiDropbox.xhr.statusText + "\n" + errorMsg; - }else if(TiDropbox.xhr.responseData){ - errorMsg = TiDropbox.xhr.responseData; - }; - if (onError_callback) { - onError_callback(errorMsg); - } + + if (e.code === 401) { + Ti.API.error("TiDropbox ERROR: token expired, try refresh it"); + TiDropbox.refreshOauth2Token(function(e){ + if (e.success) { + TiDropbox.callMethod({ + methodStr: "auth/token/revoke", + paramsObj: null, + fileBin: null, + onSuccessCallback: onSuccess_self, + onErrorCallback: onFailed_self, + callMethodXhrObjCallback: callMethodXhrObj_callback + }); + } else { + if (TiDropbox.xhr.responseText) { + errorMsg = TiDropbox.xhr.responseText.replace(/\"/g, "'").replace(/\\/g, "'"); + //errorMsg = TiDropbox.xhr.statusText + "\n" + errorMsg; + } else if (TiDropbox.xhr.responseData) { + errorMsg = TiDropbox.xhr.responseData; + }; + if (onError_callback) { + onError_callback(errorMsg); + } + } + }) + } else { + if (TiDropbox.xhr.responseText) { + errorMsg = TiDropbox.xhr.responseText.replace(/\"/g, "'").replace(/\\/g, "'"); + //errorMsg = TiDropbox.xhr.statusText + "\n" + errorMsg; + } else if (TiDropbox.xhr.responseData) { + errorMsg = TiDropbox.xhr.responseData; + }; + if (onError_callback) { + onError_callback(errorMsg); + } + } }; TiDropbox.xhr.onload = function(_xhr) { @@ -4240,12 +5394,132 @@ var TiDropbox = {}; } }; + TiDropbox.generateOauth2Token = function (code,generateOauth2Token_callback) { + console.log("TiDropbox.generateOauth2Token!!!"); + var xhr = Titanium.Network.createHTTPClient(); + var urlEndpoint = "https://api.dropbox.com/oauth2/token?code=" + code + + "&grant_type=authorization_code&redirect_uri=" + TiDropbox.redirectUri + + "&client_id=" + TiDropbox.APP_KEY + "&client_secret=" + TiDropbox.APP_SECRET; + xhr.timeout = 10000; + + xhr.onload = function (e) { + Ti.API.debug("TiDropbox.generateOauth2Token: " + xhr.responseText); + var response = JSON.parse(xhr.responseText); + var token = response.access_token; + var refresh_token = response.refresh_token; + + TiDropbox.ACCESS_TOKEN = token; + Ti.App.Properties.setString('DROPBOX_TOKENS', TiDropbox.ACCESS_TOKEN); + Ti.App.Properties.setString('DROPBOX_REFRESH_TOKENS', refresh_token); + Ti.API.debug('tidropbox_token: ' + token); + Ti.API.debug('tidropbox_refresh_token: ' + refresh_token); + console.log(response) + if (TiDropbox.auth_callback != undefined) { + TiDropbox.auth_callback({ + access_token: token, + success: true, + msg: "Ok, you have an access token" + }); + } + + destroyAuthorizeUI(); + }; + + xhr.onerror = function (e) { + console.log(e); + Ti.API.error("TiDropbox.generateOauth2Token: " + xhr.responseText); + generateOauth2Token_callback({ + access_token: null, + success: false, + msg: "Invalid or expired access token" + }); + }; + + console.log(urlEndpoint); + xhr.open("POST", urlEndpoint); + + var base64encodeString = Ti.Utils.base64encode(TiDropbox.APP_KEY + ":" + TiDropbox.APP_SECRET).toString(); + console.log(base64encodeString); + /*xhr.setRequestHeader( + "Authorization", + "Basic " + base64encodeString + );*/ + xhr.setRequestHeader("Content-Type", "application/json"); + + xhr.send(); + }; + + TiDropbox.refreshOauth2Token = function (refreshOauth2Token_callback) { + console.log("TiDropbox.refreshOauth2Token!!!"); + var refresh_token = Ti.App.Properties.getString('DROPBOX_REFRESH_TOKENS',""); + var xhr = Titanium.Network.createHTTPClient(); + var urlEndpoint = "https://api.dropbox.com/oauth2/token?" + + "grant_type=refresh_token&refresh_token=" + refresh_token + + "&client_id=" + TiDropbox.APP_KEY + "&client_secret=" + TiDropbox.APP_SECRET; + xhr.timeout = 10000; + + xhr.onload = function (e) { + Ti.API.debug("TiDropbox.refreshOauth2Token: " + xhr.responseText); + var response = JSON.parse(xhr.responseText); + var token = response.access_token; + + TiDropbox.ACCESS_TOKEN = token; + Ti.App.Properties.setString('DROPBOX_TOKENS', TiDropbox.ACCESS_TOKEN); + Ti.API.debug('tidropbox_token: ' + token); + refreshOauth2Token_callback({ + success: true, + msg: "Ok, you have an access token" + }); + if (TiDropbox.auth_callback != undefined) { + TiDropbox.auth_callback({ + access_token: token, + success: true, + msg: "Ok, you have an access token" + }); + } + }; + + xhr.onerror = function (e) { + console.log(e); + Ti.API.error("TiDropbox.refreshOauth2Token: " + xhr.responseText); + + // Can't refresh token, so try login again + TiDropbox.generateAuthUrl(function (e) { + Ti.API.debug("generateAuthUrl checkins response-> " + JSON.stringify(e)); + if (e.success) { + refreshOauth2Token_callback({ + success: true, + msg: "Ok, you have an access token" + }); + } else { + Ti.App.Properties.setString('DROPBOX_TOKENS', null); + Ti.App.Properties.setString('DROPBOX_REFRESH_TOKENS', null); + refreshOauth2Token_callback({ + success: false, + msg: "Invalid or expired access token" + }); + } + }); + }; + + console.log(urlEndpoint); + xhr.open("POST", urlEndpoint); + + /*xhr.setRequestHeader( + "Authorization", + "Basic " + Ti.Utils.base64encode(TiDropbox.APP_KEY + ":" + TiDropbox.APP_SECRET) + );*/ + xhr.setRequestHeader("Content-Type", "application/json"); + + xhr.send(); + }; + /** * code to display the familiar web login dialog we all know and love */ function showAuthorizeUI(pUrl) { - window = Ti.UI.createWindow({ + /*window = Ti.UI.createWindow({ top: (OS_IOS) ? "20dp" : "0dp", //modal: true, //fullscreen: true, @@ -4295,6 +5569,7 @@ var TiDropbox = {}; autoDetect: [Ti.UI.AUTODETECT_NONE], ignoreSslError : true }); + Ti.API.debug('Setting:[' + Ti.UI.AUTODETECT_NONE + ']'); webView.addEventListener('beforeload', function(e) { @@ -4304,19 +5579,15 @@ var TiDropbox = {}; webView.stopLoading = true; } }); - webView.addEventListener('load', authorizeUICallback); - view.add(webView); - - closeLabel.addEventListener('click', function(){ - if (TiDropbox.auth_callback != undefined) { - TiDropbox.auth_callback({ - access_token: null, - success : false, - msg : "No access token... try again" - }); - } - destroyAuthorizeUI(); - }); + if (OS_IOS) { + webView.addEventListener('load', authorizeUICallback); + } else { + webView.addEventListener('open', authorizeUICallback); + } + webView.addEventListener('close', closeAuthorizeUI); + view.add(webView); + + closeLabel.addEventListener('click', closeAuthorizeUI); window.add(closeLabel); window.add(view); @@ -4326,28 +5597,199 @@ var TiDropbox = {}; animation.duration = 500; setTimeout(function(){ view.animate(animation); - },OS_IOS ? 10 : 1000); + },OS_IOS ? 10 : 1000);*/ + + webView = require('ti.webdialog'); + if (OS_IOS) { + + webView.open({ + url: pUrl + "&callbackURL=" + TiDropbox.app_mime_scheme + "://", //'https://example.com/oauth?callbackURL=myapp://' + }); + + Ti.App.iOS.addEventListener('handleurl', handleurl); + webView.addEventListener('close', iOSwebViewOnCloseCallback); + return; + + var authSession = webView.createAuthenticationSession({ + url: pUrl + "&callbackURL=" + TiDropbox.app_mime_scheme + "://", //'https://example.com/oauth?callbackURL=myapp://', + scheme: TiDropbox.app_mime_scheme + }); + + authSession.addEventListener('callback', function (e) { + console.log("authSession callback"); + console.log(e); + if (!e.success) { + Ti.API.error('Error authenticating: ' + e.error); + closeAuthorizeUI(); + return; + } + Ti.API.info('Callback URL: ' + e.callbackURL); + + if (TiDropbox.response_type === "code") { + var code = e.callbackURL.match(/dropbox_token\?([^&]*)/)[1]; + // Adesso dovrei richiedere il token con l'api /oauth2/token + TiDropbox.generateOauth2Token(code, function (e) { + console.log("TiDropbox.generateOauth2Token callback"); + console.log(e); + if (!e.success) { + Ti.API.error('Error authenticating: ' + e.error); + closeAuthorizeUI(); + return; + } else { + authorizeUICallback({ + url: e.callbackURL + }) + } + }) + } else { + authorizeUICallback({ + url: e.callbackURL + }) + } + }); + + authSession.start(); // Or cancel() to cancel it manually. + } else { + webView.open({ + url: pUrl + "&callbackURL=" + TiDropbox.app_mime_scheme + }); + + //Ti.App.addEventListener("resumed", androidDeepLink); + webView.addEventListener('close', androidWebViewOnCloseCallback); + } }; + function iOSwebViewOnCloseCallback() { + Ti.API.debug("TiDropbox iOSwebViewOnCloseCallback"); + Ti.App.iOS.fireEvent('handleurl'); + }; + function androidWebViewOnCloseCallback() { + Ti.API.debug("TiDropbox androidWebViewOnCloseCallback"); + //Ti.App.addEventListener("resumed", resumed); + }; + + var handleurlCalled = false; + function handleurl(e) { + // check if it's alredy trigged to avoid double call + if (handleurlCalled) { + console.warn("TiDropbox: handleurl already trigged!") + return; + } + handleurlCalled = true; + setTimeout(() => { + handleurlCalled = false; + }, 1000); + + Ti.API.debug('handleurl'); + console.log(e); + + if (webView.isOpen()) { + webView.close(); + } + + var callbackURL; + try { + callbackURL = e.launchOptions.url; + } catch (error) { + callbackURL = null; + } + + if (!callbackURL) { + Ti.API.error('Error handleurl: no callbackURL'); + closeAuthorizeUI(); + return; + } + Ti.API.info('Callback URL: ' + callbackURL); + useCallbackURL(callbackURL); + } + + function useCallbackURL(callbackURL) { + if (TiDropbox.response_type === "code") { + var code = callbackURL.match(/dropbox_token\?([^&]*)/)[1]; + // Adesso dovrei richiedere il token con l'api /oauth2/token + TiDropbox.generateOauth2Token(code, function (e) { + console.log("TiDropbox.generateOauth2Token callback"); + console.log(e); + if (!e.success) { + Ti.API.error('Error authenticating: ' + e.error); + closeAuthorizeUI(); + return; + } else { + authorizeUICallback({ + url: callbackURL + }) + } + }) + } else { + authorizeUICallback({ + url: callbackURL + }) + } + } + + function closeAuthorizeUI() { + if (TiDropbox.auth_callback != undefined) { + TiDropbox.auth_callback({ + access_token: null, + success: false, + msg: "No access token... try again" + }); + } + destroyAuthorizeUI(); + } + + function androidDeepLink(e) { + console.log("androidDeepLink intent data --->"); + console.log(e); + console.log("<--- androidDeepLink intent data"); + var callbackURL = e.data; + + + + if (callbackURL && callbackURL.indexOf(TiDropbox.app_mime_scheme) > -1) { + useCallbackURL(callbackURL); + return; + var currIntent = Titanium.Android.currentActivity.intent; + if (currIntent.hasExtra("dropbox_token")) { + console.log('currIntent.hasExtras("data")'); + //var notifData = currIntent.getStringExtra("fcm_data"); + currIntent.putExtra("data", null); + } else { + console.log('currIntent has NOT Extras ("data")'); + } + Titanium.Android.currentActivity.intent.data = null; + } else { + Ti.API.error('Error androidDeepLink: no callbackURL'); + closeAuthorizeUI(); + return; + } + } /** * unloads the UI used to have the user authorize the application */ function destroyAuthorizeUI() { - Ti.API.debug('destroyAuthorizeUI'); - // if the window doesn't exist, exit - if (window == null) { - return; - } - + Ti.API.debug('destroyAuthorizeUI'); // remove the UI try { - Ti.API.debug('destroyAuthorizeUI:webView.removeEventListener'); - webView.removeEventListener('load', authorizeUICallback); - Ti.API.debug('destroyAuthorizeUI:window.close()'); - window.close(); + Ti.API.debug('destroyAuthorizeUI: webView.removeEventListener'); + if (OS_IOS) { + Ti.API.debug('destroyAuthorizeUI: Ti.App.iOS.handleurl.removeEventListener'); + Ti.App.iOS.removeEventListener('handleurl', handleurl); + webView.removeEventListener('close', iOSwebViewOnCloseCallback); + } else { + Ti.API.debug('destroyAuthorizeUI: Ti.App.removeEventListener resumed'); + //Ti.App.removeEventListener("resumed", androidDeepLink); + webView.removeEventListener('close', androidWebViewOnCloseCallback); + } + //Ti.API.debug('destroyAuthorizeUI: window.close()'); + //window.close(); + if (webView.isOpen()) { + webView.close(); + } } catch (ex) { + console.error(ex); Ti.API.debug('Cannot destroy the authorize UI. Ignoring.'); } }; @@ -4417,7 +5859,6 @@ var TiDropbox = {}; })(); exports.TiDropbox = TiDropbox; - -}).call(this,require("--timers--").setTimeout) -},{"--timers--":2,"../lib/dropboxAPIv2":3}]},{},[4])(4) +}).call(this,require("--console--"),require("--timers--").setTimeout) +},{"--console--":9,"--timers--":3,"../lib/dropboxAPIv2":13}]},{},[14])(14) }); diff --git a/package-lock.json b/package-lock.json index cf45766..728aa33 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ti.dropbox", - "version": "4.0.0", + "version": "6.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 055a134..1f88dc3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ti.dropbox", - "version": "4.1.0", + "version": "6.0.0", "description": "Titanium Appcelerator Javascript Dropbox API v2", "titaniumManifest": { "guid": "3e89fe63-2de2-415e-9777-a63ed2c102a1" diff --git a/plugins/ti.alloy/hooks/alloy.js b/plugins/ti.alloy/hooks/alloy.js index 1268281..71f7df8 100644 --- a/plugins/ti.alloy/hooks/alloy.js +++ b/plugins/ti.alloy/hooks/alloy.js @@ -1,6 +1,6 @@ /** * Alloy - * Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved. + * Copyright TiDev, Inc. 04/07/2022-Present * See LICENSE for more information on licensing. */ diff --git a/plugins/ti.alloy/hooks/deepclean.js b/plugins/ti.alloy/hooks/deepclean.js index dadbcb9..f6bfc2d 100644 --- a/plugins/ti.alloy/hooks/deepclean.js +++ b/plugins/ti.alloy/hooks/deepclean.js @@ -1,6 +1,6 @@ /** * Alloy - * Copyright (c) 2014 by Appcelerator, Inc. All Rights Reserved. + * Copyright TiDev, Inc. 04/07/2022-Present * See LICENSE for more information on licensing. */ diff --git a/tiapp.xml b/tiapp.xml index 35d3a9d..28ae29c 100644 --- a/tiapp.xml +++ b/tiapp.xml @@ -43,11 +43,34 @@ UIStatusBarStyle UIStatusBarStyleDefault + UTExportedTypeDeclarations + + + UTTypeTagSpecification + + public.mime-type + tidropbox + + + - - + + + + + + + + + + + + + + + @@ -57,8 +80,10 @@ default - ti.dropbox + ti.dropbox com.mobmaxime.TiWebview + ti.webdialog + ti.deeply true @@ -67,7 +92,7 @@ true true - 10.1.1.GA + 11.1.1.GA ti.alloy