@@ -39,8 +39,43 @@ export const load: PageServerLoad = async ({ params, platform, request, cookies
3939 console . error ( 'Failed to parse config JSON' , e ) ;
4040 }
4141
42+ const pkgs : { name : string ; type : string ; desc ?: string } [ ] = Array . isArray ( config . packages )
43+ ? config . packages . map ( ( p : any ) => typeof p === 'string' ? { name : p , type : 'formula' } : p )
44+ : [ ] ;
45+
46+ const missing = pkgs . filter ( p => ! p . desc ) ;
47+ if ( missing . length > 0 ) {
48+ const descResults = await Promise . allSettled (
49+ missing . map ( async ( p ) => {
50+ try {
51+ if ( p . type === 'npm' ) {
52+ const r = await fetch ( `https://registry.npmjs.org/${ p . name } ` , { cf : { cacheTtl : 86400 , cacheEverything : true } } as RequestInit ) ;
53+ if ( r . ok ) { const d = await r . json ( ) as any ; return { name : p . name , desc : d . description || '' } ; }
54+ } else {
55+ const kind = p . type === 'cask' ? 'cask' : 'formula' ;
56+ const r = await fetch ( `https://formulae.brew.sh/api/${ kind } /${ p . name } .json` , { cf : { cacheTtl : 86400 , cacheEverything : true } } as RequestInit ) ;
57+ if ( r . ok ) { const d = await r . json ( ) as any ; return { name : p . name , desc : d . desc || '' } ; }
58+ }
59+ } catch { }
60+ return { name : p . name , desc : '' } ;
61+ } )
62+ ) ;
63+ for ( const r of descResults ) {
64+ if ( r . status === 'fulfilled' && r . value . desc ) {
65+ const pkg = pkgs . find ( p => p . name === r . value . name ) ;
66+ if ( pkg ) pkg . desc = r . value . desc ;
67+ }
68+ }
69+ }
70+
71+ const packageDescriptions : Record < string , string > = { } ;
72+ for ( const p of pkgs ) {
73+ if ( p . desc ) packageDescriptions [ p . name ] = p . desc ;
74+ }
75+
4276 return {
4377 configUser : targetUser ,
44- config
78+ config,
79+ packageDescriptions
4580 } ;
4681} ;
0 commit comments