@@ -162,25 +162,18 @@ export const install = async (pluginName: string, cb:Function|null = null) => {
162162export let availablePlugins :MapArrayType < PackageInfo > | null = null ;
163163let 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