fix-admintests
webzwo0i 2023-07-30 01:25:43 +02:00
parent ad15aaeca4
commit d5455bcc69
2 changed files with 28 additions and 1 deletions

View File

@ -39,10 +39,12 @@ exports.expressCreateServer = (hookName, args, cb) => {
exports.socketio = (hookName, args, cb) => { exports.socketio = (hookName, args, cb) => {
const io = args.io.of('/pluginfw/installer'); const io = args.io.of('/pluginfw/installer');
io.on('connection', (socket) => { io.on('connection', (socket) => {
console.log('event connection', new Date())
const {session: {user: {is_admin: isAdmin} = {}} = {}} = socket.conn.request; const {session: {user: {is_admin: isAdmin} = {}} = {}} = socket.conn.request;
if (!isAdmin) return; if (!isAdmin) return;
socket.on('getInstalled', (query) => { socket.on('getInstalled', (query) => {
console.log('message getInstalled', new Date())
// send currently installed plugins // send currently installed plugins
const installed = const installed =
Object.keys(pluginDefs.plugins).map((plugin) => pluginDefs.plugins[plugin].package); Object.keys(pluginDefs.plugins).map((plugin) => pluginDefs.plugins[plugin].package);
@ -51,6 +53,7 @@ exports.socketio = (hookName, args, cb) => {
}); });
socket.on('checkUpdates', async () => { socket.on('checkUpdates', async () => {
console.log('message checkUpdates', new Date())
// Check plugins for updates // Check plugins for updates
try { try {
const results = await installer.getAvailablePlugins(/* maxCacheAge:*/ 60 * 10); const results = await installer.getAvailablePlugins(/* maxCacheAge:*/ 60 * 10);
@ -64,25 +67,31 @@ exports.socketio = (hookName, args, cb) => {
return semver.gt(latestVersion, currentVersion); return semver.gt(latestVersion, currentVersion);
}).map((plugin) => ({name: plugin, version: results[plugin].version})); }).map((plugin) => ({name: plugin, version: results[plugin].version}));
console.log('emit results:updatable', new Date())
socket.emit('results:updatable', {updatable}); socket.emit('results:updatable', {updatable});
} catch (err) { } catch (err) {
console.warn(err.stack || err.toString()); console.warn(err.stack || err.toString());
console.log('emit results:updatable', new Date())
socket.emit('results:updatable', {updatable: {}}); socket.emit('results:updatable', {updatable: {}});
} }
}); });
socket.on('getAvailable', async (query) => { socket.on('getAvailable', async (query) => {
console.log('message getAvailable', new Date())
try { try {
const results = await installer.getAvailablePlugins(/* maxCacheAge:*/ false); const results = await installer.getAvailablePlugins(/* maxCacheAge:*/ false);
console.log('emit results:available', new Date())
socket.emit('results:available', results); socket.emit('results:available', results);
} catch (er) { } catch (er) {
console.error(er); console.error(er);
console.log('emit results:available', new Date())
socket.emit('results:available', {}); socket.emit('results:available', {});
} }
}); });
socket.on('search', async (query) => { socket.on('search', async (query) => {
console.log('message search', new Date())
try { try {
const results = await installer.search(query.searchTerm, /* maxCacheAge:*/ 60 * 10); const results = await installer.search(query.searchTerm, /* maxCacheAge:*/ 60 * 10);
let res = Object.keys(results) let res = Object.keys(results)
@ -90,18 +99,22 @@ exports.socketio = (hookName, args, cb) => {
.filter((plugin) => !pluginDefs.plugins[plugin.name]); .filter((plugin) => !pluginDefs.plugins[plugin.name]);
res = sortPluginList(res, query.sortBy, query.sortDir) res = sortPluginList(res, query.sortBy, query.sortDir)
.slice(query.offset, query.offset + query.limit); .slice(query.offset, query.offset + query.limit);
console.log('emit results:search', new Date())
socket.emit('results:search', {results: res, query}); socket.emit('results:search', {results: res, query});
} catch (er) { } catch (er) {
console.error(er); console.error(er);
console.log('emit results:search', new Date())
socket.emit('results:search', {results: {}, query}); socket.emit('results:search', {results: {}, query});
} }
}); });
socket.on('install', (pluginName, version) => { socket.on('install', (pluginName, version) => {
console.log('message install', new Date())
installer.install(pluginName, version, (err) => { installer.install(pluginName, version, (err) => {
if (err) console.warn(err.stack || err.toString()); if (err) console.warn(err.stack || err.toString());
console.log('emit finished:install', new Date())
socket.emit('finished:install', { socket.emit('finished:install', {
plugin: pluginName, plugin: pluginName,
code: err ? err.code : null, code: err ? err.code : null,
@ -111,9 +124,11 @@ exports.socketio = (hookName, args, cb) => {
}); });
socket.on('uninstall', (pluginName) => { socket.on('uninstall', (pluginName) => {
console.log('message uninstall', new Date())
installer.uninstall(pluginName, (err) => { installer.uninstall(pluginName, (err) => {
if (err) console.warn(err.stack || err.toString()); 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}); socket.emit('finished:uninstall', {plugin: pluginName, error: err ? err.message : null});
}); });
}); });

View File

@ -5,6 +5,7 @@
$(document).ready(() => { $(document).ready(() => {
const socket = socketio.connect('..', '/pluginfw/installer'); const socket = socketio.connect('..', '/pluginfw/installer');
socket.on('disconnect', (reason) => { 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 // The socket.io client will automatically try to reconnect for all reasons other than "io
// server disconnect". // server disconnect".
if (reason === 'io server disconnect') socket.connect(); if (reason === 'io server disconnect') socket.connect();
@ -133,6 +134,7 @@ $(document).ready(() => {
} else { } else {
installed.progress.show(plugin, 'Updating'); installed.progress.show(plugin, 'Updating');
} }
window.console.log('before emit install', new Date())
socket.emit('install', plugin, version); socket.emit('install', plugin, version);
installed.messages.hide('nothing-installed'); installed.messages.hide('nothing-installed');
}); });
@ -141,6 +143,7 @@ $(document).ready(() => {
$('.do-uninstall').unbind('click').click((e) => { $('.do-uninstall').unbind('click').click((e) => {
const $row = $(e.target).closest('tr'); const $row = $(e.target).closest('tr');
const pluginName = $row.data('plugin'); const pluginName = $row.data('plugin');
window.console.log('before emit uninstall', new Date())
socket.emit('uninstall', pluginName); socket.emit('uninstall', pluginName);
installed.progress.show(pluginName, 'Uninstalling'); installed.progress.show(pluginName, 'Uninstalling');
installed.list = installed.list.filter((plugin) => plugin.name !== pluginName); installed.list = installed.list.filter((plugin) => plugin.name !== pluginName);
@ -170,7 +173,7 @@ $(document).ready(() => {
search.messages.hide('fetching'); search.messages.hide('fetching');
$('#search-query').removeAttr('disabled'); $('#search-query').removeAttr('disabled');
console.log('got search results', data); window.console.log('got search results', data);
// add to results // add to results
search.results = search.results.concat(data.results); search.results = search.results.concat(data.results);
@ -198,6 +201,7 @@ $(document).ready(() => {
}); });
socket.on('results:installed', (data) => { socket.on('results:installed', (data) => {
window.console.log('socket results:installed', new Date());
installed.messages.hide('fetching'); installed.messages.hide('fetching');
installed.messages.hide('nothing-installed'); installed.messages.hide('nothing-installed');
@ -214,6 +218,7 @@ $(document).ready(() => {
if (installed.list.length > 0) { if (installed.list.length > 0) {
displayPluginList(installed.list, $('#installed-plugins'), $('#installed-plugin-template')); displayPluginList(installed.list, $('#installed-plugins'), $('#installed-plugin-template'));
window.console.log('before emit checkUpdates', new Date())
socket.emit('checkUpdates'); socket.emit('checkUpdates');
} else { } else {
installed.messages.show('nothing-installed'); installed.messages.show('nothing-installed');
@ -221,6 +226,7 @@ $(document).ready(() => {
}); });
socket.on('results:updatable', (data) => { socket.on('results:updatable', (data) => {
window.console.log('socket results:updatable', new Date());
data.updatable.forEach((plugin) => { data.updatable.forEach((plugin) => {
const {name, version} = plugin; const {name, version} = plugin;
const actions = $(`#installed-plugins > tr.${name} .actions`); const actions = $(`#installed-plugins > tr.${name} .actions`);
@ -233,6 +239,7 @@ $(document).ready(() => {
}); });
socket.on('finished:install', (data) => { socket.on('finished:install', (data) => {
window.console.log('socket finished:install', new Date());
if (data.error) { if (data.error) {
if (data.code === 'EPEERINVALID') { if (data.code === 'EPEERINVALID') {
alert("This plugin requires that you update Etherpad so it can operate in it's true glory"); alert("This plugin requires that you update Etherpad so it can operate in it's true glory");
@ -241,6 +248,7 @@ $(document).ready(() => {
$(`#installed-plugins .${data.plugin}`).remove(); $(`#installed-plugins .${data.plugin}`).remove();
} }
window.console.log('before emit getInstalled', new Date())
socket.emit('getInstalled'); socket.emit('getInstalled');
// update search results // update search results
@ -250,6 +258,7 @@ $(document).ready(() => {
}); });
socket.on('finished:uninstall', (data) => { socket.on('finished:uninstall', (data) => {
window.console.log('socket finished:uninstall', new Date());
if (data.error) { if (data.error) {
alert(`An error occurred while uninstalling the ${data.plugin} \n${data.error}`); alert(`An error occurred while uninstalling the ${data.plugin} \n${data.error}`);
} }
@ -257,6 +266,7 @@ $(document).ready(() => {
// remove plugin from installed list // remove plugin from installed list
$(`#installed-plugins .${data.plugin}`).remove(); $(`#installed-plugins .${data.plugin}`).remove();
window.console.log('before emit getInstalled', new Date())
socket.emit('getInstalled'); socket.emit('getInstalled');
// update search results // update search results
@ -266,7 +276,9 @@ $(document).ready(() => {
}); });
socket.on('connect', () => { socket.on('connect', () => {
window.console.log('socket connect', new Date());
updateHandlers(); updateHandlers();
window.console.log('before emit getInstalled', new Date())
socket.emit('getInstalled'); socket.emit('getInstalled');
search.searchTerm = null; search.searchTerm = null;
search($('#search-query').val()); search($('#search-query').val());