MCPcopy
hub / github.com/21st-dev/1code / fetchFileIcon

Function fetchFileIcon

src/renderer/lib/hooks/use-project-icon.ts:8–32  ·  view source on GitHub ↗
(projectId: string, fileUrl: string)

Source from the content-addressed store, hash-verified

6const pendingFetches = new Map<string, Promise<string | null>>()
7
8async function fetchFileIcon(projectId: string, fileUrl: string): Promise<string | null> {
9 const cached = fileIconCache.get(projectId)
10 if (cached) return cached
11
12 const pending = pendingFetches.get(projectId)
13 if (pending) return pending
14
15 const promise = (async () => {
16 try {
17 const res = await fetch(fileUrl)
18 if (!res.ok) return null
19 const blob = await res.blob()
20 const blobUrl = URL.createObjectURL(blob)
21 fileIconCache.set(projectId, blobUrl)
22 return blobUrl
23 } catch {
24 return null
25 } finally {
26 pendingFetches.delete(projectId)
27 }
28 })()
29
30 pendingFetches.set(projectId, promise)
31 return promise
32}
33
34/**
35 * Invalidate a project's cached icon (call after upload/remove).

Callers 1

useProjectIconFunction · 0.85

Calls 3

getMethod · 0.45
setMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected