Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/node/hooks/express/adminplugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {ErrorCaused} from "../../types/ErrorCaused";
import {QueryType} from "../../types/QueryType";

import {getAvailablePlugins, install, search, uninstall} from "../../../static/js/pluginfw/installer";
import {PackageData} from "../../types/PackageInfo";
import {PackageData, PackageInfo} from "../../types/PackageInfo";
import semver from 'semver';
import log4js from 'log4js';
import {MapArrayType} from "../../types/MapType";

const pluginDefs = require('../../../static/js/pluginfw/plugin_defs');
const logger = log4js.getLogger('adminPlugins');
Expand All @@ -21,7 +22,13 @@ exports.socketio = (hookName:string, args:ArgsExpressType, cb:Function) => {
if (!isAdmin) return;

const checkPluginForUpdates = async () => {
const results = await getAvailablePlugins(/* maxCacheAge:*/ 60 * 10);
let results: MapArrayType<PackageInfo>
try {
results = await getAvailablePlugins(/* maxCacheAge:*/ 60 * 10);
} catch (error) {
console.error('Error checking for plugin updates:', error);
return [];
}
return Object.keys(pluginDefs.plugins).filter((plugin) => {
if (!results[plugin]) return false;

Expand Down
4 changes: 4 additions & 0 deletions src/node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ if (settings.dumpOnUncleanExit) {
const addProxyToAxios = (url: URL) => {
axios.defaults.proxy = {
host: url.hostname,
auth: {
username: url.username,
password: url.password,
},
port: Number(url.port),
protocol: url.protocol,
}
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"jsdom": "^26.0.0",
"jsonminify": "0.4.2",
"jsonwebtoken": "^9.0.2",
"jwt-decode": "^4.0.0",
"languages4translatewiki": "0.1.3",
"live-plugin-manager": "^1.0.0",
"lodash.clonedeep": "4.5.0",
Expand All @@ -70,7 +71,6 @@
"socket.io-client": "^4.8.1",
"superagent": "10.2.0",
"swagger-ui-express": "^5.0.1",
"jwt-decode": "^4.0.0",
"tinycon": "0.6.8",
"tsx": "4.19.3",
"ueberdb2": "^5.0.6",
Expand Down
28 changes: 13 additions & 15 deletions src/static/js/pluginfw/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,18 @@ export const install = async (pluginName: string, cb:Function|null = null) => {
export let availablePlugins:MapArrayType<PackageInfo>|null = null;
let cacheTimestamp = 0;

export const getAvailablePlugins = (maxCacheAge: number|false) => {
export const getAvailablePlugins = async (maxCacheAge: number | false) => {
const nowTimestamp = Math.round(Date.now() / 1000);

return new Promise<MapArrayType<PackageInfo>>(async (resolve, reject) => {
// check cache age before making any request
if (availablePlugins && maxCacheAge && (nowTimestamp - cacheTimestamp) <= maxCacheAge) {
return resolve(availablePlugins);
}
// check cache age before making any request
if (availablePlugins && maxCacheAge && (nowTimestamp - cacheTimestamp) <= maxCacheAge) {
return availablePlugins;
}

await axios.get(`${settings.updateServer}/plugins.json`, {headers})
.then((pluginsLoaded:AxiosResponse<MapArrayType<PackageInfo>>) => {
availablePlugins = pluginsLoaded.data;
cacheTimestamp = nowTimestamp;
resolve(availablePlugins);
})
.catch(async (err) => reject(err));
});
const pluginsLoaded: AxiosResponse<MapArrayType<PackageInfo>> = await axios.get(`${settings.updateServer}/plugins.json`, {headers})
availablePlugins = pluginsLoaded.data;
cacheTimestamp = nowTimestamp;
return availablePlugins;
};


Expand Down Expand Up @@ -211,4 +206,7 @@ export const search = (searchTerm: string, maxCacheAge: number) => getAvailableP

return res;
}
);
).catch((err)=>{
logger.error(`Error searching plugins: ${err}`);
return {} as MapArrayType<PackageInfo>;
});
Loading