mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-27 07:35:52 +00:00
Cleanup
This commit is contained in:
@@ -2,7 +2,7 @@ var request = require('superagent');
|
|||||||
var RippleTxt = require('./rippletxt').RippleTxt;
|
var RippleTxt = require('./rippletxt').RippleTxt;
|
||||||
|
|
||||||
function AuthInfo() {
|
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;
|
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) {
|
if (err || resp.error) {
|
||||||
fn(new Error('Authentication info server unreachable'));
|
fn(new Error('Authentication info server unreachable'));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -132,11 +132,11 @@ BlobObj.prototype.consolidate = function(fn) {
|
|||||||
|
|
||||||
BlobObj.prototype.applyEncryptedPatch = function(patch) {
|
BlobObj.prototype.applyEncryptedPatch = function(patch) {
|
||||||
try {
|
try {
|
||||||
var params = JSON.parse(crypt.decrypt(this.key, patch));
|
var args = JSON.parse(crypt.decrypt(this.key, patch));
|
||||||
var op = params.shift();
|
var op = args.shift();
|
||||||
var path = params.shift();
|
var path = args.shift();
|
||||||
|
|
||||||
this.applyUpdate(op, path, params);
|
this.applyUpdate(op, path, args);
|
||||||
this.revision++;
|
this.revision++;
|
||||||
|
|
||||||
return true;
|
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.
|
* The subcommands can be any commands with the pointer parameter left out.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
BlobObj.prototype.filter = function(pointer, field, value, subcommands, callback) {
|
BlobObj.prototype.filter = function(pointer, field, value, subcommands, callback) {
|
||||||
var params = Array.prototype.slice.apply(arguments);
|
var args = Array.prototype.slice.apply(arguments);
|
||||||
if (typeof params[params.length - 1] === 'function') {
|
|
||||||
callback = params.pop();
|
if (typeof args[args.length - 1] === 'function') {
|
||||||
|
callback = args.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
params.shift();
|
args.shift();
|
||||||
|
|
||||||
// Normalize subcommands to minimize the patch size
|
// 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.applyUpdate('filter', pointer, args);
|
||||||
this.postUpdate('filter', pointer, params, callback);
|
this.postUpdate('filter', pointer, args, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -457,7 +459,7 @@ function normalizeSubcommands(subcommands, compress) {
|
|||||||
if (/(number|string)/.test(typeof subcommands[0])) {
|
if (/(number|string)/.test(typeof subcommands[0])) {
|
||||||
// Case 1: Single subcommand inline
|
// Case 1: Single subcommand inline
|
||||||
subcommands = [subcommands];
|
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
|
// Case 2: Single subcommand as array
|
||||||
// (nothing to do)
|
// (nothing to do)
|
||||||
} else if (Array.isArray(subcommands[0])) {
|
} else if (Array.isArray(subcommands[0])) {
|
||||||
|
|||||||
@@ -4,6 +4,15 @@ function RippleTxt() {
|
|||||||
this.txts = { };
|
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
|
* Gets the ripple.txt file for the given domain
|
||||||
*
|
*
|
||||||
@@ -11,32 +20,25 @@ function RippleTxt() {
|
|||||||
* @param {function} fn - Callback function
|
* @param {function} fn - Callback function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
RippleTxt.prototype.get = function (domain, fn) {
|
RippleTxt.prototype.get = function(domain, fn) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (self.txts[domain]) {
|
if (self.txts[domain]) {
|
||||||
return fn(null, self.txts[domain]);
|
return fn(null, self.txts[domain]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var urls = [
|
;(function nextUrl(i) {
|
||||||
'https://ripple.'+domain+'/ripple.txt',
|
var url = RippleTxt.urlTemplates[i];
|
||||||
'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();
|
|
||||||
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return fn(new Error('No ripple.txt found'));
|
return fn(new Error('No ripple.txt found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
url = url.replace('{{domain}}', domain);
|
||||||
|
|
||||||
request.get(url, function(err, resp) {
|
request.get(url, function(err, resp) {
|
||||||
if (err || !resp.text) {
|
if (err || !resp.text) {
|
||||||
return nextUrl();
|
return nextUrl(++i);
|
||||||
}
|
}
|
||||||
|
|
||||||
var sections = self.parse(resp.text);
|
var sections = self.parse(resp.text);
|
||||||
@@ -44,7 +46,7 @@ RippleTxt.prototype.get = function (domain, fn) {
|
|||||||
|
|
||||||
fn(null, sections);
|
fn(null, sections);
|
||||||
});
|
});
|
||||||
})();
|
})(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,7 +55,7 @@ RippleTxt.prototype.get = function (domain, fn) {
|
|||||||
* @param {string} txt - Unparsed ripple.txt data
|
* @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 txt = txt.replace(/\r?\n/g, '\n').split('\n')
|
||||||
var currentSection = '';
|
var currentSection = '';
|
||||||
var sections = { };
|
var sections = { };
|
||||||
@@ -66,7 +68,7 @@ RippleTxt.prototype.parse = function (txt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (line[0] === '[' && line[line.length-1] === ']') {
|
if (line[0] === '[' && line[line.length-1] === ']') {
|
||||||
currentSection = line.slice(1, line.length-1);
|
currentSection = line.slice(1, line.length - 1);
|
||||||
sections[currentSection] = [];
|
sections[currentSection] = [];
|
||||||
} else {
|
} else {
|
||||||
line = line.replace(/^\s+|\s+$/g, '');
|
line = line.replace(/^\s+|\s+$/g, '');
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ var crypt = require('./crypt').Crypt;
|
|||||||
|
|
||||||
function VaultClient(opts) {
|
function VaultClient(opts) {
|
||||||
if (!opts) {
|
if (!opts) {
|
||||||
opts = {};
|
opts = { };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof opts === 'string') {
|
if (typeof opts === 'string') {
|
||||||
|
|||||||
Reference in New Issue
Block a user