This commit is contained in:
wltsmrz
2014-05-29 06:46:54 -07:00
parent c3568de8b3
commit 61bc01ae12
4 changed files with 37 additions and 32 deletions

View File

@@ -2,7 +2,7 @@ var request = require('superagent');
var RippleTxt = require('./rippletxt').RippleTxt;
function AuthInfo() {
this.rippleTxt = new RippleTxt;
this.rippleTxt = new RippleTxt();
};
/**
@@ -30,9 +30,10 @@ AuthInfo.prototype.get = function(domain, username, fn) {
}
var url = Array.isArray(txt.authinfo_url) ? txt.authinfo_url[0] : txt.authinfo_url;
url += '?domain='+domain+'&username='+username;
request.get(url, function(err, resp){
url += '?domain=' + domain + '&username='+username;
request.get(url, function(err, resp) {
if (err || resp.error) {
fn(new Error('Authentication info server unreachable'));
} else {

View File

@@ -132,11 +132,11 @@ BlobObj.prototype.consolidate = function(fn) {
BlobObj.prototype.applyEncryptedPatch = function(patch) {
try {
var params = JSON.parse(crypt.decrypt(this.key, patch));
var op = params.shift();
var path = params.shift();
var args = JSON.parse(crypt.decrypt(this.key, patch));
var op = args.shift();
var path = args.shift();
this.applyUpdate(op, path, params);
this.applyUpdate(op, path, args);
this.revision++;
return true;
@@ -266,19 +266,21 @@ BlobObj.prototype.unshift = function(pointer, value, fn) {
*
* The subcommands can be any commands with the pointer parameter left out.
*/
BlobObj.prototype.filter = function(pointer, field, value, subcommands, callback) {
var params = Array.prototype.slice.apply(arguments);
if (typeof params[params.length - 1] === 'function') {
callback = params.pop();
var args = Array.prototype.slice.apply(arguments);
if (typeof args[args.length - 1] === 'function') {
callback = args.pop();
}
params.shift();
args.shift();
// Normalize subcommands to minimize the patch size
params = params.slice(0, 2).concat(normalizeSubcommands(params.slice(2), true));
args = args.slice(0, 2).concat(normalizeSubcommands(args.slice(2), true));
this.applyUpdate('filter', pointer, params);
this.postUpdate('filter', pointer, params, callback);
this.applyUpdate('filter', pointer, args);
this.postUpdate('filter', pointer, args, callback);
};
/**
@@ -457,7 +459,7 @@ function normalizeSubcommands(subcommands, compress) {
if (/(number|string)/.test(typeof subcommands[0])) {
// Case 1: Single subcommand inline
subcommands = [subcommands];
} else if (subcommands.length === 1 && Array.isArray(subcommands[0]) && /(number|string)/.test(subcommands[0][0])) {
} else if (subcommands.length === 1 && Array.isArray(subcommands[0]) && /(number|string)/.test(typeof subcommands[0][0])) {
// Case 2: Single subcommand as array
// (nothing to do)
} else if (Array.isArray(subcommands[0])) {

View File

@@ -4,6 +4,15 @@ function RippleTxt() {
this.txts = { };
};
RippleTxt.urlTemplates = [
'https://ripple.{{domain}}/ripple.txt',
'https://www.{{domain}}/ripple.txt',
'https://{{domain}}/ripple.txt',
'http://ripple.{{domain}}/ripple.txt',
'http://www.{{domain}}/ripple.txt',
'http://{{domain}}/ripple.txt'
];
/**
* Gets the ripple.txt file for the given domain
*
@@ -11,32 +20,25 @@ function RippleTxt() {
* @param {function} fn - Callback function
*/
RippleTxt.prototype.get = function (domain, fn) {
RippleTxt.prototype.get = function(domain, fn) {
var self = this;
if (self.txts[domain]) {
return fn(null, self.txts[domain]);
}
var urls = [
'https://ripple.'+domain+'/ripple.txt',
'https://www.'+domain+'/ripple.txt',
'https://'+domain+'/ripple.txt',
'http://ripple.'+domain+'/ripple.txt',
'http://www.'+domain+'/ripple.txt',
'http://'+domain+'/ripple.txt'
];
;(function nextUrl() {
var url = urls.shift();
;(function nextUrl(i) {
var url = RippleTxt.urlTemplates[i];
if (!url) {
return fn(new Error('No ripple.txt found'));
}
url = url.replace('{{domain}}', domain);
request.get(url, function(err, resp) {
if (err || !resp.text) {
return nextUrl();
return nextUrl(++i);
}
var sections = self.parse(resp.text);
@@ -44,7 +46,7 @@ RippleTxt.prototype.get = function (domain, fn) {
fn(null, sections);
});
})();
})(0);
};
/**
@@ -53,7 +55,7 @@ RippleTxt.prototype.get = function (domain, fn) {
* @param {string} txt - Unparsed ripple.txt data
*/
RippleTxt.prototype.parse = function (txt) {
RippleTxt.prototype.parse = function(txt) {
var txt = txt.replace(/\r?\n/g, '\n').split('\n')
var currentSection = '';
var sections = { };
@@ -66,7 +68,7 @@ RippleTxt.prototype.parse = function (txt) {
}
if (line[0] === '[' && line[line.length-1] === ']') {
currentSection = line.slice(1, line.length-1);
currentSection = line.slice(1, line.length - 1);
sections[currentSection] = [];
} else {
line = line.replace(/^\s+|\s+$/g, '');

View File

@@ -5,7 +5,7 @@ var crypt = require('./crypt').Crypt;
function VaultClient(opts) {
if (!opts) {
opts = {};
opts = { };
}
if (typeof opts === 'string') {