Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
webzwo0i committed Jul 29, 2023
1 parent ad15aae commit d5455bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/node/hooks/express/adminplugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ exports.expressCreateServer = (hookName, args, cb) => {
exports.socketio = (hookName, args, cb) => {
const io = args.io.of('/pluginfw/installer');
io.on('connection', (socket) => {
console.log('event connection', new Date())
const {session: {user: {is_admin: isAdmin} = {}} = {}} = socket.conn.request;
if (!isAdmin) return;

socket.on('getInstalled', (query) => {
console.log('message getInstalled', new Date())
// send currently installed plugins
const installed =
Object.keys(pluginDefs.plugins).map((plugin) => pluginDefs.plugins[plugin].package);
Expand All @@ -51,6 +53,7 @@ exports.socketio = (hookName, args, cb) => {
});

socket.on('checkUpdates', async () => {
console.log('message checkUpdates', new Date())
// Check plugins for updates
try {
const results = await installer.getAvailablePlugins(/* maxCacheAge:*/ 60 * 10);
Expand All @@ -64,44 +67,54 @@ exports.socketio = (hookName, args, cb) => {
return semver.gt(latestVersion, currentVersion);
}).map((plugin) => ({name: plugin, version: results[plugin].version}));

console.log('emit results:updatable', new Date())
socket.emit('results:updatable', {updatable});
} catch (err) {
console.warn(err.stack || err.toString());

console.log('emit results:updatable', new Date())
socket.emit('results:updatable', {updatable: {}});
}
});

socket.on('getAvailable', async (query) => {
console.log('message getAvailable', new Date())
try {
const results = await installer.getAvailablePlugins(/* maxCacheAge:*/ false);
console.log('emit results:available', new Date())
socket.emit('results:available', results);
} catch (er) {
console.error(er);
console.log('emit results:available', new Date())
socket.emit('results:available', {});
}
});

socket.on('search', async (query) => {
console.log('message search', new Date())
try {
const results = await installer.search(query.searchTerm, /* maxCacheAge:*/ 60 * 10);
let res = Object.keys(results)
.map((pluginName) => results[pluginName])
.filter((plugin) => !pluginDefs.plugins[plugin.name]);
res = sortPluginList(res, query.sortBy, query.sortDir)
.slice(query.offset, query.offset + query.limit);
console.log('emit results:search', new Date())
socket.emit('results:search', {results: res, query});
} catch (er) {
console.error(er);

console.log('emit results:search', new Date())
socket.emit('results:search', {results: {}, query});
}
});

socket.on('install', (pluginName, version) => {
console.log('message install', new Date())
installer.install(pluginName, version, (err) => {
if (err) console.warn(err.stack || err.toString());

console.log('emit finished:install', new Date())
socket.emit('finished:install', {
plugin: pluginName,
code: err ? err.code : null,
Expand All @@ -111,9 +124,11 @@ exports.socketio = (hookName, args, cb) => {
});

socket.on('uninstall', (pluginName) => {
console.log('message uninstall', new Date())
installer.uninstall(pluginName, (err) => {
if (err) console.warn(err.stack || err.toString());

console.log('emit finished:uninstall', new Date())
socket.emit('finished:uninstall', {plugin: pluginName, error: err ? err.message : null});
});
});
Expand Down
14 changes: 13 additions & 1 deletion src/static/js/admin/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$(document).ready(() => {
const socket = socketio.connect('..', '/pluginfw/installer');
socket.on('disconnect', (reason) => {
window.console.log('socket disconnect', new Date());
// The socket.io client will automatically try to reconnect for all reasons other than "io
// server disconnect".
if (reason === 'io server disconnect') socket.connect();
Expand Down Expand Up @@ -133,6 +134,7 @@ $(document).ready(() => {
} else {
installed.progress.show(plugin, 'Updating');
}
window.console.log('before emit install', new Date())
socket.emit('install', plugin, version);
installed.messages.hide('nothing-installed');
});
Expand All @@ -141,6 +143,7 @@ $(document).ready(() => {
$('.do-uninstall').unbind('click').click((e) => {
const $row = $(e.target).closest('tr');
const pluginName = $row.data('plugin');
window.console.log('before emit uninstall', new Date())
socket.emit('uninstall', pluginName);
installed.progress.show(pluginName, 'Uninstalling');
installed.list = installed.list.filter((plugin) => plugin.name !== pluginName);
Expand Down Expand Up @@ -170,7 +173,7 @@ $(document).ready(() => {
search.messages.hide('fetching');
$('#search-query').removeAttr('disabled');

console.log('got search results', data);
window.console.log('got search results', data);

// add to results
search.results = search.results.concat(data.results);
Expand Down Expand Up @@ -198,6 +201,7 @@ $(document).ready(() => {
});

socket.on('results:installed', (data) => {
window.console.log('socket results:installed', new Date());
installed.messages.hide('fetching');
installed.messages.hide('nothing-installed');

Expand All @@ -214,13 +218,15 @@ $(document).ready(() => {

if (installed.list.length > 0) {
displayPluginList(installed.list, $('#installed-plugins'), $('#installed-plugin-template'));
window.console.log('before emit checkUpdates', new Date())
socket.emit('checkUpdates');
} else {
installed.messages.show('nothing-installed');
}
});

socket.on('results:updatable', (data) => {
window.console.log('socket results:updatable', new Date());
data.updatable.forEach((plugin) => {
const {name, version} = plugin;
const actions = $(`#installed-plugins > tr.${name} .actions`);
Expand All @@ -233,6 +239,7 @@ $(document).ready(() => {
});

socket.on('finished:install', (data) => {
window.console.log('socket finished:install', new Date());
if (data.error) {
if (data.code === 'EPEERINVALID') {
alert("This plugin requires that you update Etherpad so it can operate in it's true glory");
Expand All @@ -241,6 +248,7 @@ $(document).ready(() => {
$(`#installed-plugins .${data.plugin}`).remove();
}

window.console.log('before emit getInstalled', new Date())
socket.emit('getInstalled');

// update search results
Expand All @@ -250,13 +258,15 @@ $(document).ready(() => {
});

socket.on('finished:uninstall', (data) => {
window.console.log('socket finished:uninstall', new Date());
if (data.error) {
alert(`An error occurred while uninstalling the ${data.plugin} \n${data.error}`);
}

// remove plugin from installed list
$(`#installed-plugins .${data.plugin}`).remove();

window.console.log('before emit getInstalled', new Date())
socket.emit('getInstalled');

// update search results
Expand All @@ -266,7 +276,9 @@ $(document).ready(() => {
});

socket.on('connect', () => {
window.console.log('socket connect', new Date());
updateHandlers();
window.console.log('before emit getInstalled', new Date())
socket.emit('getInstalled');
search.searchTerm = null;
search($('#search-query').val());
Expand Down

0 comments on commit d5455bc

Please sign in to comment.