From 77a81cd0fcabdec0c33b28f02b5024e77cf06ad8 Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Tue, 8 Apr 2025 18:54:46 +0200 Subject: [PATCH] fix: simplified code in wrapped promise --- src/node/hooks/express/adminplugins.ts | 11 ++++++++-- src/package.json | 1 - src/static/js/pluginfw/installer.ts | 30 +++++++++++--------------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/node/hooks/express/adminplugins.ts b/src/node/hooks/express/adminplugins.ts index 4dcb8a0ab..178e6187f 100644 --- a/src/node/hooks/express/adminplugins.ts +++ b/src/node/hooks/express/adminplugins.ts @@ -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'); @@ -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 + 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; diff --git a/src/package.json b/src/package.json index 80282ee43..0bf800724 100644 --- a/src/package.json +++ b/src/package.json @@ -44,7 +44,6 @@ "find-root": "1.1.0", "formidable": "^3.5.2", "http-errors": "^2.0.0", - "https-proxy-agent": "^7.0.6", "jose": "^5.10.0", "js-cookie": "^3.0.5", "jsdom": "^26.0.0", diff --git a/src/static/js/pluginfw/installer.ts b/src/static/js/pluginfw/installer.ts index 3382d3161..98590e9e5 100644 --- a/src/static/js/pluginfw/installer.ts +++ b/src/static/js/pluginfw/installer.ts @@ -162,25 +162,18 @@ export const install = async (pluginName: string, cb:Function|null = null) => { export let availablePlugins:MapArrayType|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>(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>) => { - availablePlugins = pluginsLoaded.data; - cacheTimestamp = nowTimestamp; - resolve(availablePlugins); - }) - .catch(async (err) => { - logger.error(`Error fetching available plugins: ${err}`); - }); - }); + const pluginsLoaded: AxiosResponse> = await axios.get(`${settings.updateServer}/plugins.json`, {headers}) + availablePlugins = pluginsLoaded.data; + cacheTimestamp = nowTimestamp; + return availablePlugins; }; @@ -213,4 +206,7 @@ export const search = (searchTerm: string, maxCacheAge: number) => getAvailableP return res; } -); +).catch((err)=>{ + logger.error(`Error searching plugins: ${err}`); + return {} as MapArrayType; +});