MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / importPastedImage

Function importPastedImage

apps/desktop/src/main/vault.ts:3743–3765  ·  view source on GitHub ↗
(
  root: string,
  input: PastedImageInput,
  now = new Date()
)

Source from the content-addressed store, hash-verified

3741}
3742
3743export async function importPastedImage(
3744 root: string,
3745 input: PastedImageInput,
3746 now = new Date()
3747): Promise<ImportedAsset> {
3748 const bytes = pastedImageBuffer(input.data)
3749 if (bytes.byteLength === 0) throw new Error('Clipboard image is empty.')
3750
3751 // Pasted images land in the unified `assets/` folder.
3752 const assetsDir = path.join(root, ASSETS_DIR)
3753 await fs.mkdir(assetsDir, { recursive: true })
3754 const finalName = await uniqueFilename(assetsDir, pastedImageFilename(input, now))
3755 const destAbs = path.join(assetsDir, finalName)
3756 await fs.writeFile(destAbs, bytes)
3757
3758 const vaultRelPath = toPosix(path.relative(root, destAbs))
3759 return {
3760 name: finalName,
3761 path: vaultRelPath,
3762 markdown: `![[${vaultRelPath}]]`,
3763 kind: 'image'
3764 }
3765}
3766
3767/**
3768 * Returns the absolute path for a note, for use with `shell.showItemInFolder`

Callers 2

vault.test.tsFile · 0.90
registerIpcFunction · 0.90

Calls 4

pastedImageBufferFunction · 0.85
uniqueFilenameFunction · 0.85
pastedImageFilenameFunction · 0.85
toPosixFunction · 0.70

Tested by

no test coverage detected