Added plugin live view.

This commit is contained in:
SamTV12345 2023-10-08 21:56:40 +02:00
parent 6a2ffe6aaf
commit 71a29884d6
4 changed files with 19 additions and 13 deletions

View file

@ -6,9 +6,12 @@ const hooks = require('./hooks');
const runCmd = require('../../../node/utils/run_cmd');
const settings = require('../../../node/utils/Settings');
const axios = require('axios');
const {PluginManager} = require('live-plugin-manager');
const logger = log4js.getLogger('plugins');
exports.manager = new PluginManager();
const onAllTasksFinished = async () => {
settings.reloadSettings();
await hooks.aCallAll('loadSettings', {settings});
@ -76,22 +79,21 @@ exports.getAvailablePlugins = (maxCacheAge) => {
const nowTimestamp = Math.round(Date.now() / 1000);
return new Promise(async (resolve, reject) => {
// check cache age before making any request
if (exports.availablePlugins && maxCacheAge && (nowTimestamp - cacheTimestamp) <= maxCacheAge) {
return resolve(exports.availablePlugins);
}
// check cache age before making any request
if (exports.availablePlugins && maxCacheAge && (nowTimestamp - cacheTimestamp) <= maxCacheAge) {
return resolve(exports.availablePlugins);
}
await axios.get('https://static.etherpad.org/plugins.json', {headers: headers})
.then(pluginsLoaded => {
exports.availablePlugins = pluginsLoaded.data;
cacheTimestamp = nowTimestamp;
resolve(exports.availablePlugins);
})
await axios.get('https://static.etherpad.org/plugins.json', {headers: headers})
.then((pluginsLoaded) => {
exports.availablePlugins = pluginsLoaded.data;
cacheTimestamp = nowTimestamp;
resolve(exports.availablePlugins);})
.catch(async err => {
return reject(err);
});
})
}
});
};
exports.search = (searchTerm, maxCacheAge) => exports.getAvailablePlugins(maxCacheAge).then(