Skip to content

Commit 7f1b142

Browse files
authored
Merge pull request #17732 from ethereum/dev-tools-images
feat: upload dev tools images to s3 on trigger task
2 parents 561d59a + 0ba618b commit 7f1b142

File tree

1 file changed

+26
-3
lines changed
  • src/data-layer/fetchers/developer-tools

1 file changed

+26
-3
lines changed

src/data-layer/fetchers/developer-tools/index.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { uploadToS3 } from "@/data-layer/s3"
2+
13
import { fetchBuidlGuidl } from "./fetchBuidlGuidl"
24
import { fetchGitHub } from "./fetchGitHub"
35
import { fetchNpmJs } from "./fetchNpmJs"
@@ -16,6 +18,23 @@ import {
1618
// Re-export types for consumers
1719
export 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

Comments
 (0)