Merge pull request #2294 from ether/go-away-npm

Use request and a remote ep plugin only endpoint
This commit is contained in:
John McLear 2014-11-15 15:37:44 +00:00
commit 12914e68ff
1 changed files with 6 additions and 7 deletions

View File

@ -1,6 +1,7 @@
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
var npm = require("npm");
var request = require("request");
var npmIsLoaded = false;
var withNpm = function (npmfn) {
@ -60,17 +61,15 @@ exports.availablePlugins = null;
var cacheTimestamp = 0;
exports.getAvailablePlugins = function(maxCacheAge, cb) {
withNpm(function (er) {
request("http://etherpad.org/plugins.json", function(er, response, plugins){
if (er) return cb && cb(er);
if(exports.availablePlugins && maxCacheAge && Math.round(+new Date/1000)-cacheTimestamp <= maxCacheAge) {
return cb && cb(null, exports.availablePlugins)
}
npm.commands.search(['ep_'], /*silent?*/true, function(er, results) {
if(er) return cb && cb(er);
exports.availablePlugins = results;
cacheTimestamp = Math.round(+new Date/1000);
cb && cb(null, results)
})
plugins = JSON.parse(plugins);
exports.availablePlugins = plugins;
cacheTimestamp = Math.round(+new Date/1000);
cb && cb(null, plugins)
});
};