( root: string, input: PastedImageInput, now = new Date() )
| 3741 | } |
| 3742 | |
| 3743 | export 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` |
no test coverage detected