(filePath: string)
| 92 | * 支持文件路径或文件扩展名(如 ".txt") |
| 93 | */ |
| 94 | export async function getFileIconAsBase64(filePath: string): Promise<string> { |
| 95 | // 命中内存缓存(刷新 LRU 顺序) |
| 96 | const cached = iconMemoryCache.get(filePath) |
| 97 | if (cached) { |
| 98 | setIconCache(filePath, cached) |
| 99 | return `data:image/png;base64,${cached.toString('base64')}` |
| 100 | } |
| 101 | |
| 102 | const buffer = await extractIconQueued(filePath) |
| 103 | |
| 104 | // 写入内存缓存 |
| 105 | setIconCache(filePath, buffer) |
| 106 | |
| 107 | return `data:image/png;base64,${buffer.toString('base64')}` |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * 在指定 session 中注册 ztools-icon:// 协议 handler |
no test coverage detected