2012-03-15 18:25:06 +01:00
|
|
|
var path = require('path');
|
|
|
|
var eejs = require('ep_etherpad-lite/node/eejs');
|
|
|
|
var installer = require('ep_etherpad-lite/static/js/pluginfw/installer');
|
2012-03-19 17:16:49 +01:00
|
|
|
var plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');
|
2013-01-26 22:13:28 +01:00
|
|
|
var _ = require('underscore');
|
|
|
|
var semver = require('semver');
|
|
|
|
var async = require('async');
|
2012-03-15 18:25:06 +01:00
|
|
|
|
|
|
|
exports.expressCreateServer = function (hook_name, args, cb) {
|
|
|
|
args.app.get('/admin/plugins', function(req, res) {
|
|
|
|
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
|
|
|
|
var render_args = {
|
|
|
|
plugins: plugins.plugins,
|
|
|
|
search_results: {},
|
|
|
|
errors: [],
|
|
|
|
};
|
|
|
|
|
2012-09-22 13:51:39 +02:00
|
|
|
res.send( eejs.require("ep_etherpad-lite/templates/admin/plugins.html", render_args) );
|
2012-03-15 21:07:48 +01:00
|
|
|
});
|
2012-06-04 14:33:38 +02:00
|
|
|
args.app.get('/admin/plugins/info', function(req, res) {
|
2012-09-22 13:51:39 +02:00
|
|
|
res.send( eejs.require("ep_etherpad-lite/templates/admin/plugins-info.html", {}) );
|
2012-06-04 14:33:38 +02:00
|
|
|
});
|
2012-03-15 21:07:48 +01:00
|
|
|
}
|
2012-03-15 18:25:06 +01:00
|
|
|
|
2012-03-15 21:07:48 +01:00
|
|
|
exports.socketio = function (hook_name, args, cb) {
|
|
|
|
var io = args.io.of("/pluginfw/installer");
|
|
|
|
io.on('connection', function (socket) {
|
2012-04-19 16:04:03 +02:00
|
|
|
if (!socket.handshake.session.user || !socket.handshake.session.user.is_admin) return;
|
2012-04-19 14:25:12 +02:00
|
|
|
|
2013-03-25 17:20:10 +01:00
|
|
|
socket.on("getInstalled", function (query) {
|
2013-01-26 22:13:28 +01:00
|
|
|
// send currently installed plugins
|
2013-03-25 17:20:10 +01:00
|
|
|
var installed = Object.keys(plugins.plugins).map(function(plugin) {
|
|
|
|
return plugins.plugins[plugin].package
|
|
|
|
})
|
|
|
|
socket.emit("results:installed", {installed: installed});
|
2012-03-19 17:16:49 +01:00
|
|
|
});
|
2013-01-26 22:13:28 +01:00
|
|
|
|
2013-03-25 17:20:10 +01:00
|
|
|
socket.on("getUpdatable", function() {
|
2013-01-26 22:13:28 +01:00
|
|
|
// Check plugins for updates
|
2013-03-25 17:20:10 +01:00
|
|
|
installer.getAvailable(/*maxCacheAge:*/60*10, function(er, results) {
|
|
|
|
if(er) {
|
|
|
|
console.warn(er);
|
|
|
|
socket.emit("results:updatable", {updatable: {}});
|
|
|
|
return;
|
|
|
|
}
|
2013-01-26 22:13:28 +01:00
|
|
|
var updatable = _(plugins.plugins).keys().filter(function(plugin) {
|
2013-03-25 17:20:10 +01:00
|
|
|
if(!results[plugin]) return false;
|
|
|
|
var latestVersion = results[plugin].version
|
2013-01-26 22:13:28 +01:00
|
|
|
var currentVersion = plugins.plugins[plugin].package.version
|
|
|
|
return semver.gt(latestVersion, currentVersion)
|
|
|
|
});
|
2013-03-25 17:20:10 +01:00
|
|
|
socket.emit("results:updatable", {updatable: updatable});
|
2013-01-26 22:13:28 +01:00
|
|
|
});
|
|
|
|
})
|
2013-03-25 17:20:10 +01:00
|
|
|
|
|
|
|
socket.on("getAvailable", function (query) {
|
|
|
|
installer.getAvailablePlugins(/*maxCacheAge:*/false, function (er, results) {
|
|
|
|
if(er) {
|
|
|
|
console.error(er)
|
|
|
|
results = {}
|
|
|
|
}
|
|
|
|
socket.emit("results:available", results);
|
|
|
|
});
|
|
|
|
});
|
2012-03-19 17:16:49 +01:00
|
|
|
|
2012-03-15 21:07:48 +01:00
|
|
|
socket.on("search", function (query) {
|
2013-03-25 17:20:10 +01:00
|
|
|
installer.search(query.searchTerm, /*maxCacheAge:*/60*10, function (er, results) {
|
|
|
|
if(er) {
|
|
|
|
console.error(er)
|
|
|
|
results = {}
|
|
|
|
}
|
|
|
|
var res = Object.keys(results)
|
|
|
|
.slice(query.offset, query.offset+query.length)
|
|
|
|
.map(function(pluginName) {
|
|
|
|
return results[pluginName]
|
|
|
|
});
|
|
|
|
socket.emit("results:search", {results: res, query: query});
|
2012-03-15 18:25:06 +01:00
|
|
|
});
|
2012-03-15 21:07:48 +01:00
|
|
|
});
|
|
|
|
|
2012-03-17 18:17:10 +01:00
|
|
|
socket.on("install", function (plugin_name) {
|
2013-03-25 17:20:10 +01:00
|
|
|
installer.install(plugin_name, function (er) {
|
|
|
|
socket.emit("finished:install", {error: er});
|
2012-03-17 18:17:10 +01:00
|
|
|
});
|
2012-03-15 21:07:48 +01:00
|
|
|
});
|
|
|
|
|
2012-03-17 18:17:10 +01:00
|
|
|
socket.on("uninstall", function (plugin_name) {
|
2013-03-25 17:20:10 +01:00
|
|
|
installer.uninstall(plugin_name, function (er) {
|
|
|
|
socket.emit("finished:uninstall", {error: er});
|
2012-03-17 18:17:10 +01:00
|
|
|
});
|
2012-03-15 21:07:48 +01:00
|
|
|
});
|
2012-03-15 18:25:06 +01:00
|
|
|
});
|
2012-03-15 21:07:48 +01:00
|
|
|
}
|