MCPcopy Index your code
hub / github.com/BlockRunAI/ClawRouter / readImageFileAsDataUri

Function readImageFileAsDataUri

src/proxy.ts:1825–1842  ·  view source on GitHub ↗

* Read a local image file and return it as a base64 data URI. * Supports ~/ home directory expansion.

(filePath: string)

Source from the content-addressed store, hash-verified

1823 * Supports ~/ home directory expansion.
1824 */
1825function readImageFileAsDataUri(filePath: string): string {
1826 const resolved = filePath.startsWith("~/") ? join(homedir(), filePath.slice(2)) : filePath;
1827
1828 if (!existsSync(resolved)) {
1829 throw new Error(`Image file not found: ${resolved}`);
1830 }
1831
1832 const ext = resolved.split(".").pop()?.toLowerCase() ?? "png";
1833 const mimeMap: Record<string, string> = {
1834 png: "image/png",
1835 jpg: "image/jpeg",
1836 jpeg: "image/jpeg",
1837 webp: "image/webp",
1838 };
1839 const mime = mimeMap[ext] ?? "image/png";
1840 const data = readFileSync(resolved);
1841 return `data:${mime};base64,${data.toString("base64")}`;
1842}
1843
1844/**
1845 * Upload a base64 data URI to catbox.moe and return a public URL.

Callers 2

startProxyFunction · 0.85
proxyRequestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected