1+ import { uploadToS3 } from "@/data-layer/s3"
2+
13import { fetchBuidlGuidl } from "./fetchBuidlGuidl"
24import { fetchGitHub } from "./fetchGitHub"
35import { fetchNpmJs } from "./fetchNpmJs"
@@ -16,6 +18,23 @@ import {
1618// Re-export types for consumers
1719export type { DeveloperToolsDataEnvelope } from "./utils"
1820
21+ async function uploadToolImages (
22+ tools : DeveloperTool [ ]
23+ ) : Promise < DeveloperTool [ ] > {
24+ return Promise . all (
25+ tools . map ( async ( tool ) => {
26+ const thumbnail_url = tool . thumbnail_url
27+ ? ( ( await uploadToS3 ( tool . thumbnail_url , "tools/thumbnails" ) ) ?? "" )
28+ : tool . thumbnail_url
29+ const banner_url = tool . banner_url
30+ ? ( ( await uploadToS3 ( tool . banner_url , "tools/banners" ) ) ?? "" )
31+ : tool . banner_url
32+
33+ return { ...tool , thumbnail_url, banner_url }
34+ } )
35+ )
36+ }
37+
1938/**
2039 * Fetches and enriches developer tools data.
2140 *
@@ -41,18 +60,22 @@ export async function fetchDeveloperTools(): Promise<DeveloperToolsDataEnvelope>
4160 console . log ( "Enriched with GitHub data" )
4261
4362 // Step 3: Enrich with npm data (download counts)
44- const enrichedData = await fetchNpmJs ( withGitHub )
63+ const withNpm = await fetchNpmJs ( withGitHub )
4564 console . log ( "Enriched with npm data" )
4665
47- // Step 4: Build lookup map
66+ // Step 4: Upload images to S3
67+ const enrichedData = await uploadToolImages ( withNpm )
68+ console . log ( "Uploaded tool images to S3" )
69+
70+ // Step 5: Build lookup map
4871 const toolsById : Record < string , DeveloperTool > = Object . fromEntries (
4972 enrichedData . map ( ( tool ) => [ tool . id , tool ] )
5073 )
5174 console . log (
5275 `Built toolsById lookup with ${ Object . keys ( toolsById ) . length } tools`
5376 )
5477
55- // Step 5 : Compute randomized selections
78+ // Step 6 : Compute randomized selections
5679 const highlightsByCategory = getHighlightsByCategory ( enrichedData )
5780 const mainPageHighlights = getMainPageHighlights ( highlightsByCategory )
5881 const dataByCategory = transformDeveloperToolsData ( enrichedData )
0 commit comments