(projectId: string, fileUrl: string)
| 6 | const pendingFetches = new Map<string, Promise<string | null>>() |
| 7 | |
| 8 | async 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). |
no test coverage detected