MCPcopy
hub / github.com/codeaashu/claude-code / storeImage

Function storeImage

src/utils/imageStore.ts:54–79  ·  view source on GitHub ↗
(
  content: PastedContent,
)

Source from the content-addressed store, hash-verified

52 * Store an image from pastedContents to disk.
53 */
54export async function storeImage(
55 content: PastedContent,
56): Promise<string | null> {
57 if (content.type !== 'image') {
58 return null
59 }
60
61 try {
62 await ensureImageStoreDir()
63 const imagePath = getImagePath(content.id, content.mediaType || 'image/png')
64 const fh = await open(imagePath, 'w', 0o600)
65 try {
66 await fh.writeFile(content.content, { encoding: 'base64' })
67 await fh.datasync()
68 } finally {
69 await fh.close()
70 }
71 evictOldestIfAtCap()
72 storedImagePaths.set(content.id, imagePath)
73 logForDebugging(`Stored image ${content.id} to ${imagePath}`)
74 return imagePath
75 } catch (error) {
76 logForDebugging(`Failed to store image: ${error}`)
77 return null
78 }
79}
80
81/**
82 * Store all images from pastedContents to disk.

Callers 4

onImagePasteFunction · 0.85
onImagePasteFunction · 0.85
storeImagesFunction · 0.85

Calls 7

ensureImageStoreDirFunction · 0.85
getImagePathFunction · 0.85
openFunction · 0.85
evictOldestIfAtCapFunction · 0.85
logForDebuggingFunction · 0.85
closeMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected