Skip to content

Commit 187f177

Browse files
lesionraucao
authored andcommitted
1.0.0-alpha1
1 parent eb75e07 commit 187f177

13 files changed

+13875
-752
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "remotestoragejs",
33
"description": "JavaScript library for integrating remoteStorage",
4-
"version": "1.0.1-beta",
4+
"version": "1.0.0-alpha1",
55
"private": false,
66
"license": "MIT",
7-
"main": "./release/stable/remotestorage.js",
7+
"main": "./release/head/remotestorage.js",
88
"repository": {
99
"type": "git",
1010
"url": "git://github.com/remotestorage/remotestorage.js.git"

release/head/remotestorage-nocache.min.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

release/head/remotestorage.js

Lines changed: 16 additions & 255 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/head/remotestorage.js.map

Lines changed: 0 additions & 5 deletions
This file was deleted.

release/head/remotestorage.min.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

release/head/remotestorage-nocache.amd.js renamed to release/stable/remotestorage-nocache.amd.js

Lines changed: 38 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** remotestorage.js 0.14.1-pre, http://remotestorage.io, MIT-licensed **/
1+
/** remotestorage.js 0.14.0, http://remotestorage.io, MIT-licensed **/
22
define([], function() {
33

44
/** FILE: src/remotestorage.js **/
@@ -2155,11 +2155,11 @@ define([], function() {
21552155
/* global define */
21562156
/*!
21572157
* webfinger.js
2158-
* version 2.6.4
2158+
* version 2.4.2
21592159
* http://github.com/silverbucket/webfinger.js
21602160
*
21612161
* Developed and Maintained by:
2162-
* Nick Jennings <[email protected]> 2012
2162+
* Nick Jennings <[email protected]> 2012 - 2016
21632163
*
21642164
* webfinger.js is released under the AGPL (see LICENSE).
21652165
*
@@ -2172,11 +2172,10 @@ define([], function() {
21722172
*/
21732173

21742174
if (typeof XMLHttpRequest === 'undefined') {
2175-
// XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
2176-
XMLHttpRequest = require('xhr2');
2175+
XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
21772176
}
21782177

2179-
(function (global) {
2178+
(function (undefined) {
21802179

21812180
// URI to property name map
21822181
var LINK_URI_MAPS = {
@@ -2258,7 +2257,6 @@ if (typeof XMLHttpRequest === 'undefined') {
22582257
var self = this;
22592258

22602259
var xhr = new XMLHttpRequest();
2261-
xhr.timeout = this.config.request_timeout;
22622260

22632261
function __processState() {
22642262
if (xhr.status === 200) {
@@ -2304,18 +2302,9 @@ if (typeof XMLHttpRequest === 'undefined') {
23042302
}
23052303
};
23062304

2307-
xhr.onload = function () {
2305+
xhr.onload = function (a, b) {
23082306
__processState();
2309-
};
2310-
2311-
xhr.ontimeout = function () {
2312-
return errorHandler(generateErrorObject({
2313-
message: 'request timed out',
2314-
url: url,
2315-
status: xhr.status
2316-
}));
2317-
};
2318-
2307+
}
23192308
xhr.open('GET', url, true);
23202309
xhr.setRequestHeader('Accept', 'application/jrd+json, application/json');
23212310
xhr.send();
@@ -2352,9 +2341,6 @@ if (typeof XMLHttpRequest === 'undefined') {
23522341
}
23532342

23542343
var links = parsedJRD.links;
2355-
if (!Array.isArray(links)) {
2356-
links = [];
2357-
}
23582344
var result = { // webfinger JRD - object, json, and our own indexing
23592345
object: parsedJRD,
23602346
json: JRD,
@@ -2402,7 +2388,7 @@ if (typeof XMLHttpRequest === 'undefined') {
24022388
var host = '';
24032389
if (address.indexOf('://') > -1) {
24042390
// other uri format
2405-
host = address.replace(/ /g,'').split('/')[2];
2391+
host = address.replace(/ /g,'').split('://')[1];
24062392
} else {
24072393
// useraddress
24082394
host = address.replace(/ /g,'').split('@')[1];
@@ -2489,24 +2475,17 @@ if (typeof XMLHttpRequest === 'undefined') {
24892475
}
24902476
};
24912477

2492-
2493-
2494-
// AMD support
2495-
if (typeof define === 'function' && define.amd) {
2496-
define([], function () { return WebFinger; });
2497-
// CommonJS and Node.js module support.
2498-
} else if (typeof exports !== 'undefined') {
2499-
// Support Node.js specific `module.exports` (which can be a function)
2500-
if (typeof module !== 'undefined' && module.exports) {
2501-
exports = module.exports = WebFinger;
2502-
}
2503-
// But always support CommonJS module 1.1.1 spec (`exports` cannot be a function)
2504-
exports.WebFinger = WebFinger;
2478+
if (typeof window === 'object') {
2479+
window.WebFinger = WebFinger;
2480+
} else if (typeof (define) === 'function' && define.amd) {
2481+
define([], function () { return WebFinger; });
25052482
} else {
2506-
// browser <script> support
2507-
global.WebFinger = WebFinger;
2483+
try {
2484+
module.exports = WebFinger;
2485+
} catch (e) {}
25082486
}
2509-
})(this);
2487+
})();
2488+
25102489

25112490

25122491
/** FILE: src/authorize.js **/
@@ -6667,13 +6646,11 @@ Math.uuid = function (len, radix) {
66676646
var BASE_URL = 'https://www.googleapis.com';
66686647
var AUTH_URL = 'https://accounts.google.com/o/oauth2/auth';
66696648
var AUTH_SCOPE = 'https://www.googleapis.com/auth/drive';
6670-
var SETTINGS_KEY = 'remotestorage:googledrive';
66716649

66726650
var GD_DIR_MIME_TYPE = 'application/vnd.google-apps.folder';
66736651
var RS_DIR_MIME_TYPE = 'application/json; charset=UTF-8';
66746652

66756653
var isFolder = RemoteStorage.util.isFolder;
6676-
var hasLocalStorage;
66776654

66786655
function buildQueryString(params) {
66796656
return Object.keys(params).map(function (key) {
@@ -6733,67 +6710,22 @@ Math.uuid = function (len, radix) {
67336710
this.clientId = clientId;
67346711

67356712
this._fileIdCache = new Cache(60 * 5); // ids expire after 5 minutes (is this a good idea?)
6736-
6737-
hasLocalStorage = RemoteStorage.util.localStorageAvailable();
6738-
6739-
if (hasLocalStorage){
6740-
var settings;
6741-
try {
6742-
settings = JSON.parse(localStorage.getItem(SETTINGS_KEY));
6743-
} catch(e){}
6744-
if (settings) {
6745-
this.configure(settings);
6746-
}
6747-
}
6748-
67496713
};
67506714

67516715
RS.GoogleDrive.prototype = {
67526716
connected: false,
67536717
online: true,
67546718

67556719
configure: function (settings) { // Settings parameter compatible with WireClient
6756-
// We only update this.userAddress if settings.userAddress is set to a string or to null
6757-
if (typeof settings.userAddress !== 'undefined') { this.userAddress = settings.userAddress; }
6758-
// Same for this.token. If only one of these two is set, we leave the other one at its existing value
6759-
if (typeof settings.token !== 'undefined') { this.token = settings.token; }
6760-
6761-
var writeSettingsToCache = function() {
6762-
if (hasLocalStorage) {
6763-
localStorage.setItem(SETTINGS_KEY, JSON.stringify({
6764-
userAddress: this.userAddress,
6765-
token: this.token
6766-
}));
6767-
}
6768-
};
6769-
6770-
var handleError = function() {
6771-
this.connected = false;
6772-
delete this.token;
6773-
if (hasLocalStorage) {
6774-
localStorage.removeItem(SETTINGS_KEY);
6775-
}
6776-
};
6777-
6778-
if (this.token) {
6720+
if (settings.token) {
6721+
localStorage['remotestorage:googledrive:token'] = settings.token;
6722+
this.token = settings.token;
67796723
this.connected = true;
6780-
6781-
if (this.userAddress) {
6782-
this._emit('connected');
6783-
writeSettingsToCache.apply(this);
6784-
} else {
6785-
this.info().then(function(info) {
6786-
this.userAddress = info.user.emailAddress;
6787-
this.rs.widget.view.setUserAddress(this.userAddress);
6788-
this._emit('connected');
6789-
writeSettingsToCache.apply(this);
6790-
}.bind(this)).catch(function() {
6791-
handleError.apply(this);
6792-
this.rs._emit('error', new Error('Could not fetch user info.'));
6793-
}.bind(this));
6794-
}
6724+
this._emit('connected');
67956725
} else {
6796-
handleError.apply(this);
6726+
this.connected = false;
6727+
delete this.token;
6728+
delete localStorage['remotestorage:googledrive:token'];
67976729
}
67986730
},
67996731

@@ -6869,28 +6801,6 @@ Math.uuid = function (len, radix) {
68696801
});
68706802
},
68716803

6872-
/**
6873-
* Method: info
6874-
*
6875-
* Fetches the user's info from Google and returns a promise for it.
6876-
*
6877-
* Returns:
6878-
*
6879-
* A promise to the user's info
6880-
*/
6881-
info: function () {
6882-
var url = BASE_URL + '/drive/v2/about?fields=user';
6883-
// requesting user info(mainly for userAdress)
6884-
return this._request('GET', url, {}).then(function (resp){
6885-
try {
6886-
var info = JSON.parse(resp.responseText);
6887-
return Promise.resolve(info);
6888-
} catch (e) {
6889-
return Promise.reject(e);
6890-
}
6891-
});
6892-
},
6893-
68946804
_updateFile: function (id, path, body, contentType, options) {
68956805
var self = this;
68966806
var metadata = {
@@ -7382,18 +7292,16 @@ Math.uuid = function (len, radix) {
73827292
this._itemRefs = {};
73837293
this._metadataCache = {};
73847294

7385-
hasLocalStorage = RemoteStorage.util.localStorageAvailable();
7386-
73877295
if (hasLocalStorage){
73887296
var settings;
73897297
try {
7390-
settings = JSON.parse(localStorage.getItem(SETTINGS_KEY));
7298+
settings = JSON.parse(localStorage[SETTINGS_KEY]);
73917299
} catch(e){}
73927300
if (settings) {
73937301
this.configure(settings);
73947302
}
73957303
try {
7396-
this._itemRefs = JSON.parse(localStorage.getItem(SETTINGS_KEY+':shares'));
7304+
this._itemRefs = JSON.parse(localStorage[ SETTINGS_KEY+':shares' ]);
73977305
} catch(e) { }
73987306
}
73997307
if (this.connected) {
@@ -7431,40 +7339,23 @@ Math.uuid = function (len, radix) {
74317339
// Same for this.token. If only one of these two is set, we leave the other one at its existing value:
74327340
if (typeof settings.token !== 'undefined') { this.token = settings.token; }
74337341

7434-
var writeSettingsToCache = function() {
7435-
if (hasLocalStorage) {
7436-
localStorage.setItem(SETTINGS_KEY, JSON.stringify({
7437-
userAddress: this.userAddress,
7438-
token: this.token
7439-
}));
7440-
}
7441-
};
7442-
7443-
var handleError = function() {
7444-
this.connected = false;
7445-
if (hasLocalStorage) {
7446-
localStorage.removeItem(SETTINGS_KEY);
7447-
}
7448-
};
7449-
74507342
if (this.token) {
74517343
this.connected = true;
7452-
if (this.userAddress) {
7453-
this._emit('connected');
7454-
writeSettingsToCache.apply(this);
7455-
} else {
7344+
if ( !this.userAddress ){
74567345
this.info().then(function (info){
7457-
this.userAddress = info.email;
7346+
this.userAddress = info.display_name;
74587347
this.rs.widget.view.setUserAddress(this.userAddress);
74597348
this._emit('connected');
7460-
writeSettingsToCache.apply(this);
7461-
}.bind(this)).catch(function() {
7462-
handleError.apply(this);
7463-
this.rs._emit('error', new Error('Could not fetch user info.'));
74647349
}.bind(this));
74657350
}
74667351
} else {
7467-
handleError.apply(this);
7352+
this.connected = false;
7353+
}
7354+
if (hasLocalStorage){
7355+
localStorage[SETTINGS_KEY] = JSON.stringify({
7356+
userAddress: this.userAddress,
7357+
token: this.token
7358+
});
74687359
}
74697360
},
74707361

@@ -7762,7 +7653,7 @@ Math.uuid = function (len, radix) {
77627653
self._itemRefs[path] = response.url;
77637654

77647655
if (hasLocalStorage) {
7765-
localStorage.setItem(SETTINGS_KEY+':shares', JSON.stringify(self._itemRefs));
7656+
localStorage[SETTINGS_KEY + ':shares'] = JSON.stringify(self._itemRefs);
77667657
}
77677658

77687659
return Promise.resolve(url);
@@ -8154,6 +8045,7 @@ Math.uuid = function (len, radix) {
81548045
}
81558046

81568047
RS.Dropbox._rs_init = function (rs) {
8048+
hasLocalStorage = RemoteStorage.util.localStorageAvailable();
81578049
if ( rs.apiKeys.dropbox ) {
81588050
rs.dropbox = new RS.Dropbox(rs);
81598051
}
@@ -8169,7 +8061,7 @@ Math.uuid = function (len, radix) {
81698061
RS.Dropbox._rs_cleanup = function (rs) {
81708062
unHookIt(rs);
81718063
if (hasLocalStorage){
8172-
localStorage.removeItem(SETTINGS_KEY);
8064+
delete localStorage[SETTINGS_KEY];
81738065
}
81748066
rs.removeEventListener('error', onErrorCb);
81758067
rs.setBackend(undefined);

0 commit comments

Comments
 (0)