MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / selectImages

Function selectImages

src/integrations/misc/process-images.ts:5–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import * as path from "path"
4
5export 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
32function getMimeType(filePath: string): string {
33 const ext = path.extname(filePath).toLowerCase()

Callers 1

webviewMessageHandlerFunction · 0.90

Calls 5

getMimeTypeFunction · 0.85
showOpenDialogMethod · 0.80
allMethod · 0.80
toStringMethod · 0.65
readFileMethod · 0.45

Tested by

no test coverage detected