Chargement des profils distant via HTTP
This commit is contained in:
@@ -3,14 +3,47 @@ var cp = require('child_process');
|
||||
var glob = require('glob');
|
||||
var ini = require('ini');
|
||||
var Cache = require('./cache');
|
||||
var request = require('request');
|
||||
|
||||
var HTTP_REGEX = /^https?:\/\//i;
|
||||
/**
|
||||
* Load a JSON file
|
||||
* Load a JSON file (http or local)
|
||||
*
|
||||
* @param filePath The path of the json file
|
||||
* @return Promise
|
||||
*/
|
||||
exports.loadJSON = function(filePath) {
|
||||
exports.loadJSON = function(jsonUrl) {
|
||||
if( HTTP_REGEX.test(jsonUrl) ) {
|
||||
return exports.fetchRemoteJSON(jsonUrl);
|
||||
} else {
|
||||
return exports.loadLocalJSON(jsonUrl);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Load a remote JSON file via http
|
||||
*
|
||||
* @param filePath The path of the json file
|
||||
* @return Promise
|
||||
*/
|
||||
exports.fetchRemoteJSON = function(fileUrl) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
request(fileUrl, { followRedirect: true, json: true }, function (err, res, body) {
|
||||
if(err) return reject(err);
|
||||
console.log(body);
|
||||
return resolve(body);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Load a local JSON file
|
||||
*
|
||||
* @param filePath The path of the json file
|
||||
* @return Promise
|
||||
*/
|
||||
exports.loadLocalJSON = function(filePath) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
fs.readFile(filePath, 'utf8', function(err, fileContent) {
|
||||
if(err) return reject(err);
|
||||
|
Reference in New Issue
Block a user