Skip to content

Commit 7fde6ee

Browse files
committed
fix: simplified code in wrapped promise
1 parent d62d5a0 commit 7fde6ee

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

src/node/hooks/express/adminplugins.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import {ErrorCaused} from "../../types/ErrorCaused";
55
import {QueryType} from "../../types/QueryType";
66

77
import {getAvailablePlugins, install, search, uninstall} from "../../../static/js/pluginfw/installer";
8-
import {PackageData} from "../../types/PackageInfo";
8+
import {PackageData, PackageInfo} from "../../types/PackageInfo";
99
import semver from 'semver';
1010
import log4js from 'log4js';
11+
import {MapArrayType} from "../../types/MapType";
1112

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

2324
const checkPluginForUpdates = async () => {
24-
const results = await getAvailablePlugins(/* maxCacheAge:*/ 60 * 10);
25+
let results: MapArrayType<PackageInfo>
26+
try {
27+
results = await getAvailablePlugins(/* maxCacheAge:*/ 60 * 10);
28+
} catch (error) {
29+
console.error('Error checking for plugin updates:', error);
30+
return [];
31+
}
2532
return Object.keys(pluginDefs.plugins).filter((plugin) => {
2633
if (!results[plugin]) return false;
2734

src/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"find-root": "1.1.0",
4545
"formidable": "^3.5.2",
4646
"http-errors": "^2.0.0",
47-
"https-proxy-agent": "^7.0.6",
4847
"jose": "^5.10.0",
4948
"js-cookie": "^3.0.5",
5049
"jsdom": "^26.0.0",

src/static/js/pluginfw/installer.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,18 @@ export const install = async (pluginName: string, cb:Function|null = null) => {
162162
export let availablePlugins:MapArrayType<PackageInfo>|null = null;
163163
let cacheTimestamp = 0;
164164

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

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

174-
await axios.get(`${settings.updateServer}/plugins.json`, {headers})
175-
.then((pluginsLoaded: AxiosResponse<MapArrayType<PackageInfo>>) => {
176-
availablePlugins = pluginsLoaded.data;
177-
cacheTimestamp = nowTimestamp;
178-
resolve(availablePlugins);
179-
})
180-
.catch(async (err) => {
181-
logger.error(`Error fetching available plugins: ${err}`);
182-
});
183-
});
173+
const pluginsLoaded: AxiosResponse<MapArrayType<PackageInfo>> = await axios.get(`${settings.updateServer}/plugins.json`, {headers})
174+
availablePlugins = pluginsLoaded.data;
175+
cacheTimestamp = nowTimestamp;
176+
return availablePlugins;
184177
};
185178

186179

@@ -213,4 +206,7 @@ export const search = (searchTerm: string, maxCacheAge: number) => getAvailableP
213206

214207
return res;
215208
}
216-
);
209+
).catch((err)=>{
210+
logger.error(`Error searching plugins: ${err}`);
211+
return {} as MapArrayType<PackageInfo>;
212+
});

0 commit comments

Comments
 (0)