summaryrefslogtreecommitdiff
path: root/src/node/hooks/express/adminplugins.js
blob: fa7e7077124ed113b61d4b56f47c904832cb30ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var path = require('path');
var eejs = require('ep_etherpad-lite/node/eejs');
var installer = require('ep_etherpad-lite/static/js/pluginfw/installer');
var plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');

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: [],
    };

    res.send(eejs.require(
      "ep_etherpad-lite/templates/admin/plugins.html",
      render_args), {});
  });
}

exports.socketio = function (hook_name, args, cb) {
  var io = args.io.of("/pluginfw/installer");
  io.on('connection', function (socket) {
    socket.on("load", function (query) {
      socket.emit("installed-results", {results: plugins.plugins});
    });

    socket.on("search", function (query) {
      socket.emit("progress", {progress:0, message:'Fetching results...'});
      installer.search(query, function (progress) {
        if (progress.results)
          socket.emit("search-result", progress);
        socket.emit("progress", progress);
      });
    });

    socket.on("install", function (plugin_name) {
      socket.emit("progress", {progress:0, message:'Downloading and installing ' + plugin_name + "..."});
      installer.install(plugin_name, function (progress) {
        socket.emit("progress", progress);
      });
    });

    socket.on("uninstall", function (plugin_name) {
      socket.emit("progress", {progress:0, message:'Uninstalling ' + plugin_name + "..."});
      installer.uninstall(plugin_name, function (progress) {
        socket.emit("progress", progress);
      });
    });
  });
}