()
| 3 | import * as path from "path" |
| 4 | |
| 5 | export async function selectImages(): Promise<string[]> { |
| 6 | const options: vscode.OpenDialogOptions = { |
| 7 | canSelectMany: true, |
| 8 | openLabel: "Select", |
| 9 | filters: { |
| 10 | Images: ["png", "jpg", "jpeg", "webp"], // supported by anthropic and openrouter |
| 11 | }, |
| 12 | } |
| 13 | |
| 14 | const fileUris = await vscode.window.showOpenDialog(options) |
| 15 | |
| 16 | if (!fileUris || fileUris.length === 0) { |
| 17 | return [] |
| 18 | } |
| 19 | |
| 20 | return await Promise.all( |
| 21 | fileUris.map(async (uri) => { |
| 22 | const imagePath = uri.fsPath |
| 23 | const buffer = await fs.readFile(imagePath) |
| 24 | const base64 = buffer.toString("base64") |
| 25 | const mimeType = getMimeType(imagePath) |
| 26 | const dataUrl = `data:${mimeType};base64,${base64}` |
| 27 | return dataUrl |
| 28 | }), |
| 29 | ) |
| 30 | } |
| 31 | |
| 32 | function getMimeType(filePath: string): string { |
| 33 | const ext = path.extname(filePath).toLowerCase() |
no test coverage detected